From 8fbd16cc8c7284304ba82e9f453599770a999d04 Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Wed, 19 Aug 2020 14:39:40 +0200 Subject: [PATCH] Minor tweaks to error handling. --- static/protocol.js | 2 +- static/sfu.js | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/static/protocol.js b/static/protocol.js index 750687b..ddda51f 100644 --- a/static/protocol.js +++ b/static/protocol.js @@ -150,7 +150,7 @@ ServerConnection.prototype.close = function() { * @param {message} m - the message to send. */ ServerConnection.prototype.send = function(m) { - if(this.socket.readyState !== this.socket.OPEN) { + if(!this.socket || this.socket.readyState !== this.socket.OPEN) { // send on a closed connection doesn't throw throw(new Error('Connection is not open')); } diff --git a/static/sfu.js b/static/sfu.js index 1b0ed21..bec86f4 100644 --- a/static/sfu.js +++ b/static/sfu.js @@ -385,7 +385,11 @@ function stopUpMedia(c) { */ function delUpMedia(c) { stopUpMedia(c); - delMedia(c.id); + try { + delMedia(c.id); + } catch(e) { + console.warn(e); + } c.close(true); delete(serverConnection.up[c.id]); setButtonsVisibility() @@ -474,6 +478,8 @@ function setMedia(c, isUp) { function delMedia(id) { let mediadiv = document.getElementById('peers'); let peer = document.getElementById('peer-' + id); + if(!peer) + throw new Error('Removing unknown media'); let media = document.getElementById('media-' + id); media.srcObject = null;