@@ -31,6 +31,8 @@ import io.getstream.video.android.core.model.IceCandidate
3131import kotlinx.coroutines.CancellableContinuation
3232import kotlinx.coroutines.CoroutineScope
3333import kotlinx.coroutines.channels.Channel
34+ import kotlinx.coroutines.ensureActive
35+ import kotlinx.coroutines.flow.receiveAsFlow
3436import kotlinx.coroutines.launch
3537import kotlinx.serialization.json.Json
3638import okhttp3.OkHttpClient
@@ -79,8 +81,11 @@ public class SfuSocket(
7981 // Only set during SFU migration
8082 private var migrationData: (suspend () -> Migration )? = null
8183
82- internal val pendingPublisherIceCandidates = Channel <IceCandidate >(capacity = 99 )
83- internal val pendingSubscriberIceCandidates = Channel <IceCandidate >(capacity = 99 )
84+ private val _pendingPublisherIceCandidates = Channel <IceCandidate >(capacity = 99 )
85+ internal val pendingPublisherIceCandidates = _pendingPublisherIceCandidates .receiveAsFlow()
86+
87+ private val _pendingSubscriberIceCandidates = Channel <IceCandidate >(capacity = 99 )
88+ internal val pendingSubscriberIceCandidates = _pendingSubscriberIceCandidates .receiveAsFlow()
8489
8590 private val clientDetails
8691 get() = ClientDetails (
@@ -206,6 +211,7 @@ public class SfuSocket(
206211 handleIceTrickle(message)
207212 }
208213 } catch (error: Throwable ) {
214+ coroutineContext.ensureActive()
209215 logger.e { " [onMessage] failed: $error " }
210216 handleError(error)
211217 }
@@ -218,9 +224,9 @@ public class SfuSocket(
218224 }
219225 val iceCandidate: IceCandidate = Json .decodeFromString(event.candidate)
220226 val result = if (event.peerType == PeerType .PEER_TYPE_PUBLISHER_UNSPECIFIED ) {
221- pendingPublisherIceCandidates .send(iceCandidate)
227+ _pendingPublisherIceCandidates .send(iceCandidate)
222228 } else {
223- pendingSubscriberIceCandidates .send(iceCandidate)
229+ _pendingSubscriberIceCandidates .send(iceCandidate)
224230 }
225231 logger.v { " [handleTrickle] #sfu; #${event.peerType.stringify()} ; result: $result " }
226232 }
0 commit comments