From 96e2db0347c8adcbb9146d48cb9f64dcf1d6912e Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Fri, 8 Dec 2023 18:46:23 +0100 Subject: [PATCH] Protect against undefined navigator.mediaDevices. This may happen if we're running over plain HTTP. Thanks to kovmir. --- static/galene.js | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/static/galene.js b/static/galene.js index e99384e..67bdfce 100644 --- a/static/galene.js +++ b/static/galene.js @@ -478,25 +478,31 @@ function setVisibility(id, visible) { function setButtonsVisibility() { let connected = serverConnection && serverConnection.socket; let permissions = serverConnection.permissions; - let present = permissions.indexOf('present') >= 0; - let local = !!findUpMedia('camera'); let canWebrtc = !(typeof RTCPeerConnection === 'undefined'); + let canPresent = canWebrtc && + ('mediaDevices' in navigator) && + ('getUserMedia' in navigator.mediaDevices) && + permissions.indexOf('present') >= 0; + let canShare = canWebrtc && + ('mediaDevices' in navigator) && + ('getDisplayMedia' in navigator.mediaDevices) && + permissions.indexOf('present') >= 0; + let local = !!findUpMedia('camera'); let mediacount = document.getElementById('peers').childElementCount; let mobilelayout = isMobileLayout(); // don't allow multiple presentations - setVisibility('presentbutton', canWebrtc && present && !local); + setVisibility('presentbutton', canPresent && !local); setVisibility('unpresentbutton', local); - setVisibility('mutebutton', !connected || present); + setVisibility('mutebutton', !connected || canPresent); // allow multiple shared documents - setVisibility('sharebutton', canWebrtc && present && - ('getDisplayMedia' in navigator.mediaDevices)); + setVisibility('sharebutton', canShare); - setVisibility('mediaoptions', present); - setVisibility('sendform', present); - setVisibility('simulcastform', present); + setVisibility('mediaoptions', canPresent); + setVisibility('sendform', canPresent); + setVisibility('simulcastform', canPresent); setVisibility('collapse-video', mediacount && mobilelayout); } @@ -864,7 +870,8 @@ async function setMediaChoices(done) { let devices = []; try { - devices = await navigator.mediaDevices.enumerateDevices(); + if('mediaDevices' in navigator) + devices = await navigator.mediaDevices.enumerateDevices(); } catch(e) { console.error(e); return; @@ -2487,7 +2494,9 @@ async function gotJoined(kind, group, perms, status, data, error, message) { else this.request(mapRequest(getSettings().request)); - if(serverConnection.permissions.indexOf('present') >= 0 && + if(('mediaDevices' in navigator) && + ('getUserMedia' in navigator.mediaDevices) && + serverConnection.permissions.indexOf('present') >= 0 && !findUpMedia('camera')) { if(present) { if(present === 'mike')