feat: reset peer connection on DC to prevent ICE messages from old connection or stale state in reconnecting

This commit is contained in:
jubb 2022-03-09 10:11:26 +11:00
parent b69c4d490d
commit c16ca83279
3 changed files with 11 additions and 7 deletions

View File

@ -103,7 +103,7 @@ class WebRtcCallService: Service(), CallManager.WebRtcListener {
const val EXTRA_WANTS_TO_ANSWER = "wants_to_answer"
const val INVALID_NOTIFICATION_ID = -1
private const val TIMEOUT_SECONDS = 30L
private const val TIMEOUT_SECONDS = 90L
private const val RECONNECT_SECONDS = 5L
private const val MAX_RECONNECTS = 5
@ -820,6 +820,7 @@ class WebRtcCallService: Service(), CallManager.WebRtcListener {
.setAction(ACTION_ICE_CONNECTED)
startService(intent)
} else if (newState in arrayOf(FAILED, DISCONNECTED) && scheduledReconnect == null) {
callManager.resetPeerConnection()
callManager.callId?.let { callId ->
callManager.postConnectionEvent(Event.IceDisconnect) {
val currentNetwork = getCurrentNetwork()

View File

@ -705,6 +705,10 @@ class CallManager(context: Context, audioManager: AudioManagerCompat, private va
}
}
fun resetPeerConnection() {
peerConnection?.resetPeerConnection()
}
interface WebRtcListener: PeerConnection.Observer {
fun onHangup()
}

View File

@ -143,9 +143,6 @@ class PeerConnectionWrapper(private val context: Context,
fun setNewRemoteDescription(description: SessionDescription) {
val future = SettableFuture<Boolean>()
peerConnection?.close()
initPeerConnection()
peerConnection!!.setRemoteDescription(object: SdpObserver {
override fun onCreateSuccess(p0: SessionDescription?) {
throw AssertionError()
@ -243,9 +240,6 @@ class PeerConnectionWrapper(private val context: Context,
fun createNewOffer(mediaConstraints: MediaConstraints): SessionDescription {
val future = SettableFuture<SessionDescription>()
peerConnection?.close()
initPeerConnection()
peerConnection!!.createOffer(object:SdpObserver {
override fun onCreateSuccess(sdp: SessionDescription?) {
future.set(sdp)
@ -363,4 +357,9 @@ class PeerConnectionWrapper(private val context: Context,
rotationVideoSink.mirrored = newCameraState.activeDirection == CameraState.Direction.FRONT
cameraEventListener.onCameraSwitchCompleted(newCameraState)
}
fun resetPeerConnection() {
peerConnection?.close()
initPeerConnection()
}
}