From e04193f78cfb06b305b0b58f241bfecdc8e35a13 Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Sun, 14 Feb 2021 18:06:50 +0100 Subject: [PATCH] Display user message when browser doesn't do WebRTC. Thanks to mscherer for the report. --- static/galene.js | 20 ++++++++++++++++---- static/protocol.js | 26 +++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/static/galene.js b/static/galene.js index f97bedc..7e1a6a2 100644 --- a/static/galene.js +++ b/static/galene.js @@ -429,6 +429,7 @@ function setButtonsVisibility() { let local = !!findUpMedia('local'); let share = !!findUpMedia('screenshare'); let video = !!findUpMedia('video'); + let canWebrtc = !(typeof RTCPeerConnection === 'undefined'); let canFile = /** @ts-ignore */ !!HTMLVideoElement.prototype.captureStream || @@ -436,13 +437,13 @@ function setButtonsVisibility() { !!HTMLVideoElement.prototype.mozCaptureStream; // don't allow multiple presentations - setVisibility('presentbutton', permissions.present && !local); + setVisibility('presentbutton', canWebrtc && permissions.present && !local); setVisibility('unpresentbutton', local); setVisibility('mutebutton', !connected || permissions.present); // allow multiple shared documents - setVisibility('sharebutton', permissions.present && + setVisibility('sharebutton', canWebrtc && permissions.present && ('getDisplayMedia' in navigator.mediaDevices)); setVisibility('unsharebutton', share); @@ -1069,7 +1070,15 @@ async function addLocalMedia(localId) { setMediaChoices(true); - let c = newUpStream(localId); + let c; + + try { + c = newUpStream(localId); + } catch(e) { + console.log(e); + displayError(e); + return; + } c.kind = 'local'; c.stream = stream; @@ -1797,7 +1806,10 @@ async function gotJoined(kind, group, perms, message) { input.placeholder = 'Type /help for help'; setTimeout(() => {input.placeholder = '';}, 8000); - this.request(getSettings().request); + if(typeof RTCPeerConnection === 'undefined') + displayWarning("This browser doesn't support WebRTC"); + else + this.request(getSettings().request); if(serverConnection.permissions.present && !findUpMedia('local')) { if(present) { diff --git a/static/protocol.js b/static/protocol.js index 48d7bcf..a4e0564 100644 --- a/static/protocol.js +++ b/static/protocol.js @@ -437,6 +437,9 @@ ServerConnection.prototype.newUpStream = function(localId) { if(sc.up[id]) throw new Error('Eek!'); + if(typeof RTCPeerConnection === 'undefined') + throw new Error("This browser doesn't support WebRTC"); + let pc = new RTCPeerConnection(sc.rtcConfiguration); if(!pc) throw new Error("Couldn't create peer connection"); @@ -565,8 +568,15 @@ ServerConnection.prototype.groupAction = function(kind, message) { */ ServerConnection.prototype.gotOffer = async function(id, labels, source, username, sdp, replace) { let sc = this; - if(sc.up[id]) - throw new Error('Duplicate connection id'); + + if(sc.up[id]) { + console.error("Duplicate connection id"); + sc.send({ + type: 'abort', + id: id, + }); + return; + } let oldLocalId = null; @@ -584,7 +594,17 @@ ServerConnection.prototype.gotOffer = async function(id, labels, source, usernam console.error("Replacing duplicate stream"); if(!c) { - let pc = new RTCPeerConnection(sc.rtcConfiguration); + let pc; + try { + pc = new RTCPeerConnection(sc.rtcConfiguration); + } catch(e) { + console.error(e); + sc.send({ + type: 'abort', + id: id, + }); + return; + } c = new Stream(this, id, oldLocalId || newLocalId(), pc, false); sc.down[id] = c;