From 42bd9c5ff68ab2f0ac3febfe0a1f16562529594d Mon Sep 17 00:00:00 2001 From: Konstantin Baltruschat Date: Thu, 9 Jan 2025 16:48:56 +0100 Subject: [PATCH] fix: emit track-muted event for local tracks --- ...ack-muted-event-for-local-publications.kdl | 1 + Cargo.lock | 4 ++-- .../src/room/participant/local_participant.rs | 9 ++++++++- livekit/src/room/publication/local.rs | 20 ++++++++++++++++--- 4 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 .nanpa/track-muted-event-for-local-publications.kdl diff --git a/.nanpa/track-muted-event-for-local-publications.kdl b/.nanpa/track-muted-event-for-local-publications.kdl new file mode 100644 index 000000000..879dc0964 --- /dev/null +++ b/.nanpa/track-muted-event-for-local-publications.kdl @@ -0,0 +1 @@ +patch type="fixed" package="livekit" "Emit TrackMuted/TrackUnmuted events for local publications" \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 7fc649ecd..b0532c222 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1593,7 +1593,7 @@ checksum = "c4cd1a83af159aa67994778be9070f0ae1bd732942279cabb14f86f986a21456" [[package]] name = "livekit" -version = "0.7.1" +version = "0.7.2" dependencies = [ "chrono", "futures-util", @@ -1641,7 +1641,7 @@ dependencies = [ [[package]] name = "livekit-ffi" -version = "0.12.4" +version = "0.12.6" dependencies = [ "console-subscriber", "dashmap", diff --git a/livekit/src/room/participant/local_participant.rs b/livekit/src/room/participant/local_participant.rs index bbf269c50..ed07ac139 100644 --- a/livekit/src/room/participant/local_participant.rs +++ b/livekit/src/room/participant/local_participant.rs @@ -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) { diff --git a/livekit/src/room/publication/local.rs b/livekit/src/room/publication/local.rs index bd222982c..85657fe30 100644 --- a/livekit/src/room/publication/local.rs +++ b/livekit/src/room/publication/local.rs @@ -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) {