Repository navigation
Add single peer connection mode via /rtc/v1 #1066
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
Changes from all commits
a9f4cc7
30a20ef
9d1e43f
4adedf6
06e2d8f
b1b013c
b46205a
eec8639
63fac99
f8bb597
1ae2b47
e2ba16a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "client-sdk-android": minor | ||
| --- | ||
|
|
||
| Add `ConnectOptions.singlePeerConnection`, which joins through the `/rtc/v1` signal path and publishes and receives on one peer connection instead of a publisher and a subscriber. The client makes every offer; the server's media sections requirement adds receive-only transceivers, and the answer's mid-to-track mapping resolves received tracks. A server without `/rtc/v1` answers that handshake with 404, in which case the join retries on the legacy path with dual peer connections and later reconnects stay there. The option is off by default. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /* | ||
| * Copyright 2026 LiveKit, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package io.livekit.android.room | ||
|
|
||
| import io.livekit.android.util.LKLog | ||
| import io.livekit.android.webrtc.peerconnection.RTCThreadToken | ||
| import io.livekit.android.webrtc.peerconnection.executeOnRTCThread | ||
| import livekit.org.webrtc.MediaStream | ||
| import livekit.org.webrtc.MediaStreamTrack | ||
| import livekit.org.webrtc.RtpReceiver | ||
| import livekit.org.webrtc.RtpTransceiver | ||
|
|
||
| internal class DuplexTransportObserver(engine: RTCEngine, client: SignalClient, rtcThreadToken: RTCThreadToken) : | ||
| PublisherTransportObserver(engine, client, rtcThreadToken) { | ||
|
|
||
| override fun onTrack(transceiver: RtpTransceiver?) { | ||
| when (transceiver?.mediaType) { | ||
| MediaStreamTrack.MediaType.MEDIA_TYPE_AUDIO -> LKLog.v { "peerconn started receiving audio" } | ||
| MediaStreamTrack.MediaType.MEDIA_TYPE_VIDEO -> LKLog.v { "peerconn started receiving video" } | ||
| else -> LKLog.d { "peerconn started receiving unknown media type: ${transceiver?.mediaType}" } | ||
| } | ||
| } | ||
|
|
||
| override fun onAddTrack(receiver: RtpReceiver?, streams: Array<out MediaStream>?) { | ||
| executeOnRTCThread(rtcThreadToken) { | ||
| if (receiver != null && streams != null) { | ||
| val track = receiver.track() ?: return@executeOnRTCThread | ||
| LKLog.v { "onAddTrack: ${track.kind()}, ${track.id()}, ${streams.fold("") { sum, it -> "$sum, $it" }}" } | ||
| engine.listener?.onAddTrack(receiver, track, streams) | ||
| } | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1305,12 +1305,31 @@ constructor( | |
| return | ||
| } | ||
|
|
||
| val statsGetter = engine.createStatsGetter(receiver) | ||
| attachTrack(participant, receiver, track, trackSid!!) | ||
| } | ||
|
|
||
| /** | ||
| * @suppress | ||
| */ | ||
| override fun onTrackBound(receiver: RtpReceiver, track: MediaStreamTrack, trackSid: String): Boolean { | ||
| val participant = remoteParticipants.values.firstOrNull { it.getTrackPublication(trackSid) != null } | ||
| if (participant == null) { | ||
| LKLog.d { "no publication yet for bound track $trackSid" } | ||
| return false | ||
|
devin-ai-integration[bot] marked this conversation as resolved.
Resolved
|
||
| } | ||
| attachTrack(participant, receiver, track, trackSid) | ||
| return true | ||
| } | ||
|
|
||
| private fun attachTrack(participant: RemoteParticipant, receiver: RtpReceiver, track: MediaStreamTrack, trackSid: String) { | ||
| if (participant.getTrackPublication(trackSid)?.track?.rtcTrack === track) { | ||
| return | ||
| } | ||
| participant.addSubscribedMediaTrack( | ||
| track, | ||
| trackSid!!, | ||
| trackSid, | ||
| autoManageVideo = adaptiveStream, | ||
| statsGetter = statsGetter, | ||
| statsGetter = engine.createStatsGetter(receiver), | ||
| receiver = receiver, | ||
| ) | ||
| } | ||
|
|
@@ -1353,6 +1372,8 @@ constructor( | |
| } | ||
| } | ||
| } | ||
| // A track can be bound before the update that announces its publication. | ||
| engine.attachBoundTracks() | ||
|
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. @changt hey looking over this again, looks like this might create a second remote track and double up events.
The duplicate check in The likely fix is a one-line check in
Contributor
Author
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. Fixing this in the follow up PR! |
||
| } | ||
|
|
||
| /** | ||
|
|
@@ -1731,7 +1752,12 @@ constructor( | |
|
|
||
| sealed class RoomException(message: String? = null, cause: Throwable? = null) : | ||
| Exception(message, cause) { | ||
| class ConnectException(message: String? = null, cause: Throwable? = null) : | ||
| /** | ||
| * @param statusCode HTTP status of the rejected signal connection: the validate endpoint's | ||
| * status when it reported an error, otherwise the websocket handshake's. Null when the | ||
| * failure did not come with an HTTP response, such as a network error. | ||
| */ | ||
| class ConnectException(message: String? = null, cause: Throwable? = null, val statusCode: Int? = null) : | ||
| RoomException(message, cause) | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.