Skip to content

Commit

Permalink
Force relay client configuration (livekit#155)
Browse files Browse the repository at this point in the history
* Update protocol submodule

* Force relay configuration

* tests
  • Loading branch information
davidliu authored Oct 24, 2022
1 parent 57d4616 commit cec0b2b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,14 @@ internal constructor(
PeerConnection.ContinualGatheringPolicy.GATHER_CONTINUALLY
}

if (joinResponse.hasClientConfiguration()) {
val clientConfig = joinResponse.clientConfiguration

if (clientConfig.forceRelay == LivekitModels.ClientConfigSetting.ENABLED) {
rtcConfig.iceTransportsType = PeerConnection.IceTransportsType.RELAY
}
}

_publisher?.close()
_publisher = pctFactory.create(
rtcConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ private class MockNativePeerConnectionFactory : NativePeerConnectionFactory {
}

class MockPeerConnection(
val observer: PeerConnection.Observer?
val rtcConfig: RTCConfiguration,
val observer: Observer?
) : PeerConnection(MockNativePeerConnectionFactory()) {

private var closed = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import io.livekit.android.mock.MockPeerConnection
import io.livekit.android.util.toOkioByteString
import io.livekit.android.util.toPBByteString
import kotlinx.coroutines.ExperimentalCoroutinesApi
import livekit.LivekitModels
import livekit.LivekitRtc
import org.junit.Assert
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
Expand Down Expand Up @@ -95,4 +97,21 @@ class RTCEngineMockE2ETest : MockE2ETest() {
Assert.assertNotEquals(oldToken, newToken)
Assert.assertEquals(SignalClientTest.REFRESH_TOKEN.refreshToken, newToken)
}

@Test
fun relayConfiguration() = runTest {
connect(with(SignalClientTest.JOIN.toBuilder()) {
join = with(join.toBuilder()) {
clientConfiguration = with(LivekitModels.ClientConfiguration.newBuilder()) {
forceRelay = LivekitModels.ClientConfigSetting.ENABLED
build()
}
build()
}
build()
})

val pubPeerConnection = rtcEngine.subscriber.peerConnection as MockPeerConnection
assertEquals(PeerConnection.IceTransportsType.RELAY, pubPeerConnection.rtcConfig.iceTransportsType)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import io.livekit.android.mock.MockPeerConnection

class MockPeerConnectionFactory : PeerConnectionFactory(1L) {
override fun createPeerConnectionInternal(
rtcConfig: PeerConnection.RTCConfiguration?,
rtcConfig: PeerConnection.RTCConfiguration,
constraints: MediaConstraints?,
observer: PeerConnection.Observer?,
sslCertificateVerifier: SSLCertificateVerifier?
): PeerConnection {
return MockPeerConnection(observer)
return MockPeerConnection(rtcConfig, observer)
}
}

0 comments on commit cec0b2b

Please sign in to comment.