mirror of
https://github.com/jech/galene.git
synced 2024-11-22 16:45:58 +01:00
Implement restartIce for older browsers.
This commit is contained in:
parent
aa876bcd0d
commit
c0122c069e
1 changed files with 34 additions and 16 deletions
|
@ -386,14 +386,8 @@ ServerConnection.prototype.newUpStream = function(id) {
|
||||||
pc.oniceconnectionstatechange = e => {
|
pc.oniceconnectionstatechange = e => {
|
||||||
if(c.onstatus)
|
if(c.onstatus)
|
||||||
c.onstatus.call(c, pc.iceConnectionState);
|
c.onstatus.call(c, pc.iceConnectionState);
|
||||||
if(pc.iceConnectionState === 'failed') {
|
if(pc.iceConnectionState === 'failed')
|
||||||
try {
|
c.restartIce();
|
||||||
/** @ts-ignore */
|
|
||||||
pc.restartIce();
|
|
||||||
} catch(e) {
|
|
||||||
console.warn(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pc.ontrack = console.error;
|
pc.ontrack = console.error;
|
||||||
|
@ -587,12 +581,7 @@ ServerConnection.prototype.gotRenegotiate = async function(id) {
|
||||||
let c = this.up[id];
|
let c = this.up[id];
|
||||||
if(!c)
|
if(!c)
|
||||||
throw new Error('unknown up stream');
|
throw new Error('unknown up stream');
|
||||||
try {
|
c.restartIce();
|
||||||
/** @ts-ignore */
|
|
||||||
c.pc.restartIce();
|
|
||||||
} catch(e) {
|
|
||||||
console.warn(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -837,12 +826,17 @@ Stream.prototype.flushIceCandidates = async function () {
|
||||||
* automatically when required. If the client requires renegotiation, it
|
* automatically when required. If the client requires renegotiation, it
|
||||||
* is probably more effective to call restartIce on the underlying PC
|
* is probably more effective to call restartIce on the underlying PC
|
||||||
* rather than invoking this function directly.
|
* rather than invoking this function directly.
|
||||||
|
*
|
||||||
* @function
|
* @function
|
||||||
|
* @param {boolean} [restartIce]
|
||||||
*/
|
*/
|
||||||
Stream.prototype.negotiate = async function () {
|
Stream.prototype.negotiate = async function (restartIce) {
|
||||||
let c = this;
|
let c = this;
|
||||||
|
|
||||||
let offer = await c.pc.createOffer();
|
let options = null;
|
||||||
|
if(restartIce)
|
||||||
|
options = {iceRestart: true};
|
||||||
|
let offer = await c.pc.createOffer(options);
|
||||||
if(!offer)
|
if(!offer)
|
||||||
throw(new Error("Didn't create offer"));
|
throw(new Error("Didn't create offer"));
|
||||||
await c.pc.setLocalDescription(offer);
|
await c.pc.setLocalDescription(offer);
|
||||||
|
@ -867,6 +861,30 @@ Stream.prototype.negotiate = async function () {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* restartIce causes an ICE restart on an up stream. It is called
|
||||||
|
* automatically when ICE signals that the connection has failed. It
|
||||||
|
* returns immediately, negotiation will happen asynchronously.
|
||||||
|
*/
|
||||||
|
|
||||||
|
Stream.prototype.restartIce = function () {
|
||||||
|
let c = this;
|
||||||
|
|
||||||
|
/** @ts-ignore */
|
||||||
|
if(typeof c.pc.restartIce === 'function') {
|
||||||
|
try {
|
||||||
|
/** @ts-ignore */
|
||||||
|
c.pc.restartIce();
|
||||||
|
return;
|
||||||
|
} catch(e) {
|
||||||
|
console.warn(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// negotiate is async, but this returns immediately.
|
||||||
|
c.negotiate(true);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* updateStats is called periodically, if requested by setStatsInterval,
|
* updateStats is called periodically, if requested by setStatsInterval,
|
||||||
* in order to recompute stream statistics and invoke the onstats handler.
|
* in order to recompute stream statistics and invoke the onstats handler.
|
||||||
|
|
Loading…
Reference in a new issue