Skip to content

Commit

Permalink
Start connectivity checks after candidate exchange
Browse files Browse the repository at this point in the history
  • Loading branch information
Brutus5000 committed May 12, 2024
1 parent bd9074f commit 2ac313a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
15 changes: 10 additions & 5 deletions kia-lib/src/main/kotlin/com/faforever/ice/IceAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ class IceAdapter(
publishIceConnectionState = onIceConnectionStateChanged,
)

val connectivityCheckHandler = connectivityChecker.registerPlayer(remotePeerOrchestrator)
remotePeerOrchestrator.initialize(connectivityCheckHandler)
remotePeerOrchestrator.initialize()

players[remotePlayerId] = remotePeerOrchestrator

Expand All @@ -174,12 +173,11 @@ class IceAdapter(
isOfferer = offer,
forceRelay = iceOptions.forceRelay,
coturnServers = coturnServers,
publishLocalCandidates = onIceCandidatesGathered,
publishLocalCandidates = ::onIceCandidates,
publishIceConnectionState = onIceConnectionStateChanged,
)

val connectivityCheckHandler = connectivityChecker.registerPlayer(remotePeerOrchestrator)
remotePeerOrchestrator.initialize(connectivityCheckHandler)
remotePeerOrchestrator.initialize()

players[remotePlayerId] = remotePeerOrchestrator

Expand Down Expand Up @@ -227,4 +225,11 @@ class IceAdapter(
logger.debug { "sendToGpgNet: message=$message" }
gpgnetProxy.sendGpgnetMessage(message)
}

private fun onIceCandidates(candidatesMessage: CandidatesMessage) {
val remotePeerOrchestrator = players[candidatesMessage.destinationId]!!
val connectivityCheckHandler = connectivityChecker.registerPlayer(remotePeerOrchestrator)
remotePeerOrchestrator.setConnectivityCheckHandler(connectivityCheckHandler)
this.onIceCandidatesGathered(candidatesMessage)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class RemotePeerOrchestrator(
@Volatile
private var closing = false

fun initialize(connectivityCheckHandler: ConnectivityCheckHandler) {
fun initialize() {
withLoggingContext("remotePlayerId" to remotePlayerId.toString()) {
synchronized(objectLock) {
if (this.iceState.isNotIn(IceState.NEW, IceState.DISCONNECTED)) {
Expand All @@ -64,12 +64,21 @@ class RemotePeerOrchestrator(
name = "player-$remotePlayerId",
).apply { start() }

this.connectivityCheckHandler = connectivityCheckHandler
initAgent()
}
}
}

fun setConnectivityCheckHandler(checkHandler: ConnectivityCheckHandler) {
val currentHandler = connectivityCheckHandler
if (currentHandler != null) {
logger.warn { "ConnectivityCheckHandler was already set, disconnecting" }
currentHandler.disconnected()
}

this.connectivityCheckHandler = checkHandler
}

private fun initAgent() {
agent = AgentWrapper(
localPlayerId = localPlayerId,
Expand Down

0 comments on commit 2ac313a

Please sign in to comment.