fix(virtual-background) fix track leak in preview

This commit is contained in:
Tudor D. Pop 2021-05-12 12:36:49 +03:00 committed by GitHub
parent 5e4753888e
commit dcc659215e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 0 deletions

View File

@ -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);
}
/**