From 3fbe2747850ee2a27e0eab94d292d3c6336d716e Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Sat, 14 Dec 2024 12:20:41 +0100 Subject: [PATCH] Handle errors in filter init. We used to ignore errors in filter init, which could cause us to send unblurred videos to the server. --- static/galene.js | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/static/galene.js b/static/galene.js index 7334019..36a56a1 100644 --- a/static/galene.js +++ b/static/galene.js @@ -1369,12 +1369,7 @@ async function setUpStream(c, stream) { c.setStream(stream); - try { - await setFilter(c); - } catch(e) { - displayWarning("Couldn't set filter: " + e); - } - + // set up the handler early, in case setFilter fails. c.onclose = async replace => { await removeFilter(c); if(!replace) { @@ -1385,6 +1380,8 @@ async function setUpStream(c, stream) { } } + await setFilter(c); + /** * @param {MediaStreamTrack} t */ @@ -1507,10 +1504,20 @@ async function replaceUpStream(c) { cn.userdata.onclose = c.userdata.onclose; let media = /** @type{HTMLVideoElement} */ (document.getElementById('media-' + c.localId)); - await setUpStream(cn, c.stream); + try { + await setUpStream(cn, c.stream); + } catch(e) { + console.error(e); + displayError(e); + cn.close(); + c.close(); + return null; + } + await setMedia(cn, cn.label == 'camera' && getSettings().mirrorView, cn.label == 'video' && media); + return cn; } @@ -1611,8 +1618,14 @@ async function addLocalMedia(localId) { displayWarning(`Unknown filter ${settings.filter}`); } - await setUpStream(c, stream); - await setMedia(c, settings.mirrorView); + try { + await setUpStream(c, stream); + await setMedia(c, settings.mirrorView); + } catch(e) { + console.error(e); + displayError(e); + c.close(); + } setButtonsVisibility(); }