David Zhao

Improved reconnection when network changes.

<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<JetCodeStyleSettings>
<option name="PACKAGES_TO_USE_STAR_IMPORTS">
<value>
<package name="java.util" alias="false" withSubpackages="false" />
<package name="kotlinx.android.synthetic" alias="false" withSubpackages="true" />
<package name="io.ktor" alias="false" withSubpackages="true" />
</value>
</option>
<option name="PACKAGES_IMPORT_LAYOUT">
<value>
<package name="" alias="false" withSubpackages="true" />
<package name="java" alias="false" withSubpackages="true" />
<package name="javax" alias="false" withSubpackages="true" />
<package name="kotlin" alias="false" withSubpackages="true" />
<package name="" alias="true" withSubpackages="true" />
</value>
</option>
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
</JetCodeStyleSettings>
<codeStyleSettings language="XML">
... ...
... ... @@ -11,7 +11,7 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.0-beta03'
classpath 'com.android.tools.build:gradle:7.0.0-beta04'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version"
... ...
#Thu Apr 29 14:50:17 JST 2021
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
... ...
... ... @@ -25,9 +25,10 @@ constructor(
listener
) ?: throw IllegalStateException("peer connection creation failed?")
val pendingCandidates = mutableListOf<IceCandidate>()
var iceRestart: Boolean = false
fun addIceCandidate(candidate: IceCandidate) {
if (peerConnection.remoteDescription != null) {
if (peerConnection.remoteDescription != null && !iceRestart) {
peerConnection.addIceCandidate(candidate)
} else {
pendingCandidates.add(candidate)
... ... @@ -42,6 +43,7 @@ constructor(
peerConnection.addIceCandidate(pending)
}
pendingCandidates.clear()
iceRestart = false
super.onSetSuccess()
}
}
... ... @@ -50,6 +52,10 @@ constructor(
return observer.awaitSet()
}
fun prepareForIceRestart() {
iceRestart = true
}
fun close() {
peerConnection.close()
}
... ...
... ... @@ -276,6 +276,8 @@ constructor(
// trigger ICE restart
iceState = IceState.RECONNECTING
publisher.prepareForIceRestart()
subscriber.prepareForIceRestart()
negotiate()
}
... ...
... ... @@ -114,14 +114,14 @@ constructor(
}
override fun onFailure(webSocket: WebSocket, t: Throwable, response: Response?) {
Timber.v(t) { "websocket failure: ${response}" }
Timber.v(t) { "websocket failure: $response" }
super.onFailure(webSocket, t, response)
}
//------------------------------- End WebSocket Listener ------------------------------------//
fun fromProtoSessionDescription(sd: LivekitRtc.SessionDescription): SessionDescription {
private fun fromProtoSessionDescription(sd: LivekitRtc.SessionDescription): SessionDescription {
val rtcSdpType = when (sd.type) {
SD_TYPE_ANSWER -> SessionDescription.Type.ANSWER
SD_TYPE_OFFER -> SessionDescription.Type.OFFER
... ... @@ -131,7 +131,7 @@ constructor(
return SessionDescription(rtcSdpType, sd.sdp)
}
fun toProtoSessionDescription(sdp: SessionDescription): LivekitRtc.SessionDescription {
private fun toProtoSessionDescription(sdp: SessionDescription): LivekitRtc.SessionDescription {
val sdBuilder = LivekitRtc.SessionDescription.newBuilder()
sdBuilder.sdp = sdp.description
sdBuilder.type = when (sdp.type) {
... ... @@ -224,11 +224,10 @@ constructor(
sendRequest(request)
}
fun sendUpdateSubscription(sid: String, subscribe: Boolean, videoQuality: LivekitRtc.VideoQuality) {
fun sendUpdateSubscription(sid: String, subscribe: Boolean) {
val subscription = LivekitRtc.UpdateSubscription.newBuilder()
.addTrackSids(sid)
.setSubscribe(subscribe)
.setQuality(videoQuality)
val request = LivekitRtc.SignalRequest.newBuilder()
.setSubscription(subscription)
... ... @@ -247,7 +246,8 @@ constructor(
private fun sendRequest(request: LivekitRtc.SignalRequest) {
Timber.v { "sending request: $request" }
if (!isConnected || currentWs == null) {
throw IllegalStateException("not connected!")
Timber.w { "not connected, could not send request $request" }
return
}
val sent: Boolean
if (useJson) {
... ... @@ -340,7 +340,7 @@ constructor(
const val SD_TYPE_ANSWER = "answer"
const val SD_TYPE_OFFER = "offer"
const val SD_TYPE_PRANSWER = "pranswer"
const val PROTOCOL_VERSION = 2;
const val PROTOCOL_VERSION = 2
private fun iceServer(url: String) =
PeerConnection.IceServer.builder(url).createIceServer()
... ...
... ... @@ -44,7 +44,7 @@ class RemoteTrackPublication(
unsubscribed = !subscribed
val participant = this.participant.get() as? RemoteParticipant ?: return
participant.signalClient.sendUpdateSubscription(sid, !unsubscribed, videoQuality)
participant.signalClient.sendUpdateSubscription(sid, !unsubscribed)
}
/**
... ...