accept candidates before offer.

This commit is contained in:
Miroslav Šedivý 2021-02-02 21:05:30 +01:00
parent 4850b5cb7c
commit b0ed563792

View File

@ -41,9 +41,10 @@ export class NekoWebRTC extends EventEmitter<NekoWebRTCEvents> {
) )
} }
candidates: RTCIceCandidateInit[] = []
public async setCandidate(candidate: RTCIceCandidateInit) { public async setCandidate(candidate: RTCIceCandidateInit) {
if (!this._peer) { if (!this._peer) {
this._log.warn(`could not add remote ICE candidate: peer does not exist!`) this.candidates.push(candidate)
return return
} }
@ -71,6 +72,15 @@ 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)
} }