Line | Count | Source (jump to first uncovered line) |
1 | | use serde::{de::DeserializeOwned, Serialize}; |
2 | | |
3 | | use super::Client; |
4 | | use crate::{ |
5 | | requests::general::{CallVendorRequest, CallVendorRequestInternal, Request}, |
6 | | responses::general as responses, |
7 | | Error, Result, |
8 | | }; |
9 | | |
10 | | /// General functions of the API. |
11 | | pub struct General<'a> { |
12 | | pub(super) client: &'a Client, |
13 | | } |
14 | | |
15 | | impl<'a> General<'a> { |
16 | | /// Gets data about the current plugin and RPC version. |
17 | 19 | pub async fn version(&self) -> Result<responses::Version> { <obws::client::general::General>::version Line | Count | Source | 17 | 19 | pub async fn version(&self) -> Result<responses::Version> { |
Unexecuted instantiation: <obws::client::general::General>::version |
18 | 38 | self.client.send_message(Request::Version)19 .await |
19 | 19 | } <obws::client::general::General>::version::{closure#0} Line | Count | Source | 18 | 38 | self.client.send_message(Request::Version)19 .await | 19 | 19 | } |
Unexecuted instantiation: <obws::client::general::General>::version::{closure#0} Unexecuted instantiation: <obws::client::general::General>::version::{closure#0} |
20 | | |
21 | | /// Gets statistics about OBS, obs-websocket, and the current session. |
22 | 1 | pub async fn stats(&self) -> Result<responses::Stats> { <obws::client::general::General>::stats Line | Count | Source | 22 | 1 | pub async fn stats(&self) -> Result<responses::Stats> { |
Unexecuted instantiation: <obws::client::general::General>::stats |
23 | 2 | self.client.send_message(Request::Stats)1 .await |
24 | 1 | } <obws::client::general::General>::stats::{closure#0} Line | Count | Source | 23 | 2 | self.client.send_message(Request::Stats)1 .await | 24 | 1 | } |
Unexecuted instantiation: <obws::client::general::General>::stats::{closure#0} Unexecuted instantiation: <obws::client::general::General>::stats::{closure#0} |
25 | | |
26 | | /// Broadcasts a custom event to all web-socket clients. Receivers are clients which are |
27 | | /// identified and subscribed. |
28 | 1 | pub async fn broadcast_custom_event<T>(&self, event_data: &T) -> Result<()> |
29 | 1 | where |
30 | 1 | T: Serialize, |
31 | 1 | { <obws::client::general::General>::broadcast_custom_event::<integration::general::CustomEvent> Line | Count | Source | 28 | 1 | pub async fn broadcast_custom_event<T>(&self, event_data: &T) -> Result<()> | 29 | 1 | where | 30 | 1 | T: Serialize, | 31 | 1 | { |
Unexecuted instantiation: <obws::client::general::General>::broadcast_custom_event::<_> Unexecuted instantiation: <obws::client::general::General>::broadcast_custom_event::<_> |
32 | 1 | let event_data = serde_json::to_value(event_data).map_err(Error::SerializeCustomData)?0 ; |
33 | 1 | if !event_data.is_object() { |
34 | 0 | return Err(Error::InvalidCustomData); |
35 | 1 | } |
36 | 1 | |
37 | 1 | self.client |
38 | 2 | .send_message(Request::BroadcastCustomEvent { event_data }) |
39 | 2 | .await |
40 | 1 | } <obws::client::general::General>::broadcast_custom_event::<integration::general::CustomEvent>::{closure#0} Line | Count | Source | 32 | 1 | let event_data = serde_json::to_value(event_data).map_err(Error::SerializeCustomData)?0 ; | 33 | 1 | if !event_data.is_object() { | 34 | 0 | return Err(Error::InvalidCustomData); | 35 | 1 | } | 36 | 1 | | 37 | 1 | self.client | 38 | 2 | .send_message(Request::BroadcastCustomEvent { event_data }) | 39 | 2 | .await | 40 | 1 | } |
Unexecuted instantiation: <obws::client::general::General>::broadcast_custom_event::<_>::{closure#0} Unexecuted instantiation: <obws::client::general::General>::broadcast_custom_event::<_>::{closure#0} |
41 | | |
42 | | /// Call a request registered to a vendor. |
43 | | /// |
44 | | /// A vendor is a unique name registered by a third-party plugin or script, which allows for |
45 | | /// custom requests and events to be added to obs-websocket. If a plugin or script implements |
46 | | /// vendor requests or events, documentation is expected to be provided with them. |
47 | 0 | pub async fn call_vendor_request<T, R>( |
48 | 0 | &self, |
49 | 0 | request: CallVendorRequest<'_, T>, |
50 | 0 | ) -> Result<responses::VendorResponse<R>> |
51 | 0 | where |
52 | 0 | T: Serialize, |
53 | 0 | R: DeserializeOwned, |
54 | 0 | { Unexecuted instantiation: <obws::client::general::General>::call_vendor_request::<_, _> Unexecuted instantiation: <obws::client::general::General>::call_vendor_request::<_, _> |
55 | | self.client |
56 | | .send_message(Request::CallVendorRequest(CallVendorRequestInternal { |
57 | 0 | vendor_name: request.vendor_name, |
58 | 0 | request_type: request.request_type, |
59 | 0 | request_data: serde_json::to_value(&request.request_data) |
60 | 0 | .map_err(Error::SerializeCustomData)?, |
61 | 0 | })) |
62 | 0 | .await |
63 | 0 | } Unexecuted instantiation: <obws::client::general::General>::call_vendor_request::<_, _>::{closure#0} Unexecuted instantiation: <obws::client::general::General>::call_vendor_request::<_, _>::{closure#0} |
64 | | } |