-
Notifications
You must be signed in to change notification settings - Fork 161
Fix: Publisher re-enable tracks after room connected in case of timeout #3674
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
Open
BillCarsonFr
wants to merge
1
commit into
livekit
Choose a base branch
from
valere/bug/auto_recover_publish_timeout
base: livekit
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+86
−5
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ import { | |
| LocalVideoTrack, | ||
| ParticipantEvent, | ||
| type Room as LivekitRoom, | ||
| RoomEvent as LivekitRoomEvent, | ||
| Track, | ||
| } from "livekit-client"; | ||
| import { | ||
|
|
@@ -89,6 +90,23 @@ export class Publisher { | |
| ParticipantEvent.LocalTrackPublished, | ||
| this.onLocalTrackPublished.bind(this), | ||
| ); | ||
|
|
||
| this.connection.livekitRoom.once(LivekitRoomEvent.Connected, () => { | ||
| // When `createAndSetupTracks` is called before the connection is established, | ||
| // there is an internal timeout in livekit that could be triggered if it takes | ||
| // too long to connect. | ||
| // It is no-op if tracks are already created, so it is safe to call it again. | ||
| const audio = this.muteStates.audio.enabled$.value; | ||
| const video = this.muteStates.video.enabled$.value; | ||
| this.enableTracks(audio, video, this.connection.livekitRoom).catch( | ||
| (e) => { | ||
| this.logger.error( | ||
| "Failed to enable tracks after connection established", | ||
| e, | ||
| ); | ||
| }, | ||
| ); | ||
| }); | ||
| } | ||
|
|
||
| // LiveKit will publish the tracks as soon as they are created | ||
|
|
@@ -157,16 +175,29 @@ export class Publisher { | |
| // We are using the `ParticipantEvent.LocalTrackPublished` to be notified | ||
| // when tracks are actually published, and at that point | ||
| // we can pause upstream if needed (depending on if startPublishing has been called). | ||
| this.enableTracks(audio, video, lkRoom).catch((e) => { | ||
| // If it is PublisherTrackError (408), i.e the publishing timed out, | ||
| // because it took too long to connet to the room, we are safe because | ||
| // we registered to the RoomEvent.Connected to create the tracks once connected. | ||
| this.logger.error("Failed to enable tracks", e); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want to inform the console log about that as well: and (very minor) |
||
| }); | ||
|
|
||
| return Promise.resolve(); | ||
| } | ||
|
|
||
| private async enableTracks( | ||
| audio: boolean, | ||
| video: boolean, | ||
| lkRoom: LivekitRoom, | ||
| ): Promise<void> { | ||
| if (audio && video) { | ||
| // Enable both at once in order to have a single permission prompt! | ||
| void lkRoom.localParticipant.enableCameraAndMicrophone(); | ||
| await lkRoom.localParticipant.enableCameraAndMicrophone(); | ||
| } else if (audio) { | ||
| void lkRoom.localParticipant.setMicrophoneEnabled(true); | ||
| await lkRoom.localParticipant.setMicrophoneEnabled(true); | ||
| } else if (video) { | ||
| void lkRoom.localParticipant.setCameraEnabled(true); | ||
| await lkRoom.localParticipant.setCameraEnabled(true); | ||
| } | ||
|
|
||
| return Promise.resolve(); | ||
| } | ||
|
|
||
| private async pauseUpstreams( | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm noticing some leaks: both the
LocalTrackPublishedcallback and theConnectedcallback should not remain set after the scope ends