Repository navigation
Conversation
In single peer connection mode the client is the only offerer, so the publisher, its three data channels and the first offer are built before the signal socket opens and the offer travels in JoinRequest.publisher_offer. The server answers it over the signal channel right after the JoinResponse, which removes one offer/answer round trip from the connect path. PeerConnectionTransport.createInitialOffer creates and munges the offer but does not apply it: setLocalDescription would start ICE gathering before the server's ICE servers are known. The offer stays pending and setRemoteDescription applies it just before the answer. While it is pending, negotiate queues a renegotiation the same way as for an offer already in flight. Offer creation and munging are shared with createAndSendOffer through createMungedOffer. RTCEngine builds the early publisher with a client-side configuration (makeRTCConfig with no server response) and configure adopts it, installing the server's ICE servers and relay policy through updateRTCConfig before the pending offer can be applied. The eager negotiate on join is skipped while the initial offer is pending. Not yet handled: closing the early publisher when the join fails, and the /rtc/v1 404 fallback, which still adopts it. The two fallback reconnect tests in SinglePeerConnectionFallbackMockE2ETest fail until then.
The publisher created ahead of a single peer connection join lived in locals of joinImpl, so a join that failed before configure ran left it with no owner, and the /rtc/v1 404 fallback handed the already-closed publisher to configure, which adopted it into the dual peer connection transport. RTCEngine now holds the early publisher and its observer in fields. configure adopts them into the transport and clears the fields once the data channels are in place; closeResources closes a publisher that was never adopted, which covers a failed or cancelled join through the engine's normal teardown. The 404 fallback calls closeEarlyPublisher before the legacy join, so that join starts from nothing. The helper also disposes the publisher's data channels, and closeResources reuses it for that side of the teardown. The two SinglePeerConnectionFallbackMockE2ETest reconnect tests pass again.
SinglePeerConnectionMockE2ETest answered the last offer sent over the signal connection after joining. With the publisher offer bundled in the /rtc/v1 join request there is no such offer, so every test that connects failed on an empty list. The connect helper now decodes the offer from the join request URL and answers that one by id. publisherOfferRidesInTheJoinRequest checks that the offer travels with the join request and that nothing is offered over the signal connection before or after its answer. The detekt baseline entry for makeRTCConfig takes the nullable server response the function has had since the early publisher was added.
createInitialOffer bundled the munged description as is. The ordinary offer path sends whatever setMungedSdp managed to apply, so an empty munge falls back to the offer libwebrtc created, but the initial offer is sent before anything is applied and had no such step: an empty munge went to the server as an empty publisher offer. createInitialOffer now bundles the unmunged description in that case. The pending offer is the bundled one, so what the server answers is what the answer path sets locally. In the mock E2E suite createOffer returns a placeholder that munges to nothing, so publisherOfferRidesInTheJoinRequest can now also check that the bundled SDP is not empty and becomes the local description once it is answered.
changt
requested review from
MaxHeimbrock,
davidliu and
xianshijing-lk
as code owners
November 13, 2026 23:37
🦋 Changeset detectedLatest commit: a730a78 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 |
Contributor
|
Diffuse output: AARJAR |
RTCEngine counts as closed until a join response arrives, and close returns early in that state. The early publisher is created before the response, so a rejected or cancelled first join left it in its field with nothing to dispose it: Room's close after the failure did nothing, and a retry against another region replaced the field and dropped the only reference to the first peer connection. close now disposes an unadopted early publisher even when the engine is already closed, and joinImpl disposes one that an earlier join left behind before creating the next. SinglePeerConnectionFailedJoinMockE2ETest covers both paths. MockPeerConnectionFactory records the peer connections it creates so the tests can reach the early publisher.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
In single peer connection mode the client makes every offer, so the first one no longer waits for the join to finish. The publisher peer connection, its three data channels and the initial offer are created before the signal socket opens, and the offer travels in
JoinRequest.publisher_offer. The server answers it over the signal channel right after theJoinResponse, which removes one offer/answer round trip from connecting. Same approach as livekit/client-sdk-js#1846, livekit/rust-sdks#996 and livekit/client-sdk-swift#1111.Follows #1066. Only joins with
ConnectOptions.singlePeerConnectionare affected.PeerConnectionTransportcreateInitialOffercreates and munges the offer but does not apply it:setLocalDescriptionwould start ICE gathering before the server's ICE servers are known. The offer stays pending, andsetRemoteDescriptionapplies it as the local description just before the answer.negotiatequeues a renegotiation, the same way it does for an offer already in flight. A publish that races the join therefore waits for the answer instead of offering over the bundled offer.createAndSendOfferthroughcreateMungedOffer.RTCEngineconfigureadopts them into the transport and installs the server's ICE servers and relay policy throughupdateRTCConfig.SignalClientholds responses untilconfigureis done, so the answer is applied after that.closedisposes it even when the join ended before its response, a point at which the engine still counts as closed. A new join disposes one left by an earlier attempt, such as a region retry.closeResourcesdisposes it on teardown and before a full reconnect's join./rtc/v1404 fallback the early publisher and its data channels are closed before the legacy join, so that join starts from nothing.makeRTCConfigaccepts a missing server response, for the configuration the early publisher starts with.Signal
SignalClient.jointakes an optionalpublisherOfferand passes it toSignalUrlBuilder.buildJoinRequestUrl.SinglePeerConnectionTransportskips the eager negotiate on join while the initial offer is pending.Not included
Tests
PeerConnectionTransportTest(new) covers the initial offer: offer id, constraints, munging, the empty-munge case, not being applied or sent, being applied before the answer, and queued negotiation.SinglePeerConnectionMockE2ETestnow answers the offer decoded from the join request and checks that nothing is offered over the signal connection.SinglePeerConnectionFallbackMockE2ETestcovers the 404 fallback and the reconnects after it.SinglePeerConnectionFailedJoinMockE2ETest(new) covers a rejected join and a join that follows a rejected one: in both, the earlier publisher is closed.Not yet run on a device against a live server.