do not fire onnegotiation when not stable.

This commit is contained in:
Miroslav Šedivý 2021-11-25 23:48:41 +01:00
parent 18e04fdb03
commit ed8fab1afa

View File

@ -145,16 +145,26 @@ export class NekoWebRTC extends EventEmitter<NekoWebRTCEvents> {
} }
this._peer.onnegotiationneeded = async () => { this._peer.onnegotiationneeded = async () => {
const state = this._peer!.iceConnectionState const offer = await this._peer?.createOffer()
// If the connection hasn't yet achieved the "stable" state,
// return to the caller. Another negotiationneeded event
// will be fired when the state stabilizes.
const state = this._peer!.signalingState
this._log.warn(`negotiation is needed`, { state }) this._log.warn(`negotiation is needed`, { state })
const offer = await this._peer?.createOffer() if (state != 'stable') {
this._log.info(`connection isn't stable yet; postponing...`)
return
}
this._peer!.setLocalDescription(offer) this._peer!.setLocalDescription(offer)
if (offer) { if (offer) {
this.emit('negotiation', offer) this.emit('negotiation', offer)
} else { } else {
this._log.warn(`megotiatoion offer is empty`) this._log.warn(`negotiatoion offer is empty`)
} }
} }