Skip to content

Commit

Permalink
invoke restartIce() on icestate 'failed' like MDN
Browse files Browse the repository at this point in the history
no longer on 'disconnected'
backed up by mdn explanations of failed, disconnected
  • Loading branch information
cameronelliott committed Dec 10, 2021
1 parent 198c3f8 commit be2cac1
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions whip-whap-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ async function handleNegotiationNeeded(ev, url, bearerToken) {
opt.headers = { 'Content-Type': 'application/sdp' }
if (typeof bearerToken === 'string') { // may be null or undefined
opt.headers.Authorization = `Bearer ${bearerToken}`
}
}
opt.body = ofr.sdp
let resp = { status:-1}
let resp = { status: -1 }
try { // without try/catch, a thrown except from fetch exits our 'thread'
resp = await fetch(url, opt)
} catch (error) {
; // not needed console.log(error)
}



if (resp.status == 201) {
Expand Down Expand Up @@ -94,7 +94,17 @@ async function handleNegotiationNeeded(ev, url, bearerToken) {
function handleIceStateChange(event) {
let pc = /** @type {RTCPeerConnection} */ (event.target)

if (pc.iceConnectionState === "disconnected") { //'failed' is also an option
// 12 10 21
// I am not really sure of the ideal iceConnectionStates to trigger
// an ice restart.
// Prior to 12/10/21 I had ''
// The MDN perfect negotiation example uses 'failed'
// as of 12/10/21, I am changing from disconnected to failed as per the MDN
// perfect negotation example:
// states definitions:
// https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/iceConnectionState#value

if (pc.iceConnectionState === "failed") { //'failed' is also an option
console.debug('*** restarting ice')
pc.restartIce()
}
Expand Down

0 comments on commit be2cac1

Please sign in to comment.