Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: emit track-muted event for local tracks #544

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading