Commit 1afb3c85 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Open microphone early on Safari.

Safari forbids autoplay and omits host candidates unless the microphone
is open.
parent 0de01997
......@@ -275,6 +275,14 @@ function showVideo() {
scheduleReconsiderDownRate();
}
function isSafari() {
let ua = navigator.userAgent.toLowerCase();
return ua.indexOf('safari') >= 0 && ua.indexOf('chrome') < 0;
}
/** @type {MediaStream} */
let safariStream = null;
/**
* @param{boolean} connected
*/
......@@ -289,6 +297,15 @@ function setConnected(connected) {
window.onresize = function(e) {
scheduleReconsiderDownRate();
}
if(isSafari()) {
/* Safari doesn't allow autoplay and omits host candidates
* unless there is Open one and keep it around. */
if(!safariStream) {
navigator.mediaDevices.getUserMedia({audio: true}).then(s => {
safariStream = s;
});
}
}
} else {
userbox.classList.add('invisible');
connectionbox.classList.remove('invisible');
......@@ -1145,11 +1162,6 @@ function addFilters() {
}
}
function isSafari() {
let ua = navigator.userAgent.toLowerCase();
return ua.indexOf('safari') >= 0 && ua.indexOf('chrome') < 0;
}
const unlimitedRate = 1000000000;
const simulcastRate = 100000;
const hqAudioRate = 128000;
......@@ -1444,7 +1456,7 @@ async function addShareMedia() {
if(!safariScreenshareDone) {
if(isSafari()) {
let ok = confirm(
'Screen sharing in Safari is badly broken. ' +
'Screen sharing in Safari is broken. ' +
'It will work at first, ' +
'but then your video will randomly freeze. ' +
'Are you sure that you wish to enable screensharing?'
......@@ -1758,15 +1770,6 @@ async function setMedia(c, mirror, video) {
showVideo();
resizePeers();
if(!c.up && isSafari() && !findUpMedia('camera')) {
// 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