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(virtual-background) fix track leak in preview

Tudor D. Popdcc659215e00
diff --git a/react/features/virtual-background/components/VirtualBackgroundPreview.js b/react/features/virtual-background/components/VirtualBackgroundPreview.js
index 55c384c07d..135f7ea2a0 100644
--- a/react/features/virtual-background/components/VirtualBackgroundPreview.js
+++ b/react/features/virtual-background/components/VirtualBackgroundPreview.js
@@ -78,6 +78,18 @@ class VirtualBackgroundPreview extends PureComponent<Props, State> {
};
}
+ /**
+ * Destroys the jitsiTrack object.
+ *
+ * @param {Object} jitsiTrack - The track that needs to be disposed.
+ * @returns {Promise<void>}
+ */
+ _stopStream(jitsiTrack) {
+ if (jitsiTrack) {
+ jitsiTrack.dispose();
+ }
+ }
+
/**
* Creates and updates the track data.
*
@@ -89,9 +101,12 @@ class VirtualBackgroundPreview extends PureComponent<Props, State> {
devices: [ 'video' ]
});
+
// In case the component gets unmounted before the tracks are created
// avoid a leak by not setting the state
if (this._componentWasUnmounted) {
+ this._stopStream(jitsiTrack);
+
return;
}
this.setState({
@@ -178,6 +193,7 @@ class VirtualBackgroundPreview extends PureComponent<Props, State> {
*/
componentWillUnmount() {
this._componentWasUnmounted = true;
+ this._stopStream(this.state.jitsiTrack);
}
/**