From 95069fd3fafd3cd40fb2b48edb061da50796e8db Mon Sep 17 00:00:00 2001 From: Robin Date: Tue, 14 Oct 2025 12:19:23 -0400 Subject: [PATCH] Fix joining call with audio and video muted --- src/state/PublishConnection.ts | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/state/PublishConnection.ts b/src/state/PublishConnection.ts index 23d23fb4..52db6968 100644 --- a/src/state/PublishConnection.ts +++ b/src/state/PublishConnection.ts @@ -109,18 +109,24 @@ export class PublishConnection extends Connection { if (this.stopped) return; - // TODO this can throw errors? It will also prompt for permissions if not already granted - const tracks = await this.livekitRoom.localParticipant.createTracks({ - audio: this.muteStates.audio.enabled$.value, - video: this.muteStates.video.enabled$.value, - }); - if (this.stopped) return; - for (const track of tracks) { - // TODO: handle errors? Needs the signaling connection to be up, but it has some retries internally - // with a timeout. - await this.livekitRoom.localParticipant.publishTrack(track); + // TODO-MULTI-SFU: Prepublish a microphone track + const audio = this.muteStates.audio.enabled$.value; + const video = this.muteStates.video.enabled$.value; + // createTracks throws if called with audio=false and video=false + if (audio || video) { + // TODO this can still throw errors? It will also prompt for permissions if not already granted + const tracks = await this.livekitRoom.localParticipant.createTracks({ + audio, + video, + }); if (this.stopped) return; - // TODO: check if the connection is still active? and break the loop if not? + for (const track of tracks) { + // TODO: handle errors? Needs the signaling connection to be up, but it has some retries internally + // with a timeout. + await this.livekitRoom.localParticipant.publishTrack(track); + if (this.stopped) return; + // TODO: check if the connection is still active? and break the loop if not? + } } }