add ice candidates adter accepting remote description.

This commit is contained in:
Miroslav Šedivý 2021-02-07 16:01:08 +01:00
parent 46c2625f1c
commit 0aef325c5b

View File

@ -82,15 +82,6 @@ export class NekoWebRTC extends EventEmitter<NekoWebRTCEvents> {
}) })
} }
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._peer.onconnectionstatechange = (event) => {
this._log.debug(`peer connection state changed`, this._peer ? this._peer.connectionState : undefined) this._log.debug(`peer connection state changed`, this._peer ? this._peer.connectionState : undefined)
} }
@ -139,6 +130,15 @@ export class NekoWebRTC extends EventEmitter<NekoWebRTCEvents> {
this._peer.setRemoteDescription({ type: 'offer', sdp }) 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() const answer = await this._peer.createAnswer()
this._peer!.setLocalDescription(answer) this._peer!.setLocalDescription(answer)