From c712a03768d2698d017b32a276bb78d6e05b311e Mon Sep 17 00:00:00 2001 From: Alex Stelea Date: Fri, 26 Jan 2024 23:11:42 +0800 Subject: [PATCH] fix: wait for onRemoteDescriptionSuccess before adding ice candidates --- src/connector/webrtc/ice-candidate-client.ts | 18 +++++------------- src/connector/webrtc/subjects.ts | 1 + 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/connector/webrtc/ice-candidate-client.ts b/src/connector/webrtc/ice-candidate-client.ts index 4a06bac..2aac0df 100644 --- a/src/connector/webrtc/ice-candidate-client.ts +++ b/src/connector/webrtc/ice-candidate-client.ts @@ -77,18 +77,10 @@ export const IceCandidateClient = (input: { ), ) - const haveLocalOffer$ = subjects.onSignalingStateChangeSubject.pipe( - filter((value) => value === 'have-local-offer'), - ) - - const haveRemoteOffer$ = subjects.onSignalingStateChangeSubject.pipe( - filter((value) => value === 'have-remote-offer'), - ) - const waitForRemoteDescription$ = merge( - haveLocalOffer$, - haveRemoteOffer$, - subjects.onRemoteAnswerSubject, - ) + const onRemoteDescriptionSuccess$ = + subjects.onRemoteDescriptionSuccessSubject.pipe( + filter((isSuccess) => isSuccess), + ) const onRemoteIceCandidate$ = merge( subjects.remoteIceCandidatesSubject.pipe( @@ -110,7 +102,7 @@ export const IceCandidateClient = (input: { ) subscriptions.add( - waitForRemoteDescription$ + onRemoteDescriptionSuccess$ .pipe( mergeMap(() => onRemoteIceCandidate$), concatMap(addIceCandidate), diff --git a/src/connector/webrtc/subjects.ts b/src/connector/webrtc/subjects.ts index b74a4f3..e3968b9 100644 --- a/src/connector/webrtc/subjects.ts +++ b/src/connector/webrtc/subjects.ts @@ -20,4 +20,5 @@ export const WebRtcSubjects = () => ({ onSignalingStateChangeSubject: new Subject(), dataChannelStatusSubject: new BehaviorSubject<'open' | 'closed'>('closed'), iceConnectionStateSubject: new Subject(), + onRemoteDescriptionSuccessSubject: new BehaviorSubject(false), })