Skip to content

Add Transport interface and move RTCEngine peer connections behind it - #1064

Merged
changt merged 3 commits into
mainfrom
sc/dual-peer-connection-transport
Nov 9, 2026
Merged

changt merged 3 commits into
mainfrom
sc/dual-peer-connection-transport

Conversation

@changt

@changt changt commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

RTCEngine now holds a Transport instead of separate publisher and subscriber fields. DualPeerConnectionTransport implements it for the existing two peer connection setup and owns the decisions that depend on that arrangement: ICE candidate routing, answering server offers, which peer connections a resume waits on, and the sync state descriptions. Whether to negotiate the publisher on join stays a transport decision, with hasPublished kept in the engine across full reconnects.

The interface also covers what a single peer connection will need, with DualPeerConnectionTransport keeping today's behavior:

  • applyServerAnswer takes the answer's mid_to_track_id, now passed through SignalClient.Listener.onServerAnswer.
  • trackIdForReceiver resolves a remote track's ID from that mapping; Room.onAddTrack prefers it over the stream ID when present.
  • handleMediaSectionsRequirement handles the MediaSectionsRequirement signal message, which SignalClient now forwards.

Either gains isLeft/isRight with smart-cast contracts.

No behavior changes. This is the first of a series of PRs toward single peer connection support via /rtc/v1.

RTCEngine now holds a Transport instead of separate publisher and
subscriber fields. DualPeerConnectionTransport implements it for the
existing two peer connection setup and owns the decisions that depend on
that arrangement: ICE candidate routing, answering server offers, which
peer connections a resume waits on, and the sync state descriptions.
Whether to negotiate the publisher on join stays a transport decision,
with hasPublished kept in the engine across full reconnects.

The interface also covers what a single peer connection needs, with
DualPeerConnectionTransport keeping today's behavior:
- applyServerAnswer takes the answer's mid_to_track_id, now passed
  through SignalClient.Listener.onServerAnswer.
- trackIdForReceiver resolves a remote track's ID from that mapping;
  Room.onAddTrack prefers it over the stream ID when present.
- handleMediaSectionsRequirement handles the MediaSectionsRequirement
  signal message, which SignalClient now forwards.

Either gains isLeft/isRight with smart-cast contracts.
@changeset-bot

changeset-bot Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 913fa51

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
client-sdk-android Patch

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

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Diffuse output:

Base AAR cache miss. Please run the build job on main to generate the base AAR.

devin-ai-integration[bot]

This comment was marked as resolved.

@changt
changt requested a review from lukasIO November 6, 2026 18:14
…ated

Both peer connections are locals until the DualPeerConnectionTransport
is assigned, so a failure creating the subscriber left the publisher
with no owner: its native PeerConnection has no finalizer and
closeResources could not reach it.
Transport and DualPeerConnectionTransport suppress TooManyFunctions, as
DataStreams does. The baseline entries for the test-only peer connection
getters now match their transport!! form.
Comment on lines +358 to +365
val publisher = pctFactory.create(
rtcConfig,
publisherObserver,
publisherObserver,
)
subscriber?.close()
subscriber = pctFactory.create(
rtcConfig,
subscriberObserver,
null,
)
val subscriber = runCatching { pctFactory.create(rtcConfig, subscriberObserver, null) }
.onFailure { publisher.close() }
.getOrThrow()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is this still a concern for RTCEngine or is this a concern for DualPeerConnectionTransport?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The creation of the publisher and subscriber is staying with RTCEngine, so it's a concern for the engine.

@lukasIO lukasIO Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see, I guess my question is why it's still on the engine.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

mainly, it's a smaller delta, so easier to review and ensure correctness.

* Whether the publisher connects only once something is published or sent, rather than
* as part of joining.
*/
val publisherConnectsOnDemand: Boolean

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this looks unused? Is this for single peer connection?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes. The unused fields are for single peer connection.

@changt
changt merged commit db9a083 into main Nov 9, 2026
6 checks passed
@changt
changt deleted the sc/dual-peer-connection-transport branch November 9, 2026 21:08
@davidliu davidliu mentioned this pull request Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants