Commit 37128979 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Call onclose on up streams too.

parent 820b303e
...@@ -236,12 +236,15 @@ ServerConnection.prototype.connect = async function(url) { ...@@ -236,12 +236,15 @@ ServerConnection.prototype.connect = async function(url) {
}; };
this.socket.onclose = function(e) { this.socket.onclose = function(e) {
sc.permissions = {}; sc.permissions = {};
for(let id in sc.up) {
let c = sc.up[id];
delete(sc.up[id]);
c.close();
}
for(let id in sc.down) { for(let id in sc.down) {
let c = sc.down[id]; let c = sc.down[id];
delete(sc.down[id]); delete(sc.down[id]);
c.close(); c.close();
if(c.onclose)
c.onclose.call(c);
} }
if(sc.group && sc.onjoined) if(sc.group && sc.onjoined)
sc.onjoined.call(sc, 'leave', sc.group, {}, ''); sc.onjoined.call(sc, 'leave', sc.group, {}, '');
...@@ -528,7 +531,7 @@ ServerConnection.prototype.gotOffer = async function(id, labels, source, usernam ...@@ -528,7 +531,7 @@ ServerConnection.prototype.gotOffer = async function(id, labels, source, usernam
// Unless the server indicates that this is a renegotiation with // Unless the server indicates that this is a renegotiation with
// all parameters unchanged, tear down the existing connection. // all parameters unchanged, tear down the existing connection.
delete(sc.down[id]); delete(sc.down[id]);
c.close(); c.close(true);
c = null; c = null;
} }
...@@ -634,7 +637,7 @@ ServerConnection.prototype.gotAnswer = async function(id, sdp) { ...@@ -634,7 +637,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(); c.close(true);
} }
return; return;
} }
...@@ -668,8 +671,6 @@ ServerConnection.prototype.gotClose = function(id) { ...@@ -668,8 +671,6 @@ ServerConnection.prototype.gotClose = function(id) {
throw new Error('unknown down stream'); throw new Error('unknown down stream');
delete(this.down[id]); delete(this.down[id]);
c.close(); c.close();
if(c.onclose)
c.onclose.call(c);
}; };
/** /**
...@@ -882,8 +883,10 @@ function Stream(sc, id, pc, up) { ...@@ -882,8 +883,10 @@ function Stream(sc, id, pc, up) {
* For streams in the up direction, this may be called at any time. For * For streams in the up direction, this may be called at any time. For
* 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]
*/ */
Stream.prototype.close = function() { Stream.prototype.close = function(nocallback) {
let c = this; let c = this;
if(c.statsHandler) { if(c.statsHandler) {
clearInterval(c.statsHandler); clearInterval(c.statsHandler);
...@@ -909,6 +912,9 @@ Stream.prototype.close = function() { ...@@ -909,6 +912,9 @@ Stream.prototype.close = function() {
} catch(e) { } catch(e) {
} }
} }
if(!nocallback && c.onclose)
c.onclose.call(c);
c.sc = null; c.sc = null;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment