From 0aef325c5bab2f53fef935948d44e6653222ead4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Sun, 7 Feb 2021 16:01:08 +0100 Subject: [PATCH] add ice candidates adter accepting remote description. --- src/component/internal/webrtc.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/component/internal/webrtc.ts b/src/component/internal/webrtc.ts index 5b3691a5..18a1c89c 100644 --- a/src/component/internal/webrtc.ts +++ b/src/component/internal/webrtc.ts @@ -82,15 +82,6 @@ export class NekoWebRTC extends EventEmitter { }) } - if (this.candidates.length > 0) { - for (const candidate of this.candidates) { - this._peer.addIceCandidate(candidate) - } - - this._log.debug(`added ${this.candidates.length} remote ICE candidates`, this.candidates) - this.candidates = [] - } - this._peer.onconnectionstatechange = (event) => { this._log.debug(`peer connection state changed`, this._peer ? this._peer.connectionState : undefined) } @@ -139,6 +130,15 @@ export class NekoWebRTC extends EventEmitter { this._peer.setRemoteDescription({ type: 'offer', sdp }) + if (this.candidates.length > 0) { + for (const candidate of this.candidates) { + this._peer.addIceCandidate(candidate) + } + + this._log.debug(`added ${this.candidates.length} remote ICE candidates`, this.candidates) + this.candidates = [] + } + const answer = await this._peer.createAnswer() this._peer!.setLocalDescription(answer)