1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-11-22 16:45:58 +01:00

Protect against undefined navigator.mediaDevices.

This may happen if we're running over plain HTTP.
Thanks to kovmir.
This commit is contained in:
Juliusz Chroboczek 2023-12-08 18:46:23 +01:00
parent c0214c3350
commit 96e2db0347

View file

@ -478,25 +478,31 @@ function setVisibility(id, visible) {
function setButtonsVisibility() { function setButtonsVisibility() {
let connected = serverConnection && serverConnection.socket; let connected = serverConnection && serverConnection.socket;
let permissions = serverConnection.permissions; let permissions = serverConnection.permissions;
let present = permissions.indexOf('present') >= 0;
let local = !!findUpMedia('camera');
let canWebrtc = !(typeof RTCPeerConnection === 'undefined'); 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 mediacount = document.getElementById('peers').childElementCount;
let mobilelayout = isMobileLayout(); let mobilelayout = isMobileLayout();
// don't allow multiple presentations // don't allow multiple presentations
setVisibility('presentbutton', canWebrtc && present && !local); setVisibility('presentbutton', canPresent && !local);
setVisibility('unpresentbutton', local); setVisibility('unpresentbutton', local);
setVisibility('mutebutton', !connected || present); setVisibility('mutebutton', !connected || canPresent);
// allow multiple shared documents // allow multiple shared documents
setVisibility('sharebutton', canWebrtc && present && setVisibility('sharebutton', canShare);
('getDisplayMedia' in navigator.mediaDevices));
setVisibility('mediaoptions', present); setVisibility('mediaoptions', canPresent);
setVisibility('sendform', present); setVisibility('sendform', canPresent);
setVisibility('simulcastform', present); setVisibility('simulcastform', canPresent);
setVisibility('collapse-video', mediacount && mobilelayout); setVisibility('collapse-video', mediacount && mobilelayout);
} }
@ -864,7 +870,8 @@ async function setMediaChoices(done) {
let devices = []; let devices = [];
try { try {
devices = await navigator.mediaDevices.enumerateDevices(); if('mediaDevices' in navigator)
devices = await navigator.mediaDevices.enumerateDevices();
} catch(e) { } catch(e) {
console.error(e); console.error(e);
return; return;
@ -2487,7 +2494,9 @@ async function gotJoined(kind, group, perms, status, data, error, message) {
else else
this.request(mapRequest(getSettings().request)); 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')) { !findUpMedia('camera')) {
if(present) { if(present) {
if(present === 'mike') if(present === 'mike')