diff --git a/addons/mail/static/src/components/rtc_video/rtc_video.js b/addons/mail/static/src/components/rtc_video/rtc_video.js index 9b0b2df55c4..185669d651f 100644 --- a/addons/mail/static/src/components/rtc_video/rtc_video.js +++ b/addons/mail/static/src/components/rtc_video/rtc_video.js @@ -60,11 +60,22 @@ export class RtcVideo extends Component { //-------------------------------------------------------------------------- /** + * Plays the video as some browsers may not support or block autoplay. + * * @private * @param {Event} ev */ async _onVideoLoadedMetaData(ev) { - await ev.target.play(); + try { + await ev.target.play(); + } catch (error) { + if (typeof error === 'object' && error.name === 'NotAllowedError') { + // Ignored as some browsers may reject play() calls that do not + // originate from a user input. + return; + } + throw error; + } } } diff --git a/addons/mail/static/src/components/rtc_video/rtc_video.xml b/addons/mail/static/src/components/rtc_video/rtc_video.xml index 14248f3b0d6..8dc63649de4 100644 --- a/addons/mail/static/src/components/rtc_video/rtc_video.xml +++ b/addons/mail/static/src/components/rtc_video/rtc_video.xml @@ -4,7 +4,11 @@ diff --git a/addons/mail/static/src/models/rtc_session/rtc_session.js b/addons/mail/static/src/models/rtc_session/rtc_session.js index 6051339efbb..5a11c625a4f 100644 --- a/addons/mail/static/src/models/rtc_session/rtc_session.js +++ b/addons/mail/static/src/models/rtc_session/rtc_session.js @@ -104,19 +104,31 @@ function factory(dependencies) { * @param {boolean} param0.isMuted * @param {boolean} param0.isTalking */ - setAudio({ audioStream, isMuted, isTalking }) { + async setAudio({ audioStream, isMuted, isTalking }) { this._removeAudio(); const audioElement = this.audioElement || new window.Audio(); audioElement.srcObject = audioStream; audioElement.volume = this.partner && this.partner.volumeSetting ? this.partner.volumeSetting.volume : this.volume; audioElement.muted = this.messaging.mailRtc.currentRtcSession.isDeaf; - audioElement.play(); + // Using both autoplay and play() as safari may prevent play() outside of user interactions + // while some browsers may not support or block autoplay. + audioElement.autoplay = true; this.update({ audioElement, audioStream, isMuted, isTalking, }); + try { + await audioElement.play(); + } catch (error) { + if (typeof error === 'object' && error.name === 'NotAllowedError') { + // Ignored as some browsers may reject play() calls that do not + // originate from a user input. + return; + } + throw error; + } } /**