Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

fix(Video.js): prevent DOMException: The play() request was interrupted by a new load request

Paweł Domasa6054030292b
diff --git a/react/features/base/media/components/web/Video.js b/react/features/base/media/components/web/Video.js
index c140228cad..da0e3859a9 100644
--- a/react/features/base/media/components/web/Video.js
+++ b/react/features/base/media/components/web/Video.js
@@ -144,6 +144,7 @@ type Props = {
*/
class Video extends Component<Props> {
_videoElement: ?Object;
+ _mounted: boolean;
/**
* Default values for {@code Video} component's properties.
@@ -189,6 +190,8 @@ class Video extends Component<Props> {
* @returns {void}
*/
componentDidMount() {
+ this._mounted = true;
+
if (this._videoElement) {
this._videoElement.volume = 0;
this._videoElement.onplaying = this._onVideoPlaying;
@@ -200,7 +203,14 @@ class Video extends Component<Props> {
// Ensure the video gets play() called on it. This may be necessary in the
// case where the local video container was moved and re-attached, in which
// case video does not autoplay.
- this._videoElement.play();
+ this._videoElement.play()
+ .catch(error => {
+ // Prevent uncaught "DOMException: The play() request was interrupted by a new load request"
+ // when video playback takes long to start and it starts after the component was unmounted.
+ if (this._mounted) {
+ throw error;
+ }
+ });
}
}
@@ -212,6 +222,7 @@ class Video extends Component<Props> {
* @returns {void}
*/
componentWillUnmount() {
+ this._mounted = false;
this._detachTrack(this.props.videoTrack);
}