Coverage Report

Created: 2022-07-04 16:17

src/client/inputs.rs
Line
Count
Source (jump to first uncovered line)
1
use serde::{de::DeserializeOwned, Serialize};
2
use time::Duration;
3
4
use super::Client;
5
use crate::{
6
    common::MonitorType,
7
    requests::inputs::{
8
        Create, CreateInputInternal, Request, SetSettings, SetSettingsInternal, Volume,
9
    },
10
    responses::inputs as responses,
11
    Error, Result,
12
};
13
14
/// API functions related to inputs.
15
pub struct Inputs<'a> {
16
    pub(super) client: &'a Client,
17
}
18
19
impl<'a> Inputs<'a> {
20
    /// Gets an array of all inputs in OBS.
21
19
    pub async fn list(&self, kind: Option<&str>) -> Result<Vec<responses::Input>> {
<obws::client::inputs::Inputs>::list
Line
Count
Source
21
19
    pub async fn list(&self, kind: Option<&str>) -> Result<Vec<responses::Input>> {
Unexecuted instantiation: <obws::client::inputs::Inputs>::list
22
19
        self.client
23
38
            .send_message::<_, responses::Inputs>(Request::List { kind })
24
38
            .await
25
19
            .map(|i| i.inputs)
<obws::client::inputs::Inputs>::list::{closure#0}::{closure#0}
Line
Count
Source
25
19
            .map(|i| i.inputs)
Unexecuted instantiation: <obws::client::inputs::Inputs>::list::{closure#0}::{closure#0}
Unexecuted instantiation: <obws::client::inputs::Inputs>::list::{closure#0}::{closure#0}
26
19
    }
<obws::client::inputs::Inputs>::list::{closure#0}
Line
Count
Source
22
19
        self.client
23
38
            .send_message::<_, responses::Inputs>(Request::List { kind })
24
38
            .await
25
19
            .map(|i| i.inputs)
26
19
    }
Unexecuted instantiation: <obws::client::inputs::Inputs>::list::{closure#0}
Unexecuted instantiation: <obws::client::inputs::Inputs>::list::{closure#0}
27
28
    /// Gets an array of all available input kinds in OBS.
29
1
    pub async fn list_kinds(&self, unversioned: bool) -> Result<Vec<String>> {
<obws::client::inputs::Inputs>::list_kinds
Line
Count
Source
29
1
    pub async fn list_kinds(&self, unversioned: bool) -> Result<Vec<String>> {
Unexecuted instantiation: <obws::client::inputs::Inputs>::list_kinds
30
1
        self.client
31
2
            .send_message::<_, responses::InputKinds>(Request::ListKinds { unversioned })
32
2
            .await
33
1
            .map(|ik| ik.input_kinds)
<obws::client::inputs::Inputs>::list_kinds::{closure#0}::{closure#0}
Line
Count
Source
33
1
            .map(|ik| ik.input_kinds)
Unexecuted instantiation: <obws::client::inputs::Inputs>::list_kinds::{closure#0}::{closure#0}
Unexecuted instantiation: <obws::client::inputs::Inputs>::list_kinds::{closure#0}::{closure#0}
34
1
    }
<obws::client::inputs::Inputs>::list_kinds::{closure#0}
Line
Count
Source
30
1
        self.client
31
2
            .send_message::<_, responses::InputKinds>(Request::ListKinds { unversioned })
32
2
            .await
33
1
            .map(|ik| ik.input_kinds)
34
1
    }
Unexecuted instantiation: <obws::client::inputs::Inputs>::list_kinds::{closure#0}
Unexecuted instantiation: <obws::client::inputs::Inputs>::list_kinds::{closure#0}
35
36
    /// Gets the default settings for an input kind.
37
1
    pub async fn default_settings<T>(&self, kind: &str) -> Result<T>
38
1
    where
39
1
        T: DeserializeOwned,
40
1
    {
<obws::client::inputs::Inputs>::default_settings::<serde_json::value::Value>
Line
Count
Source
37
1
    pub async fn default_settings<T>(&self, kind: &str) -> Result<T>
38
1
    where
39
1
        T: DeserializeOwned,
40
1
    {
Unexecuted instantiation: <obws::client::inputs::Inputs>::default_settings::<_>
Unexecuted instantiation: <obws::client::inputs::Inputs>::default_settings::<_>
41
1
        self.client
42
1
            .send_message::<_, responses::DefaultInputSettings<T>>(Request::DefaultSettings {
43
1
                kind,
44
2
            })
45
2
            .await
46
1
            .map(|dis| dis.default_input_settings)
<obws::client::inputs::Inputs>::default_settings::<serde_json::value::Value>::{closure#0}::{closure#0}
Line
Count
Source
46
1
            .map(|dis| dis.default_input_settings)
Unexecuted instantiation: <obws::client::inputs::Inputs>::default_settings::<_>::{closure#0}::{closure#0}
Unexecuted instantiation: <obws::client::inputs::Inputs>::default_settings::<_>::{closure#0}::{closure#0}
47
1
    }
<obws::client::inputs::Inputs>::default_settings::<serde_json::value::Value>::{closure#0}
Line
Count
Source
41
1
        self.client
42
1
            .send_message::<_, responses::DefaultInputSettings<T>>(Request::DefaultSettings {
43
1
                kind,
44
2
            })
45
2
            .await
46
1
            .map(|dis| dis.default_input_settings)
47
1
    }
Unexecuted instantiation: <obws::client::inputs::Inputs>::default_settings::<_>::{closure#0}
Unexecuted instantiation: <obws::client::inputs::Inputs>::default_settings::<_>::{closure#0}
48
49
    /// Gets the settings of an input.
50
    ///
51
    /// **Note:** Does not include defaults. To create the entire settings object, overlay input
52
    /// settings over the default input settings provided by [`Inputs::default_settings`].
53
1
    pub async fn settings<T>(&self, name: &str) -> Result<responses::InputSettings<T>>
54
1
    where
55
1
        T: DeserializeOwned,
56
1
    {
<obws::client::inputs::Inputs>::settings::<serde_json::value::Value>
Line
Count
Source
53
1
    pub async fn settings<T>(&self, name: &str) -> Result<responses::InputSettings<T>>
54
1
    where
55
1
        T: DeserializeOwned,
56
1
    {
Unexecuted instantiation: <obws::client::inputs::Inputs>::settings::<_>
Unexecuted instantiation: <obws::client::inputs::Inputs>::settings::<_>
57
2
        
self.client.send_message(Request::Settings { name })1
.await
58
1
    }
<obws::client::inputs::Inputs>::settings::<serde_json::value::Value>::{closure#0}
Line
Count
Source
57
2
        
self.client.send_message(Request::Settings { name })1
.await
58
1
    }
Unexecuted instantiation: <obws::client::inputs::Inputs>::settings::<_>::{closure#0}
Unexecuted instantiation: <obws::client::inputs::Inputs>::settings::<_>::{closure#0}
59
60
    /// Sets the settings of an input.
61
1
    pub async fn set_settings<T>(&self, settings: SetSettings<'_, T>) -> Result<()>
62
1
    where
63
1
        T: Serialize,
64
1
    {
<obws::client::inputs::Inputs>::set_settings::<serde_json::value::Value>
Line
Count
Source
61
1
    pub async fn set_settings<T>(&self, settings: SetSettings<'_, T>) -> Result<()>
62
1
    where
63
1
        T: Serialize,
64
1
    {
Unexecuted instantiation: <obws::client::inputs::Inputs>::set_settings::<_>
Unexecuted instantiation: <obws::client::inputs::Inputs>::set_settings::<_>
65
        self.client
66
            .send_message(Request::SetSettings(SetSettingsInternal {
67
1
                input: settings.input,
68
1
                settings: serde_json::to_value(&settings.settings)
69
1
                    .map_err(Error::SerializeCustomData)
?0
,
70
1
                overlay: settings.overlay,
71
2
            }))
72
2
            .await
73
1
    }
<obws::client::inputs::Inputs>::set_settings::<serde_json::value::Value>::{closure#0}
Line
Count
Source
67
1
                input: settings.input,
68
1
                settings: serde_json::to_value(&settings.settings)
69
1
                    .map_err(Error::SerializeCustomData)
?0
,
70
1
                overlay: settings.overlay,
71
2
            }))
72
2
            .await
73
1
    }
Unexecuted instantiation: <obws::client::inputs::Inputs>::set_settings::<_>::{closure#0}
Unexecuted instantiation: <obws::client::inputs::Inputs>::set_settings::<_>::{closure#0}
74
75
    /// Gets the audio mute state of an input.
76
1
    pub async fn muted(&self, name: &str) -> Result<bool> {
<obws::client::inputs::Inputs>::muted
Line
Count
Source
76
1
    pub async fn muted(&self, name: &str) -> Result<bool> {
Unexecuted instantiation: <obws::client::inputs::Inputs>::muted
77
1
        self.client
78
2
            .send_message::<_, responses::InputMuted>(Request::Muted { name })
79
2
            .await
80
1
            .map(|im| im.muted)
<obws::client::inputs::Inputs>::muted::{closure#0}::{closure#0}
Line
Count
Source
80
1
            .map(|im| im.muted)
Unexecuted instantiation: <obws::client::inputs::Inputs>::muted::{closure#0}::{closure#0}
Unexecuted instantiation: <obws::client::inputs::Inputs>::muted::{closure#0}::{closure#0}
81
1
    }
<obws::client::inputs::Inputs>::muted::{closure#0}
Line
Count
Source
77
1
        self.client
78
2
            .send_message::<_, responses::InputMuted>(Request::Muted { name })
79
2
            .await
80
1
            .map(|im| im.muted)
81
1
    }
Unexecuted instantiation: <obws::client::inputs::Inputs>::muted::{closure#0}
Unexecuted instantiation: <obws::client::inputs::Inputs>::muted::{closure#0}
82
83
    /// Sets the audio mute state of an input.
84
2
    pub async fn set_muted(&self, name: &str, muted: bool) -> Result<()> {
<obws::client::inputs::Inputs>::set_muted
Line
Count
Source
84
2
    pub async fn set_muted(&self, name: &str, muted: bool) -> Result<()> {
Unexecuted instantiation: <obws::client::inputs::Inputs>::set_muted
85
2
        self.client
86
4
            .send_message(Request::SetMuted { name, muted })
87
4
            .await
88
2
    }
<obws::client::inputs::Inputs>::set_muted::{closure#0}
Line
Count
Source
85
2
        self.client
86
4
            .send_message(Request::SetMuted { name, muted })
87
4
            .await
88
2
    }
Unexecuted instantiation: <obws::client::inputs::Inputs>::set_muted::{closure#0}
Unexecuted instantiation: <obws::client::inputs::Inputs>::set_muted::{closure#0}
89
90
    /// Toggles the audio mute state of an input.
91
2
    pub async fn toggle_mute(&self, name: &str) -> Result<bool> {
<obws::client::inputs::Inputs>::toggle_mute
Line
Count
Source
91
2
    pub async fn toggle_mute(&self, name: &str) -> Result<bool> {
Unexecuted instantiation: <obws::client::inputs::Inputs>::toggle_mute
92
2
        self.client
93
4
            .send_message::<_, responses::InputMuted>(Request::ToggleMute { name })
94
4
            .await
95
2
            .map(|im| im.muted)
<obws::client::inputs::Inputs>::toggle_mute::{closure#0}::{closure#0}
Line
Count
Source
95
2
            .map(|im| im.muted)
Unexecuted instantiation: <obws::client::inputs::Inputs>::toggle_mute::{closure#0}::{closure#0}
Unexecuted instantiation: <obws::client::inputs::Inputs>::toggle_mute::{closure#0}::{closure#0}
96
2
    }
<obws::client::inputs::Inputs>::toggle_mute::{closure#0}
Line
Count
Source
92
2
        self.client
93
4
            .send_message::<_, responses::InputMuted>(Request::ToggleMute { name })
94
4
            .await
95
2
            .map(|im| im.muted)
96
2
    }
Unexecuted instantiation: <obws::client::inputs::Inputs>::toggle_mute::{closure#0}
Unexecuted instantiation: <obws::client::inputs::Inputs>::toggle_mute::{closure#0}
97
98
    /// Gets the current volume setting of an input.
99
1
    pub async fn volume(&self, name: &str) -> Result<responses::InputVolume> {
<obws::client::inputs::Inputs>::volume
Line
Count
Source
99
1
    pub async fn volume(&self, name: &str) -> Result<responses::InputVolume> {
Unexecuted instantiation: <obws::client::inputs::Inputs>::volume
100
2
        
self.client.send_message(Request::Volume { name })1
.await
101
1
    }
<obws::client::inputs::Inputs>::volume::{closure#0}
Line
Count
Source
100
2
        
self.client.send_message(Request::Volume { name })1
.await
101
1
    }
Unexecuted instantiation: <obws::client::inputs::Inputs>::volume::{closure#0}
Unexecuted instantiation: <obws::client::inputs::Inputs>::volume::{closure#0}
102
103
    /// Sets the volume setting of an input.
104
1
    pub async fn set_volume(&self, name: &str, volume: Volume) -> Result<()> {
<obws::client::inputs::Inputs>::set_volume
Line
Count
Source
104
1
    pub async fn set_volume(&self, name: &str, volume: Volume) -> Result<()> {
Unexecuted instantiation: <obws::client::inputs::Inputs>::set_volume
105
1
        self.client
106
2
            .send_message(Request::SetVolume { name, volume })
107
2
            .await
108
1
    }
<obws::client::inputs::Inputs>::set_volume::{closure#0}
Line
Count
Source
105
1
        self.client
106
2
            .send_message(Request::SetVolume { name, volume })
107
2
            .await
108
1
    }
Unexecuted instantiation: <obws::client::inputs::Inputs>::set_volume::{closure#0}
Unexecuted instantiation: <obws::client::inputs::Inputs>::set_volume::{closure#0}
109
110
    /// Sets the name of an input (rename).
111
2
    pub async fn set_name(&self, name: &str, new: &str) -> Result<()> {
<obws::client::inputs::Inputs>::set_name
Line
Count
Source
111
2
    pub async fn set_name(&self, name: &str, new: &str) -> Result<()> {
Unexecuted instantiation: <obws::client::inputs::Inputs>::set_name
112
2
        self.client
113
4
            .send_message(Request::SetName { name, new })
114
4
            .await
115
2
    }
<obws::client::inputs::Inputs>::set_name::{closure#0}
Line
Count
Source
112
2
        self.client
113
4
            .send_message(Request::SetName { name, new })
114
4
            .await
115
2
    }
Unexecuted instantiation: <obws::client::inputs::Inputs>::set_name::{closure#0}
Unexecuted instantiation: <obws::client::inputs::Inputs>::set_name::{closure#0}
116
117
    /// Creates a new input, adding it as a scene item to the specified scene.
118
0
    pub async fn create<T>(&self, input: Create<'_, T>) -> Result<i64>
119
0
    where
120
0
        T: Serialize,
121
0
    {
Unexecuted instantiation: <obws::client::inputs::Inputs>::create::<_>
Unexecuted instantiation: <obws::client::inputs::Inputs>::create::<_>
122
        self.client
123
            .send_message::<_, responses::SceneItemId>(Request::Create(CreateInputInternal {
124
0
                scene: input.scene,
125
0
                input: input.input,
126
0
                kind: input.kind,
127
0
                settings: input
128
0
                    .settings
129
0
                    .map(|settings| {
130
0
                        serde_json::to_value(&settings).map_err(Error::SerializeCustomData)
131
0
                    })
Unexecuted instantiation: <obws::client::inputs::Inputs>::create::<_>::{closure#0}::{closure#0}
Unexecuted instantiation: <obws::client::inputs::Inputs>::create::<_>::{closure#0}::{closure#0}
132
0
                    .transpose()?,
133
0
                enabled: input.enabled,
134
0
            }))
135
0
            .await
136
0
            .map(|sii| sii.scene_item_id)
Unexecuted instantiation: <obws::client::inputs::Inputs>::create::<_>::{closure#0}::{closure#1}
Unexecuted instantiation: <obws::client::inputs::Inputs>::create::<_>::{closure#0}::{closure#1}
137
0
    }
Unexecuted instantiation: <obws::client::inputs::Inputs>::create::<_>::{closure#0}
Unexecuted instantiation: <obws::client::inputs::Inputs>::create::<_>::{closure#0}
138
139
    /// Removes an existing input.
140
    ///
141
    /// **Note:** Will immediately remove all associated scene items.
142
0
    pub async fn remove(&self, name: &str) -> Result<()> {
Unexecuted instantiation: <obws::client::inputs::Inputs>::remove
Unexecuted instantiation: <obws::client::inputs::Inputs>::remove
143
0
        self.client.send_message(Request::Remove { name }).await
144
0
    }
Unexecuted instantiation: <obws::client::inputs::Inputs>::remove::{closure#0}
Unexecuted instantiation: <obws::client::inputs::Inputs>::remove::{closure#0}
145
146
    /// Gets the audio sync offset of an input.
147
    ///
148
    /// **Note:** The audio sync offset can be negative too!
149
1
    pub async fn audio_sync_offset(&self, name: &str) -> Result<Duration> {
<obws::client::inputs::Inputs>::audio_sync_offset
Line
Count
Source
149
1
    pub async fn audio_sync_offset(&self, name: &str) -> Result<Duration> {
Unexecuted instantiation: <obws::client::inputs::Inputs>::audio_sync_offset
150
1
        self.client
151
2
            .send_message::<_, responses::AudioSyncOffset>(Request::AudioSyncOffset { name })
152
2
            .await
153
1
            .map(|aso| aso.input_audio_sync_offset)
<obws::client::inputs::Inputs>::audio_sync_offset::{closure#0}::{closure#0}
Line
Count
Source
153
1
            .map(|aso| aso.input_audio_sync_offset)
Unexecuted instantiation: <obws::client::inputs::Inputs>::audio_sync_offset::{closure#0}::{closure#0}
Unexecuted instantiation: <obws::client::inputs::Inputs>::audio_sync_offset::{closure#0}::{closure#0}
154
1
    }
<obws::client::inputs::Inputs>::audio_sync_offset::{closure#0}
Line
Count
Source
150
1
        self.client
151
2
            .send_message::<_, responses::AudioSyncOffset>(Request::AudioSyncOffset { name })
152
2
            .await
153
1
            .map(|aso| aso.input_audio_sync_offset)
154
1
    }
Unexecuted instantiation: <obws::client::inputs::Inputs>::audio_sync_offset::{closure#0}
Unexecuted instantiation: <obws::client::inputs::Inputs>::audio_sync_offset::{closure#0}
155
156
    /// Sets the audio sync offset of an input.
157
2
    pub async fn set_audio_sync_offset(&self, name: &str, offset: Duration) -> Result<()> {
<obws::client::inputs::Inputs>::set_audio_sync_offset
Line
Count
Source
157
2
    pub async fn set_audio_sync_offset(&self, name: &str, offset: Duration) -> Result<()> {
Unexecuted instantiation: <obws::client::inputs::Inputs>::set_audio_sync_offset
158
2
        self.client
159
4
            .send_message(Request::SetAudioSyncOffset { name, offset })
160
4
            .await
161
2
    }
<obws::client::inputs::Inputs>::set_audio_sync_offset::{closure#0}
Line
Count
Source
158
2
        self.client
159
4
            .send_message(Request::SetAudioSyncOffset { name, offset })
160
4
            .await
161
2
    }
Unexecuted instantiation: <obws::client::inputs::Inputs>::set_audio_sync_offset::{closure#0}
Unexecuted instantiation: <obws::client::inputs::Inputs>::set_audio_sync_offset::{closure#0}
162
163
    /// Gets the audio monitor type of input.
164
1
    pub async fn audio_monitor_type(&self, name: &str) -> Result<MonitorType> {
<obws::client::inputs::Inputs>::audio_monitor_type
Line
Count
Source
164
1
    pub async fn audio_monitor_type(&self, name: &str) -> Result<MonitorType> {
Unexecuted instantiation: <obws::client::inputs::Inputs>::audio_monitor_type
165
1
        self.client
166
2
            .send_message::<_, responses::AudioMonitorType>(Request::AudioMonitorType { name })
167
2
            .await
168
1
            .map(|amt| amt.monitor_type)
<obws::client::inputs::Inputs>::audio_monitor_type::{closure#0}::{closure#0}
Line
Count
Source
168
1
            .map(|amt| amt.monitor_type)
Unexecuted instantiation: <obws::client::inputs::Inputs>::audio_monitor_type::{closure#0}::{closure#0}
Unexecuted instantiation: <obws::client::inputs::Inputs>::audio_monitor_type::{closure#0}::{closure#0}
169
1
    }
<obws::client::inputs::Inputs>::audio_monitor_type::{closure#0}
Line
Count
Source
165
1
        self.client
166
2
            .send_message::<_, responses::AudioMonitorType>(Request::AudioMonitorType { name })
167
2
            .await
168
1
            .map(|amt| amt.monitor_type)
169
1
    }
Unexecuted instantiation: <obws::client::inputs::Inputs>::audio_monitor_type::{closure#0}
Unexecuted instantiation: <obws::client::inputs::Inputs>::audio_monitor_type::{closure#0}
170
171
    /// Sets the audio monitor type of input.
172
2
    pub async fn set_audio_monitor_type(
173
2
        &self,
174
2
        name: &str,
175
2
        monitor_type: MonitorType,
176
2
    ) -> Result<()> {
<obws::client::inputs::Inputs>::set_audio_monitor_type
Line
Count
Source
172
2
    pub async fn set_audio_monitor_type(
173
2
        &self,
174
2
        name: &str,
175
2
        monitor_type: MonitorType,
176
2
    ) -> Result<()> {
Unexecuted instantiation: <obws::client::inputs::Inputs>::set_audio_monitor_type
177
2
        self.client
178
4
            .send_message(Request::SetAudioMonitorType { name, monitor_type })
179
4
            .await
180
2
    }
<obws::client::inputs::Inputs>::set_audio_monitor_type::{closure#0}
Line
Count
Source
177
2
        self.client
178
4
            .send_message(Request::SetAudioMonitorType { name, monitor_type })
179
4
            .await
180
2
    }
Unexecuted instantiation: <obws::client::inputs::Inputs>::set_audio_monitor_type::{closure#0}
Unexecuted instantiation: <obws::client::inputs::Inputs>::set_audio_monitor_type::{closure#0}
181
182
    /// Gets the items of a list property from an input's properties.
183
    ///
184
    /// **Note:** Use this in cases where an input provides a dynamic, selectable list of items. For
185
    /// example, display capture, where it provides a list of available displays.
186
0
    pub async fn properties_list_property_items(
187
0
        &self,
188
0
        input: &str,
189
0
        property: &str,
190
0
    ) -> Result<Vec<responses::ListPropertyItem>> {
Unexecuted instantiation: <obws::client::inputs::Inputs>::properties_list_property_items
Unexecuted instantiation: <obws::client::inputs::Inputs>::properties_list_property_items
191
0
        self.client
192
0
            .send_message::<_, responses::ListPropertyItems>(Request::PropertiesListPropertyItems {
193
0
                input,
194
0
                property,
195
0
            })
196
0
            .await
197
0
            .map(|lpi| lpi.property_items)
Unexecuted instantiation: <obws::client::inputs::Inputs>::properties_list_property_items::{closure#0}::{closure#0}
Unexecuted instantiation: <obws::client::inputs::Inputs>::properties_list_property_items::{closure#0}::{closure#0}
198
0
    }
Unexecuted instantiation: <obws::client::inputs::Inputs>::properties_list_property_items::{closure#0}
Unexecuted instantiation: <obws::client::inputs::Inputs>::properties_list_property_items::{closure#0}
199
200
    /// Presses a button in the properties of an input.
201
    ///
202
    /// **Note:** Use this in cases where there is a button in the properties of an input that
203
    /// cannot be accessed in any other way. For example, browser sources, where there is a refresh
204
    /// button.
205
0
    pub async fn press_properties_button(&self, input: &str, property: &str) -> Result<()> {
Unexecuted instantiation: <obws::client::inputs::Inputs>::press_properties_button
Unexecuted instantiation: <obws::client::inputs::Inputs>::press_properties_button
206
0
        self.client
207
0
            .send_message(Request::PressPropertiesButton { input, property })
208
0
            .await
209
0
    }
Unexecuted instantiation: <obws::client::inputs::Inputs>::press_properties_button::{closure#0}
Unexecuted instantiation: <obws::client::inputs::Inputs>::press_properties_button::{closure#0}
210
}