Repository navigation
Conversation
🦋 Changeset detectedLatest commit: 1bc82e7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
This PR also affects a pause that the SDK starts. We see this on iOS Safari (iOS 26, livekit-client 2.23.0). Steps
Result: Remote participants see the camera as muted. Only a page reload fixes it. Effect of this PR: The PR keeps a paused track paused after a republish. This is correct for a pause from the app. For a pause from the SDK, it keeps a live camera paused. Possible fix: Record why the upstream is paused. Clear a pause from the capture Our workaround: On Line numbers are from the |
| name: opts.name, | ||
| type: Track.kindToProto(track.kind), | ||
| muted: track.isMuted, | ||
| // the server sees a paused upstream as muted, see onTrackUpstreamPaused |
There was a problem hiding this comment.
| // the server sees a paused upstream as muted, see onTrackUpstreamPaused |
| cid: simulcastTrack.mediaStreamTrack.id, | ||
| type: Track.kindToProto(track.kind), | ||
| muted: track.isMuted, | ||
| // match the primary publish request, the backup sender starts without a paused track |
There was a problem hiding this comment.
| // match the primary publish request, the backup sender starts without a paused track |
| throw new UnexpectedConnectionState('Required webRTC APIs not supported on this device'); | ||
| } | ||
| this.setupFrameMetadataSender(sender, opts); | ||
| await this.keepPausedTrackOffSender(track, sender); |
There was a problem hiding this comment.
This also catches a pause the SDK starts itself (capture mute → pauseUpstream() after 5s). On a full reconnect republishAllTracks() clears track.sender before restartTrack(), so the resumeUpstream() in setMediaStreamTrack returns early and the flag stays true on a live capture. Same for an unmute that fires between the unpublish and the new sender being assigned.
So far media still flowed in those cases. With this change the track stays dead until the app calls resumeUpstream(), which is what dklima describes above.
Could LocalTrack record who paused (app vs. device), clear a device pause when the restart yields a live capture, and keep the app one?
| // a track republished while its upstream is paused (e.g. after a full reconnect) gets a new | ||
| // sender, which pauseUpstream() never saw: the sender has to start without the track | ||
| private async keepPausedTrackOffSender(track: LocalTrack, sender: RTCRtpSender) { | ||
| if (track.isUpstreamPaused) { | ||
| await sender.replaceTrack(null); | ||
| } | ||
| } |
There was a problem hiding this comment.
Could this live on the track instead of the engine? LocalTrack / LocalVideoTrack own _isUpstreamPaused and every other replaceTrack(null). setSimulcastTrackSender() already receives the backup sender, and the primary could go through a small track method where publish() assigns track.sender.
| // sender, which pauseUpstream() never saw: the sender has to start without the track | ||
| private async keepPausedTrackOffSender(track: LocalTrack, sender: RTCRtpSender) { | ||
| if (track.isUpstreamPaused) { | ||
| await sender.replaceTrack(null); |
There was a problem hiding this comment.
Did you get to try this against a server on Firefox and Safari? In Chromium the first offer keeps a=msid with the track id after replaceTrack(null), so the cid still matches there. I have not checked the other browsers, or how the server treats a new publication that never receives RTP.
| }); | ||
| }); | ||
|
|
||
| describe('createSender', () => { |
There was a problem hiding this comment.
Could we add a case for the restart path: pause → republishAllTracks() with restartTracks = true → still paused, and resumeUpstream() puts the track back on the new sender?
The app pause only survives that path today because resumeUpstream() is a no-op without a sender. Any other restart clears the pause, so this is easy to break.
| type: Track.kindToProto(track.kind), | ||
| muted: track.isMuted, | ||
| // the server sees a paused upstream as muted, see onTrackUpstreamPaused | ||
| muted: track.isMuted || track.isUpstreamPaused, |
There was a problem hiding this comment.
nit: isMuted || isUpstreamPaused now exists in four places (updateInfo, onTrackUnmuted, here, and the backup codec request). Worth a getter on LocalTrack
Problem
pauseUpstream()stops sending a track without stopping it locally, so the app can keep showing its own preview. The paused state is stored on theLocalTrack(_isUpstreamPaused), and the null track is set on theRTCRtpSenderonly.After a full reconnect,
republishAllTracks()unpublishes every track and publishes it again withpublishOrRepublishTrack(). The track keepsisUpstreamPaused === true, but:MediaStreamTrack, so media flows to the SFU again;AddTrackRequestis sent withmuted: track.isMuted, so the server sees the track as unmuted;pauseUpstream()again does nothing, because of theif (this._isUpstreamPaused === true) returnguard.updateInfo()resends the mute state (pub.isMuted || track.isUpstreamPaused), but only for tracks that are in a participant update received after the republish, so the server can stay out of sync. Even when it does fix the mute state, the sender still sends media. The app can only get out of this withresumeUpstream()followed bypauseUpstream().The same thing happens to a backup codec published while the track is paused:
createSimulcastSender()attaches the clone even thoughpauseUpstream()had nulled the other senders.Repro
track.pauseUpstream().room.simulateScenario('full-reconnect').track.isUpstreamPausedis stilltrue.Fix
RTCEngine.createSender()andcreateSimulcastSender()callreplaceTrack(null)on the new sender when the track is paused. This runs before the sender is assigned to the track and before negotiation, so no media is sent.resumeUpstream()works as before: it putsmediaStreamTrackback ontrack.senderand the backup codec senders.AddTrackRequestannouncesmuted: track.isMuted || track.isUpstreamPaused, which is whatonTrackUpstreamPausedandupdateInfo()already send. The backup codec request frompublishAdditionalCodecForTrack()does the same.The change applies to every path that publishes a paused track again: full reconnect, E2EE toggle (
setE2EEEnabled→republishAllTracks), or the app publishing a track it unpublished while paused.Tests
Each new test failed before the fix and passes after it:
RTCEngine.test.ts: a paused track getsreplaceTrack(null)on its new sender and on a new backup codec sender; a track that is not paused is left on its sender.LocalParticipant.test.ts: the add track request of a paused track hasmuted: true, and so does the request for its backup codec.pnpm test,tsc --noEmitand eslint pass. I didn't run the e2e suite against a server.Context
We hit this in WorkAdventure, which never unpublishes the camera or microphone and uses
pauseUpstream()instead. We currently work around it onLocalTrackPublishedwithresumeUpstream()and thenpauseUpstream()(workadventure/workadventure#6800). We'll remove that once this is released.