1use super::*;
2use webrtc::{audio_source::RtcAudioSource, video_source::RtcVideoSource};
3
4pub use livekit::track::{TrackKind, TrackSource};
5
6#[derive(Clone, Debug)]
7pub enum LocalTrack {
8 Audio(LocalAudioTrack),
9 Video(LocalVideoTrack),
10}
11
12#[derive(Clone, Debug)]
13pub enum RemoteTrack {
14 Audio(RemoteAudioTrack),
15 Video(RemoteVideoTrack),
16}
17
18#[derive(Clone, Debug)]
19pub struct LocalVideoTrack {}
20
21#[derive(Clone, Debug)]
22pub struct LocalAudioTrack {}
23
24#[derive(Clone, Debug)]
25pub struct RemoteVideoTrack {
26 pub(super) server_track: Arc<TestServerVideoTrack>,
27 pub(super) _room: WeakRoom,
28}
29
30#[derive(Clone, Debug)]
31pub struct RemoteAudioTrack {
32 pub(super) server_track: Arc<TestServerAudioTrack>,
33 pub(super) room: WeakRoom,
34}
35
36pub enum RtcTrack {
37 Audio(RtcAudioTrack),
38 Video(RtcVideoTrack),
39}
40
41pub struct RtcAudioTrack {
42 pub(super) server_track: Arc<TestServerAudioTrack>,
43 pub(super) room: WeakRoom,
44}
45
46pub struct RtcVideoTrack {
47 pub(super) _server_track: Arc<TestServerVideoTrack>,
48}
49
50impl RemoteTrack {
51 pub fn sid(&self) -> TrackSid {
52 match self {
53 RemoteTrack::Audio(track) => track.sid(),
54 RemoteTrack::Video(track) => track.sid(),
55 }
56 }
57
58 pub fn kind(&self) -> TrackKind {
59 match self {
60 RemoteTrack::Audio(_) => TrackKind::Audio,
61 RemoteTrack::Video(_) => TrackKind::Video,
62 }
63 }
64
65 pub fn publisher_id(&self) -> ParticipantIdentity {
66 match self {
67 RemoteTrack::Audio(track) => track.publisher_id(),
68 RemoteTrack::Video(track) => track.publisher_id(),
69 }
70 }
71
72 pub fn rtc_track(&self) -> RtcTrack {
73 match self {
74 RemoteTrack::Audio(track) => RtcTrack::Audio(track.rtc_track()),
75 RemoteTrack::Video(track) => RtcTrack::Video(track.rtc_track()),
76 }
77 }
78}
79
80impl LocalVideoTrack {
81 pub fn create_video_track(_name: &str, _source: RtcVideoSource) -> Self {
82 Self {}
83 }
84}
85
86impl LocalAudioTrack {
87 pub fn create_audio_track(_name: &str, _source: RtcAudioSource) -> Self {
88 Self {}
89 }
90}
91
92impl RemoteAudioTrack {
93 pub fn sid(&self) -> TrackSid {
94 self.server_track.sid.clone()
95 }
96
97 pub fn publisher_id(&self) -> ParticipantIdentity {
98 self.server_track.publisher_id.clone()
99 }
100
101 pub fn start(&self) {
102 if let Some(room) = self.room.upgrade() {
103 room.0
104 .lock()
105 .paused_audio_tracks
106 .remove(&self.server_track.sid);
107 }
108 }
109
110 pub fn stop(&self) {
111 if let Some(room) = self.room.upgrade() {
112 room.0
113 .lock()
114 .paused_audio_tracks
115 .insert(self.server_track.sid.clone());
116 }
117 }
118
119 pub fn rtc_track(&self) -> RtcAudioTrack {
120 RtcAudioTrack {
121 server_track: self.server_track.clone(),
122 room: self.room.clone(),
123 }
124 }
125}
126
127impl RemoteVideoTrack {
128 pub fn sid(&self) -> TrackSid {
129 self.server_track.sid.clone()
130 }
131
132 pub fn publisher_id(&self) -> ParticipantIdentity {
133 self.server_track.publisher_id.clone()
134 }
135
136 pub fn rtc_track(&self) -> RtcVideoTrack {
137 RtcVideoTrack {
138 _server_track: self.server_track.clone(),
139 }
140 }
141}
142
143impl RtcTrack {
144 pub fn enabled(&self) -> bool {
145 match self {
146 RtcTrack::Audio(track) => track.enabled(),
147 RtcTrack::Video(track) => track.enabled(),
148 }
149 }
150
151 pub fn set_enabled(&self, enabled: bool) {
152 match self {
153 RtcTrack::Audio(track) => track.set_enabled(enabled),
154 RtcTrack::Video(_) => {}
155 }
156 }
157}
158
159impl RtcAudioTrack {
160 pub fn set_enabled(&self, enabled: bool) {
161 if let Some(room) = self.room.upgrade() {
162 let paused_audio_tracks = &mut room.0.lock().paused_audio_tracks;
163 if enabled {
164 paused_audio_tracks.remove(&self.server_track.sid);
165 } else {
166 paused_audio_tracks.insert(self.server_track.sid.clone());
167 }
168 }
169 }
170
171 pub fn enabled(&self) -> bool {
172 if let Some(room) = self.room.upgrade() {
173 !room
174 .0
175 .lock()
176 .paused_audio_tracks
177 .contains(&self.server_track.sid)
178 } else {
179 false
180 }
181 }
182}
183
184impl RtcVideoTrack {
185 pub fn enabled(&self) -> bool {
186 true
187 }
188}