Merge pull request #5921 from prlanzarin/webkit-audio-fix

Temporary workaround for WebKit listen only audio on HTML5
This commit is contained in:
Anton Georgiev 2018-07-25 13:12:53 -04:00 committed by GitHub
commit 2ed8f08321
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View File

@ -145,6 +145,11 @@ class AudioManager {
setTimeout(reject, 12000, iceGatheringErr);
});
// Workaround to circumvent the WebKit autoplay policy without prompting
// the user to do some action again. A silent stream is played.
this.playFakeAudio();
return this.onAudioJoining()
.then(() => Promise.race([
bridge.joinAudio(callOptions, this.callStateCallback.bind(this)),
@ -213,6 +218,8 @@ class AudioManager {
});
}
clearInterval(this.fakeAudioInterval);
if (!this.isEchoTest) {
this.notify(this.messages.info.JOINED_AUDIO);
}
@ -352,6 +359,19 @@ class AudioManager {
this.isListenOnly ? 'audio_on' : 'unmute',
);
}
playFakeAudio() {
const outputDeviceId = this.outputDeviceId;
const sound = new Audio('resources/sounds/silence.mp3');
if (outputDeviceId && sound.setSinkId) {
sound.setSinkId(outputDeviceId);
}
// Hack within the hack: haven't got time to get the right timing to play
// the audio on stock listen only, but I'll get back to it - prlanzarin
this.fakeAudioInterval = setInterval(() => {
sound.play();
}, 1000);
}
}
const audioManager = new AudioManager();