Commit edd91a8f authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Delay opening safariStream until after join.

Also close the stream when we leave.
parent 4d6a7a92
...@@ -352,14 +352,6 @@ function isFirefox() { ...@@ -352,14 +352,6 @@ function isFirefox() {
return ua.indexOf('firefox') >= 0; return ua.indexOf('firefox') >= 0;
} }
/**
* Under Safari, we request access to the camera at startup in order to
* enable autoplay. The camera stream is stored in safariStream.
*
* @type {MediaStream}
*/
let safariStream = null;
/** /**
* setConnected is called whenever we connect or disconnect to the server. * setConnected is called whenever we connect or disconnect to the server.
* *
...@@ -376,15 +368,6 @@ function setConnected(connected) { ...@@ -376,15 +368,6 @@ 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 an open device. */
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');
...@@ -506,6 +489,7 @@ function onPeerConnection() { ...@@ -506,6 +489,7 @@ function onPeerConnection() {
*/ */
function gotClose(code, reason) { function gotClose(code, reason) {
closeUpMedia(); closeUpMedia();
closeSafariStream();
setConnected(false); setConnected(false);
if(code != 1000) { if(code != 1000) {
console.warn('Socket close', code, reason); console.warn('Socket close', code, reason);
...@@ -2726,6 +2710,28 @@ function setTitle(title) { ...@@ -2726,6 +2710,28 @@ function setTitle(title) {
set('Galène'); set('Galène');
} }
/**
* Under Safari, we request access to the camera at startup in order to
* enable autoplay. The camera stream is stored in safariStream.
*
* @type {MediaStream}
*/
let safariStream = null;
async function openSafariStream() {
if(!isSafari())
return;
if(!safariStream)
safariStream = await navigator.mediaDevices.getUserMedia({audio: true})
}
async function closeSafariStream() {
if(!safariStream)
return;
stopStream(safariStream);
safariStream = null;
}
/** /**
* @this {ServerConnection} * @this {ServerConnection}
...@@ -2749,15 +2755,18 @@ async function gotJoined(kind, group, perms, status, data, error, message) { ...@@ -2749,15 +2755,18 @@ async function gotJoined(kind, group, perms, status, data, error, message) {
token = null; token = null;
displayError('The server said: ' + message); displayError('The server said: ' + message);
} }
closeSafariStream();
this.close(); this.close();
setButtonsVisibility(); setButtonsVisibility();
return; return;
case 'redirect': case 'redirect':
closeSafariStream();
this.close(); this.close();
token = null; token = null;
document.location.href = message; document.location.href = message;
return; return;
case 'leave': case 'leave':
closeSafariStream();
this.close(); this.close();
setButtonsVisibility(); setButtonsVisibility();
setChangePassword(null); setChangePassword(null);
...@@ -2768,6 +2777,7 @@ async function gotJoined(kind, group, perms, status, data, error, message) { ...@@ -2768,6 +2777,7 @@ async function gotJoined(kind, group, perms, status, data, error, message) {
probingState = 'success'; probingState = 'success';
setVisibility('userform', false); setVisibility('userform', false);
setVisibility('passwordform', false); setVisibility('passwordform', false);
closeSafariStream();
this.close(); this.close();
setButtonsVisibility(); setButtonsVisibility();
return; return;
...@@ -2783,12 +2793,14 @@ async function gotJoined(kind, group, perms, status, data, error, message) { ...@@ -2783,12 +2793,14 @@ async function gotJoined(kind, group, perms, status, data, error, message) {
setChangePassword(pwAuth && !!groupStatus.canChangePassword && setChangePassword(pwAuth && !!groupStatus.canChangePassword &&
serverConnection.username serverConnection.username
); );
openSafariStream();
if(kind === 'change') if(kind === 'change')
return; return;
break; break;
default: default:
token = null; token = null;
displayError('Unknown join message'); displayError('Unknown join message');
closeSafariStream();
this.close(); this.close();
return; return;
} }
......
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