From 89719520e28066f5e68d0ea0bef766efd6bdd110 Mon Sep 17 00:00:00 2001 From: damencho Date: Mon, 29 Apr 2019 11:41:54 +0100 Subject: [PATCH] Disposes the tracks in component was unmounted while creating those. The issue is if you quickly click Devices and then another tab, we may leave open tracks (video light stays on even when you are video muted). --- .../components/DeviceSelection.js | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/react/features/device-selection/components/DeviceSelection.js b/react/features/device-selection/components/DeviceSelection.js index ec5f03439..20bec7818 100644 --- a/react/features/device-selection/components/DeviceSelection.js +++ b/react/features/device-selection/components/DeviceSelection.js @@ -118,6 +118,18 @@ type State = { * @extends Component */ class DeviceSelection extends AbstractDialogTab { + + /** + * Whether current component is mounted or not. + * + * In component did mount we start a Promise to create tracks and + * set the tracks in the state, if we unmount the component in the meanwhile + * tracks will be created and will never been disposed (dispose tracks is + * in componentWillUnmount). When tracks are created and component is + * unmounted we dispose the tracks. + */ + _unMounted: boolean; + /** * Initializes a new DeviceSelection instance. * @@ -134,6 +146,7 @@ class DeviceSelection extends AbstractDialogTab { previewVideoTrack: null, previewVideoTrackError: null }; + this._unMounted = true; } /** @@ -142,6 +155,7 @@ class DeviceSelection extends AbstractDialogTab { * @inheritdoc */ componentDidMount() { + this._unMounted = false; Promise.all([ this._createAudioInputTrack(this.props.selectedAudioInputId), this._createVideoInputTrack(this.props.selectedVideoInputId) @@ -193,6 +207,7 @@ class DeviceSelection extends AbstractDialogTab { * @inheritdoc */ componentWillUnmount() { + this._unMounted = true; this._disposeAudioInputPreview(); this._disposeVideoInputPreview(); } @@ -244,6 +259,12 @@ class DeviceSelection extends AbstractDialogTab { return this._disposeAudioInputPreview() .then(() => createLocalTrack('audio', deviceId)) .then(jitsiLocalTrack => { + if (this._unMounted) { + jitsiLocalTrack.dispose(); + + return; + } + this.setState({ previewAudioTrack: jitsiLocalTrack }); @@ -270,6 +291,12 @@ class DeviceSelection extends AbstractDialogTab { return Promise.reject(); } + if (this._unMounted) { + jitsiLocalTrack.dispose(); + + return; + } + this.setState({ previewVideoTrack: jitsiLocalTrack, previewVideoTrackError: null