Skip to content

Commit

Permalink
fix: emit track-muted event for local tracks
Browse files Browse the repository at this point in the history
  • Loading branch information
kbalt committed Jan 9, 2025
1 parent 5047dae commit 42bd9c5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
1 change: 1 addition & 0 deletions .nanpa/track-muted-event-for-local-publications.kdl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
patch type="fixed" package="livekit" "Emit TrackMuted/TrackUnmuted events for local publications"
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion livekit/src/room/participant/local_participant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,14 @@ impl LocalParticipant {
}

pub(crate) fn update_info(&self, info: proto::ParticipantInfo) {
super::update_info(&self.inner, &Participant::Local(self.clone()), info);
super::update_info(&self.inner, &Participant::Local(self.clone()), info.clone());

for track in info.tracks {
let track_sid = track.sid.clone().try_into().unwrap();
if let Some(publication) = self.get_track_publication(&track_sid) {
publication.update_info(track.clone());
}
}
}

pub(crate) fn set_speaking(&self, speaking: bool) {
Expand Down
20 changes: 17 additions & 3 deletions livekit/src/room/publication/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,23 @@ impl LocalTrackPublication {
self.inner.info.read().proto_info.clone()
}

#[allow(dead_code)]
pub(crate) fn update_info(&self, info: proto::TrackInfo) {
super::update_info(&self.inner, &TrackPublication::Local(self.clone()), info);
pub(crate) fn update_info(&self, new_info: proto::TrackInfo) {
super::update_info(&self.inner, &TrackPublication::Local(self.clone()), new_info.clone());

let mut info = self.inner.info.write();
if info.muted != new_info.muted {
info.muted = new_info.muted;

drop(info);

if new_info.muted {
if let Some(on_mute) = self.inner.events.muted.lock().as_ref() {
on_mute(TrackPublication::Local(self.clone()));
}
} else if let Some(on_unmute) = self.inner.events.unmuted.lock().as_ref() {
on_unmute(TrackPublication::Local(self.clone()));
}
}
}

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

0 comments on commit 42bd9c5

Please sign in to comment.