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() { ...@@ -275,6 +275,14 @@ function showVideo() {
scheduleReconsiderDownRate(); 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 * @param{boolean} connected
*/ */
...@@ -289,6 +297,15 @@ function setConnected(connected) { ...@@ -289,6 +297,15 @@ function setConnected(connected) {
window.onresize = function(e) { window.onresize = function(e) {
scheduleReconsiderDownRate(); 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 { } else {
userbox.classList.add('invisible'); userbox.classList.add('invisible');
connectionbox.classList.remove('invisible'); connectionbox.classList.remove('invisible');
...@@ -1145,11 +1162,6 @@ function addFilters() { ...@@ -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 unlimitedRate = 1000000000;
const simulcastRate = 100000; const simulcastRate = 100000;
const hqAudioRate = 128000; const hqAudioRate = 128000;
...@@ -1444,7 +1456,7 @@ async function addShareMedia() { ...@@ -1444,7 +1456,7 @@ async function addShareMedia() {
if(!safariScreenshareDone) { if(!safariScreenshareDone) {
if(isSafari()) { if(isSafari()) {
let ok = confirm( let ok = confirm(
'Screen sharing in Safari is badly broken. ' + 'Screen sharing in Safari is broken. ' +
'It will work at first, ' + 'It will work at first, ' +
'but then your video will randomly freeze. ' + 'but then your video will randomly freeze. ' +
'Are you sure that you wish to enable screensharing?' 'Are you sure that you wish to enable screensharing?'
...@@ -1758,15 +1770,6 @@ async function setMedia(c, mirror, video) { ...@@ -1758,15 +1770,6 @@ async function setMedia(c, mirror, video) {
showVideo(); showVideo();
resizePeers(); 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