Skip to content

Commit

Permalink
fix: wait for onRemoteDescriptionSuccess before adding ice candidates
Browse files Browse the repository at this point in the history
  • Loading branch information
xstelea committed Jan 26, 2024
1 parent 7bd42d2 commit c712a03
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
18 changes: 5 additions & 13 deletions src/connector/webrtc/ice-candidate-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -110,7 +102,7 @@ export const IceCandidateClient = (input: {
)

subscriptions.add(
waitForRemoteDescription$
onRemoteDescriptionSuccess$
.pipe(
mergeMap(() => onRemoteIceCandidate$),
concatMap(addIceCandidate),
Expand Down
1 change: 1 addition & 0 deletions src/connector/webrtc/subjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ export const WebRtcSubjects = () => ({
onSignalingStateChangeSubject: new Subject<RTCSignalingState>(),
dataChannelStatusSubject: new BehaviorSubject<'open' | 'closed'>('closed'),
iceConnectionStateSubject: new Subject<RTCIceConnectionState>(),
onRemoteDescriptionSuccessSubject: new BehaviorSubject<boolean>(false),
})

0 comments on commit c712a03

Please sign in to comment.