Skip to content

Commit

Permalink
Keep the negotiating state until the SDP is ready (#558)
Browse files Browse the repository at this point in the history
  • Loading branch information
giavac authored Jan 10, 2025
1 parent 0bf947f commit 2877060
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
10 changes: 9 additions & 1 deletion packages/common/src/webrtc/BaseCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,8 @@ export default abstract class BaseCall implements IWebRTCCall {
}

private _requestAnotherLocalDescription() {
logger.debug('_requestAnotherLocalDescription')

if (isFunction(this.peer.onSdpReadyTwice)) {
trigger(SwEvent.Error, new Error('SDP without candidates for the second time!'), this.session.uuid)
return
Expand All @@ -633,11 +635,16 @@ export default abstract class BaseCall implements IWebRTCCall {
}

private _onIceSdp(data: RTCSessionDescription) {
logger.debug('_onIceSdp')

if (this._iceTimeout) {
clearTimeout(this._iceTimeout)
}
this._iceTimeout = null
this._iceDone = true

this.peer.resetNegotiating()

const { sdp, type } = data
if (sdp.indexOf('candidate') === -1) {
this._requestAnotherLocalDescription()
Expand Down Expand Up @@ -678,10 +685,11 @@ export default abstract class BaseCall implements IWebRTCCall {
return
}
if (this._iceTimeout === null) {
logger.debug('Setting _iceTimeout to 1 second')
this._iceTimeout = setTimeout(() => this._onIceSdp(instance.localDescription), 1000)
}
if (event.candidate) {
logger.info('IceCandidate:', event.candidate)
logger.debug('IceCandidate: address:', event.candidate.address, ' - port:', event.candidate.port, ' - type:', event.candidate.type)
} else {
this._onIceSdp(instance.localDescription)
}
Expand Down
12 changes: 9 additions & 3 deletions packages/common/src/webrtc/Peer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ export default class Peer {
this._init()
}

resetNegotiating() {
this._negotiating = false
}

get isNegotiating() {
return this._negotiating
}

startNegotiation() {
this._negotiating = true

Expand All @@ -39,9 +47,6 @@ export default class Peer {
this.instance.onsignalingstatechange = event => {
switch (this.instance.signalingState) {
case 'stable':
// Workaround to skip nested negotiations
// Chrome bug: https://bugs.chromium.org/p/chromium/issues/detail?id=740501
this._negotiating = false
break
case 'closed':
this.instance = null
Expand Down Expand Up @@ -114,6 +119,7 @@ export default class Peer {
if (googleMaxBitrate && googleMinBitrate && googleStartBitrate) {
sessionDescription.sdp = sdpBitrateHack(sessionDescription.sdp, googleMaxBitrate, googleMinBitrate, googleStartBitrate)
}
logger.debug('calling setLocalDescription with SDP:', sessionDescription.sdp)
return this.instance.setLocalDescription(sessionDescription)
}

Expand Down

0 comments on commit 2877060

Please sign in to comment.