Skip to content

Instantly share code, notes, and snippets.

@skydoves
Last active January 27, 2023 05:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skydoves/d545474ee297951bcea4356a5d5c7268 to your computer and use it in GitHub Desktop.
Save skydoves/d545474ee297951bcea4356a5d5c7268 to your computer and use it in GitHub Desktop.
Handling Signaling Messages
// Copyright 2023 Stream.IO, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
init {
sessionManagerScope.launch {
signalingClient.signalingCommandFlow
.collect { commandToValue ->
when (commandToValue.first) {
SignalingCommand.OFFER -> handleOffer(commandToValue.second)
SignalingCommand.ANSWER -> handleAnswer(commandToValue.second)
SignalingCommand.ICE -> handleIce(commandToValue.second)
else -> Unit
}
}
}
}
private fun handleOffer(sdp: String) {
logger.d { "[SDP] handle offer: $sdp" }
offer = sdp
}
private suspend fun handleAnswer(sdp: String) {
logger.d { "[SDP] handle answer: $sdp" }
peerConnection.setRemoteDescription(
SessionDescription(SessionDescription.Type.ANSWER, sdp)
)
}
private suspend fun handleIce(iceMessage: String) {
val iceArray = iceMessage.split(ICE_SEPARATOR)
peerConnection.addIceCandidate(
IceCandidate(
iceArray[0],
iceArray[1].toInt(),
iceArray[2]
)
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment