1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//! Wrapper around a received remote [MediaStreamTrack][1].
//!
//! [1]: https://w3.org/TR/mediacapture-streams/#dom-mediastreamtrack
use derive_more::with_trait::{From, Into};
use wasm_bindgen::prelude::*;
use crate::{
api::{MediaDirection, MediaKind, MediaSourceKind},
media::track::remote,
};
/// Wrapper around a received remote [MediaStreamTrack][1].
///
/// [1]: https://w3.org/TR/mediacapture-streams/#dom-mediastreamtrack
#[wasm_bindgen]
#[derive(Clone, Debug, From, Into)]
pub struct RemoteMediaTrack(remote::Track);
#[wasm_bindgen]
impl RemoteMediaTrack {
/// Returns the underlying [MediaStreamTrack][1].
///
/// [1]: https://w3.org/TR/mediacapture-streams/#dom-mediastreamtrack
#[must_use]
pub fn get_track(&self) -> web_sys::MediaStreamTrack {
Clone::clone(self.0.get_track().as_ref())
}
/// Indicates whether this [`RemoteMediaTrack`] is muted.
#[must_use]
pub fn muted(&self) -> bool {
self.0.muted()
}
/// Sets callback to invoke when this [`RemoteMediaTrack`] is muted.
pub fn on_muted(&self, cb: js_sys::Function) {
self.0.on_muted(cb.into());
}
/// Sets callback to invoke when this [`RemoteMediaTrack`] is unmuted.
pub fn on_unmuted(&self, cb: js_sys::Function) {
self.0.on_unmuted(cb.into());
}
/// Sets callback to invoke when this [`RemoteMediaTrack`] is stopped.
pub fn on_stopped(&self, cb: js_sys::Function) {
self.0.on_stopped(cb.into());
}
/// Sets callback to invoke whenever this [`RemoteMediaTrack`]'s general
/// [`MediaDirection`] changes.
pub fn on_media_direction_changed(&self, cb: js_sys::Function) {
self.0.on_media_direction_changed(cb.into());
}
/// Returns a [`MediaKind::Audio`] if this [`RemoteMediaTrack`] represents
/// an audio track, or a [`MediaKind::Video`] if it represents a video
/// track.
#[must_use]
pub fn kind(&self) -> MediaKind {
self.0.kind().into()
}
/// Returns a [`MediaSourceKind::Device`] if this [`RemoteMediaTrack`] is
/// sourced from some device (webcam/microphone), or a
/// [`MediaSourceKind::Display`] if it's captured via
/// [MediaDevices.getDisplayMedia()][1].
///
/// [1]: https://w3.org/TR/screen-capture/#dom-mediadevices-getdisplaymedia
#[must_use]
pub fn media_source_kind(&self) -> MediaSourceKind {
self.0.media_source_kind().into()
}
/// Returns the current general [`MediaDirection`] of this
/// [`RemoteMediaTrack`].
#[must_use]
pub fn media_direction(&self) -> MediaDirection {
self.0.media_direction().into()
}
}