Skip to content
Merged
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
12 changes: 12 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@
"name": "wgpu_room(debug)",
"program": "${workspaceFolder}/examples/target/debug/wgpu_room",
"preLaunchTask": "build"
},
Copy link
Contributor

@ladvoc ladvoc Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a strong opinion, but do you think we should commit this launch configuration?

{
"type": "lldb",
"request": "launch",
"name": "local_audio(debug)",
"program": "${workspaceFolder}/target/debug/local_audio",
"preLaunchTask": "build",
"env": {
"LIVEKIT_URL": "ws://localhost:7880",
"LIVEKIT_API_KEY": "testkey",
"LIVEKIT_API_SECRET": "testsecret",
},
}
]
}
48 changes: 47 additions & 1 deletion examples/local_audio/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,38 @@ async fn stream_audio_to_livekit_with_shared_apm(
Ok(())
}

async fn handle_room_events(room: Arc<Room>) -> Result<()> {
let mut room_events = room.subscribe();

while let Some(event) = room_events.recv().await {
match event {
RoomEvent::TrackMuted { participant, publication } => {
println!(
"Track muted by {}: {} ({:?})",
participant.identity(),
publication.name(),
publication.kind()
);
}

RoomEvent::TrackUnmuted { participant, publication } => {
println!(
"Track unmuted by {}: {} ({:?})",
participant.identity(),
publication.name(),
publication.kind()
);
}
_ => {
// Handle other room events as needed
debug!("Room event: {:?}", event);
}
}
}

Ok(())
}

async fn handle_remote_audio_streams(
room: Arc<Room>,
mixer: AudioMixer,
Expand Down Expand Up @@ -573,6 +605,9 @@ async fn main() -> Result<()> {
1000, // 1 second buffer
);

// Handle room events
tokio::spawn(handle_room_events(room.clone()));

// Create and publish audio track
let track = LocalAudioTrack::create_audio_track(
"microphone",
Expand All @@ -581,7 +616,7 @@ async fn main() -> Result<()> {

room.local_participant()
.publish_track(
LocalTrack::Audio(track),
LocalTrack::Audio(track.clone()),
TrackPublishOptions { source: TrackSource::Microphone, ..Default::default() },
)
.await?;
Expand Down Expand Up @@ -702,6 +737,17 @@ async fn main() -> Result<()> {
if _audio_playback.is_some() { "Enabled" } else { "Disabled" }
);

// Demonstrate muting/unmuting the microphone track
tokio::spawn(async move {
// Demonstrate muting/unmuting after some time
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
track.mute();
info!("Microphone muted for 5 seconds...");
tokio::time::sleep(tokio::time::Duration::from_secs(5)).await;
track.unmute();
info!("Microphone unmuted.");
});

// Wait for Ctrl+C
tokio::signal::ctrl_c().await?;
info!("\nShutting down...");
Expand Down
3 changes: 3 additions & 0 deletions livekit/src/room/participant/local_participant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,9 @@ impl LocalParticipant {
let publication = LocalTrackPublication::new(track_info.clone(), track.clone());
track.update_info(track_info); // Update sid + source

// set track for publication to listen mute/unmute events
publication.set_track(Some(track.clone().into()));

let transceiver =
self.inner.rtc_engine.create_sender(track.clone(), options.clone(), encodings).await?;

Expand Down
1 change: 1 addition & 0 deletions livekit/src/room/participant/remote_participant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ impl RemoteParticipant {
name: remote_publication.name(),
r#type: proto::TrackType::from(remote_publication.kind()) as i32,
source: proto::TrackSource::from(remote_publication.source()) as i32,
muted: remote_publication.is_muted(),
..Default::default()
});

Expand Down
2 changes: 1 addition & 1 deletion livekit/src/room/track/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ pub(super) fn set_muted(inner: &Arc<TrackInner>, track: &Track, muted: bool) {
if let Some(on_mute) = inner.events.lock().muted.as_ref() {
on_mute(track.clone());
}
} else if let Some(on_unmute) = inner.events.lock().muted.as_ref() {
} else if let Some(on_unmute) = inner.events.lock().unmuted.as_ref() {
on_unmute(track.clone());
}
}
Expand Down