Commit 96e5030d authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Work around Safari's autoplay restrictions.

parent e8c732c5
...@@ -764,6 +764,11 @@ async function setMaxVideoThroughput(c, bps) { ...@@ -764,6 +764,11 @@ async function setMaxVideoThroughput(c, bps) {
} }
} }
function isSafari() {
let ua = navigator.userAgent.toLowerCase();
return ua.indexOf('safari') >= 0 && ua.indexOf('chrome') < 0;
}
/** /**
* @param {string} [id] * @param {string} [id]
*/ */
...@@ -833,7 +838,7 @@ async function addLocalMedia(id) { ...@@ -833,7 +838,7 @@ async function addLocalMedia(id) {
setButtonsVisibility(); setButtonsVisibility();
} }
let safariWarningDone = false; let safariScreenshareDone = false;
async function addShareMedia() { async function addShareMedia() {
if(!getUserPass()) if(!getUserPass())
...@@ -852,13 +857,11 @@ async function addShareMedia() { ...@@ -852,13 +857,11 @@ async function addShareMedia() {
return; return;
} }
if(!safariWarningDone) { if(!safariScreenshareDone) {
let ua = navigator.userAgent.toLowerCase(); if(isSafari())
if(ua.indexOf('safari') >= 0 && ua.indexOf('chrome') < 0) {
displayWarning('Screen sharing under Safari is experimental. ' + displayWarning('Screen sharing under Safari is experimental. ' +
'Please use a different browser if possible.'); 'Please use a different browser if possible.');
} safariScreenshareDone = true;
safariWarningDone = true;
} }
let c = newUpStream(); let c = newUpStream();
...@@ -931,7 +934,7 @@ async function addFileMedia(file) { ...@@ -931,7 +934,7 @@ async function addFileMedia(file) {
delUpMedia(c); delUpMedia(c);
} }
}; };
setMedia(c, true, false, video); await setMedia(c, true, false, video);
c.userdata.play = true; c.userdata.play = true;
setButtonsVisibility() setButtonsVisibility()
} }
...@@ -1026,7 +1029,7 @@ function muteLocalTracks(mute) { ...@@ -1026,7 +1029,7 @@ function muteLocalTracks(mute) {
* - the video element to add. If null, a new element with custom * - the video element to add. If null, a new element with custom
* controls will be created. * controls will be created.
*/ */
function setMedia(c, isUp, mirror, video) { async function setMedia(c, isUp, mirror, video) {
let peersdiv = document.getElementById('peers'); let peersdiv = document.getElementById('peers');
let div = document.getElementById('peer-' + c.id); let div = document.getElementById('peer-' + c.id);
...@@ -1080,6 +1083,15 @@ function setMedia(c, isUp, mirror, video) { ...@@ -1080,6 +1083,15 @@ function setMedia(c, isUp, mirror, video) {
showVideo(); showVideo();
resizePeers(); resizePeers();
if(!isUp && isSafari() && !findUpMedia('local')) {
// Safari doesn't allow autoplay unless the user has granted media access
try {
let stream = await navigator.mediaDevices.getUserMedia({audio: true});
stream.getTracks().forEach(t => t.stop());
} catch(e) {
}
}
} }
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment