mirror of
https://github.com/jech/galene.git
synced 2024-11-23 00:55:58 +01:00
Add replace parameter to onclose stream callback.
This indicates that the stream is being replaced by another one with the same id. This avoids moving videos around when they are being renegotiated.
This commit is contained in:
parent
f7b1ec73f1
commit
7d216f650c
2 changed files with 37 additions and 24 deletions
|
@ -320,8 +320,9 @@ function gotClose(code, reason) {
|
||||||
* @param {Stream} c
|
* @param {Stream} c
|
||||||
*/
|
*/
|
||||||
function gotDownStream(c) {
|
function gotDownStream(c) {
|
||||||
c.onclose = function() {
|
c.onclose = function(replace) {
|
||||||
delMedia(c.id);
|
if(!replace)
|
||||||
|
delMedia(c.id);
|
||||||
};
|
};
|
||||||
c.onerror = function(e) {
|
c.onerror = function(e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -1013,11 +1014,16 @@ async function addLocalMedia(id) {
|
||||||
}
|
}
|
||||||
|
|
||||||
let old = id && serverConnection.up[id];
|
let old = id && serverConnection.up[id];
|
||||||
if(old)
|
if(!audio && !video) {
|
||||||
old.close();
|
if(old)
|
||||||
|
old.close();
|
||||||
if(!audio && !video)
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(old && old.onclose) {
|
||||||
|
// make sure that the camera is released before we try to reopen it
|
||||||
|
old.onclose.call(old, true);
|
||||||
|
}
|
||||||
|
|
||||||
let constraints = {audio: audio, video: video};
|
let constraints = {audio: audio, video: video};
|
||||||
/** @type {MediaStream} */
|
/** @type {MediaStream} */
|
||||||
|
@ -1040,22 +1046,25 @@ async function addLocalMedia(id) {
|
||||||
try {
|
try {
|
||||||
let f = new Filter(stream, filter);
|
let f = new Filter(stream, filter);
|
||||||
setFilter(c, f);
|
setFilter(c, f);
|
||||||
c.onclose = () => {
|
c.onclose = replace => {
|
||||||
stopStream(stream);
|
stopStream(stream);
|
||||||
setFilter(c, null);
|
setFilter(c, null);
|
||||||
delMedia(c.id);
|
if(!replace)
|
||||||
|
delMedia(c.id);
|
||||||
}
|
}
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
displayWarning(e);
|
displayWarning(e);
|
||||||
c.onclose = () => {
|
c.onclose = replace => {
|
||||||
stopStream(c.stream);
|
stopStream(c.stream);
|
||||||
delMedia(c.id);
|
if(!replace)
|
||||||
|
delMedia(c.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
c.onclose = () => {
|
c.onclose = replace => {
|
||||||
stopStream(c.stream);
|
stopStream(c.stream);
|
||||||
delMedia(c.id);
|
if(!replace)
|
||||||
|
delMedia(c.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1106,9 +1115,10 @@ async function addShareMedia() {
|
||||||
let c = newUpStream();
|
let c = newUpStream();
|
||||||
c.kind = 'screenshare';
|
c.kind = 'screenshare';
|
||||||
c.stream = stream;
|
c.stream = stream;
|
||||||
c.onclose = () => {
|
c.onclose = replace => {
|
||||||
stopStream(stream);
|
stopStream(stream);
|
||||||
delMedia(c.id);
|
if(!replace)
|
||||||
|
delMedia(c.id);
|
||||||
}
|
}
|
||||||
stream.getTracks().forEach(t => {
|
stream.getTracks().forEach(t => {
|
||||||
c.pc.addTrack(t, stream);
|
c.pc.addTrack(t, stream);
|
||||||
|
@ -1141,7 +1151,7 @@ async function addFileMedia(file) {
|
||||||
let c = newUpStream();
|
let c = newUpStream();
|
||||||
c.kind = 'video';
|
c.kind = 'video';
|
||||||
c.stream = stream;
|
c.stream = stream;
|
||||||
c.onclose = function() {
|
c.onclose = function(replace) {
|
||||||
stopStream(c.stream);
|
stopStream(c.stream);
|
||||||
let media = /** @type{HTMLVideoElement} */
|
let media = /** @type{HTMLVideoElement} */
|
||||||
(document.getElementById('media-' + this.id));
|
(document.getElementById('media-' + this.id));
|
||||||
|
@ -1149,8 +1159,9 @@ async function addFileMedia(file) {
|
||||||
URL.revokeObjectURL(media.src);
|
URL.revokeObjectURL(media.src);
|
||||||
media.src = null;
|
media.src = null;
|
||||||
}
|
}
|
||||||
delMedia(c.id);
|
if(!replace)
|
||||||
}
|
delMedia(c.id);
|
||||||
|
};
|
||||||
|
|
||||||
stream.onaddtrack = function(e) {
|
stream.onaddtrack = function(e) {
|
||||||
let t = e.track;
|
let t = e.track;
|
||||||
|
|
|
@ -634,7 +634,7 @@ ServerConnection.prototype.gotAnswer = async function(id, sdp) {
|
||||||
if(c.onerror)
|
if(c.onerror)
|
||||||
c.onerror.call(c, e);
|
c.onerror.call(c, e);
|
||||||
} finally {
|
} finally {
|
||||||
c.close(true);
|
c.close();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -825,9 +825,10 @@ function Stream(sc, id, pc, up) {
|
||||||
/* Callbacks */
|
/* Callbacks */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* onclose is called when the stream is closed.
|
* onclose is called when the stream is closed. Replace will be true
|
||||||
|
* if the stream is being replaced by another one with the same id.
|
||||||
*
|
*
|
||||||
* @type{(this: Stream) => void}
|
* @type{(this: Stream, replace: boolean) => void}
|
||||||
*/
|
*/
|
||||||
this.onclose = null;
|
this.onclose = null;
|
||||||
/**
|
/**
|
||||||
|
@ -880,9 +881,10 @@ function Stream(sc, id, pc, up) {
|
||||||
* streams in the down direction, this will be called automatically when
|
* streams in the down direction, this will be called automatically when
|
||||||
* the server signals that it is closing a stream.
|
* the server signals that it is closing a stream.
|
||||||
*
|
*
|
||||||
* @param {boolean} [nocallback]
|
* @param {boolean} [replace]
|
||||||
|
* - true if the stream is being replaced by another one with the same id
|
||||||
*/
|
*/
|
||||||
Stream.prototype.close = function(nocallback) {
|
Stream.prototype.close = function(replace) {
|
||||||
let c = this;
|
let c = this;
|
||||||
|
|
||||||
if(!c.sc) {
|
if(!c.sc) {
|
||||||
|
@ -920,8 +922,8 @@ Stream.prototype.close = function(nocallback) {
|
||||||
}
|
}
|
||||||
c.sc = null;
|
c.sc = null;
|
||||||
|
|
||||||
if(!nocallback && c.onclose)
|
if(c.onclose)
|
||||||
c.onclose.call(c);
|
c.onclose.call(c, replace);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue