livekit / rust-sdks

LiveKit realtime and server SDKs for Rust
https://livekit.io
Apache License 2.0
185 stars 44 forks source link

livekit: send UpdateTrackSettings on disable #368

Closed nbsp closed 2 months ago

nbsp commented 2 months ago

fixes #359

nbsp commented 2 months ago

@maxbrunsfeld the test app needs some refactoring to work with this change, as it currently disables the RTC track directly, and wouldn't send any updates to the LiveKit SFU. something like this was enough for my testing:

a diff ```diff diff --git a/crates/live_kit_client/examples/test_app.rs b/crates/live_kit_client/examples/test_app.rs index 127f4be05..11aff6f4e 100644 --- a/crates/live_kit_client/examples/test_app.rs +++ b/crates/live_kit_client/examples/test_app.rs @@ -12,7 +12,7 @@ use live_kit_client::{ options::{TrackPublishOptions, VideoCodec}, participant::{Participant, RemoteParticipant}, play_remote_audio_track, - publication::LocalTrackPublication, + publication::{LocalTrackPublication, RemoteTrackPublication}, track::{LocalTrack, RemoteAudioTrack, RemoteTrack, RemoteVideoTrack, TrackSource}, AudioStream, RemoteVideoTrackView, Room, RoomEvent, RoomOptions, }; @@ -91,7 +91,7 @@ struct LivekitWindow { #[derive(Default)] struct ParticipantState { - audio_output_stream: Option<(RemoteAudioTrack, AudioStream)>, + audio_output_stream: Option<(RemoteTrackPublication, AudioStream)>, muted: bool, screen_share_output_view: Option<(RemoteVideoTrack, View)>, speaking: bool, @@ -170,20 +170,23 @@ impl LivekitWindow { } RoomEvent::TrackSubscribed { - track, participant, .. + publication, + participant, + .. } => { let output = self.remote_participant(participant); - match track { - RemoteTrack::Audio(track) => { + match publication.track() { + Some(RemoteTrack::Audio(track)) => { output.audio_output_stream = - Some((track.clone(), play_remote_audio_track(&track, cx))); + Some((publication.clone(), play_remote_audio_track(&track, cx))); } - RemoteTrack::Video(track) => { + Some(RemoteTrack::Video(track)) => { output.screen_share_output_view = Some(( track.clone(), cx.new_view(|cx| RemoteVideoTrackView::new(track, cx)), )); } + None => todo!(), } cx.notify(); } @@ -317,8 +320,12 @@ impl LivekitWindow { None } })?; - let track = participant.audio_output_stream.as_ref()?.0.rtc_track(); - track.set_enabled(!track.enabled()); + let publication = &participant.audio_output_stream.as_ref()?.0; + if publication.is_enabled() { + publication.set_enabled(false); + } else { + publication.set_enabled(true); + } cx.notify(); Some(()) } @@ -390,7 +397,7 @@ impl Render for LivekitWindow { el.child( button() .id(SharedString::from(identity.0.clone())) - .child(if state.0.rtc_track().enabled() { + .child(if state.0.is_enabled() { "Deafen" } else { "Undeafen" ```