Skip to content

Commit

Permalink
Improve peer connection health check to prevent reconnecting (#1081)
Browse files Browse the repository at this point in the history
Co-authored-by: Aleksandar Apostolov <[email protected]>
  • Loading branch information
liviu-timar and aleksandar-apostolov authored May 2, 2024
1 parent 470c4fc commit cd7dd70
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import kotlinx.coroutines.Job
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import org.openapitools.client.models.OwnCapability
import org.threeten.bp.OffsetDateTime
import org.threeten.bp.temporal.ChronoUnit
import org.webrtc.PeerConnection
Expand Down Expand Up @@ -117,13 +118,19 @@ public class CallHealthMonitor(

val subscriberState = call.session?.subscriber?.state?.value
val publisherState = call.session?.publisher?.state?.value
val healthyPeerConnections = subscriberState in goodStates && publisherState in goodStates
val canPublish = call.state.ownCapabilities.value.any {
it == OwnCapability.SendAudio || it == OwnCapability.SendVideo
}

val isSubConnectionHealthy = subscriberState in goodStates
val isPubConnectionHealthyOrNotNeeded = publisherState in goodStates || (publisherState == null && !canPublish)
val arePeerConnectionsHealthy = isSubConnectionHealthy && isPubConnectionHealthyOrNotNeeded

logger.d {
"checking call health: peers are healthy: $healthyPeerConnections publisher $publisherState subscriber $subscriberState"
"checking call health: peers are healthy: $arePeerConnectionsHealthy publisher $publisherState subscriber $subscriberState"
}

if (healthyPeerConnections) {
if (arePeerConnectionsHealthy) {
// don't reconnect if things are healthy
timeoutJob?.cancel()
timeoutJob = null
Expand Down

0 comments on commit cd7dd70

Please sign in to comment.