Skip to content

Commit 36905ef

Browse files
committed
feat: emit track-muted event for local tracks
1 parent 5047dae commit 36905ef

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

livekit/src/room/participant/local_participant.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,14 @@ impl LocalParticipant {
115115
}
116116

117117
pub(crate) fn update_info(&self, info: proto::ParticipantInfo) {
118-
super::update_info(&self.inner, &Participant::Local(self.clone()), info);
118+
super::update_info(&self.inner, &Participant::Local(self.clone()), info.clone());
119+
120+
for track in info.tracks {
121+
let track_sid = track.sid.clone().try_into().unwrap();
122+
if let Some(publication) = self.get_track_publication(&track_sid) {
123+
publication.update_info(track.clone());
124+
}
125+
}
119126
}
120127

121128
pub(crate) fn set_speaking(&self, speaking: bool) {

livekit/src/room/publication/local.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,23 @@ impl LocalTrackPublication {
6565
self.inner.info.read().proto_info.clone()
6666
}
6767

68-
#[allow(dead_code)]
69-
pub(crate) fn update_info(&self, info: proto::TrackInfo) {
70-
super::update_info(&self.inner, &TrackPublication::Local(self.clone()), info);
68+
pub(crate) fn update_info(&self, new_info: proto::TrackInfo) {
69+
super::update_info(&self.inner, &TrackPublication::Local(self.clone()), new_info.clone());
70+
71+
let mut info = self.inner.info.write();
72+
if info.muted != new_info.muted {
73+
info.muted = new_info.muted;
74+
75+
drop(info);
76+
77+
if new_info.muted {
78+
if let Some(on_mute) = self.inner.events.muted.lock().as_ref() {
79+
on_mute(TrackPublication::Local(self.clone()));
80+
}
81+
} else if let Some(on_unmute) = self.inner.events.unmuted.lock().as_ref() {
82+
on_unmute(TrackPublication::Local(self.clone()));
83+
}
84+
}
7185
}
7286

7387
pub(crate) fn update_publish_options(&self, opts: TrackPublishOptions) {

0 commit comments

Comments
 (0)