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)