fix(virtual-background) fix track leak in preview
This commit is contained in:
parent
5e4753888e
commit
dcc659215e
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue