mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
skip onnegotiationneeded if in progress. (#22)
This commit is contained in:
parent
dc2ef37e17
commit
ae80753378
@ -184,27 +184,34 @@ export class NekoWebRTC extends EventEmitter<NekoWebRTCEvents> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let negotiating = false
|
||||||
this._peer.onnegotiationneeded = async () => {
|
this._peer.onnegotiationneeded = async () => {
|
||||||
if (!this._peer) {
|
if (!this._peer) {
|
||||||
this._log.warn(`attempting to call 'onsignalingstatechange' for nonexistent peer`)
|
this._log.warn(`attempting to call 'onsignalingstatechange' for nonexistent peer`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const state = this._peer.signalingState
|
||||||
const offer = await this._peer.createOffer()
|
this._log.warn(`negotiation is needed`, { state })
|
||||||
|
|
||||||
|
if (negotiating) {
|
||||||
|
this._log.info(`negotiation already in progress; skipping...`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
negotiating = true
|
||||||
|
|
||||||
|
try {
|
||||||
// If the connection hasn't yet achieved the "stable" state,
|
// If the connection hasn't yet achieved the "stable" state,
|
||||||
// return to the caller. Another negotiationneeded event
|
// return to the caller. Another negotiationneeded event
|
||||||
// will be fired when the state stabilizes.
|
// will be fired when the state stabilizes.
|
||||||
|
|
||||||
const state = this._peer.signalingState
|
|
||||||
this._log.warn(`negotiation is needed`, { state })
|
|
||||||
|
|
||||||
if (state != 'stable') {
|
if (state != 'stable') {
|
||||||
this._log.info(`connection isn't stable yet; postponing...`)
|
this._log.info(`connection isn't stable yet; postponing...`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const offer = await this._peer.createOffer()
|
||||||
await this._peer.setLocalDescription(offer)
|
await this._peer.setLocalDescription(offer)
|
||||||
|
|
||||||
if (offer) {
|
if (offer) {
|
||||||
@ -214,6 +221,8 @@ export class NekoWebRTC extends EventEmitter<NekoWebRTCEvents> {
|
|||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
this._log.error(`on negotiation needed failed`, { error })
|
this._log.error(`on negotiation needed failed`, { error })
|
||||||
|
} finally {
|
||||||
|
negotiating = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user