|
|
@@ -3,15 +3,18 @@
|
|
3
|
3
|
import Spinner from '@atlaskit/spinner';
|
|
4
|
4
|
import React, { PureComponent } from 'react';
|
|
5
|
5
|
|
|
|
6
|
+import { hideDialog } from '../../base/dialog';
|
|
6
|
7
|
import { translate } from '../../base/i18n';
|
|
7
|
8
|
import { VIDEO_TYPE } from '../../base/media';
|
|
8
|
9
|
import Video from '../../base/media/components/Video';
|
|
9
|
10
|
import { connect, equals } from '../../base/redux';
|
|
10
|
11
|
import { getCurrentCameraDeviceId } from '../../base/settings';
|
|
11
|
12
|
import { createLocalTracksF } from '../../base/tracks/functions';
|
|
|
13
|
+import { showWarningNotification } from '../../notifications/actions';
|
|
12
|
14
|
import { toggleBackgroundEffect } from '../actions';
|
|
13
|
15
|
import { VIRTUAL_BACKGROUND_TYPE } from '../constants';
|
|
14
|
16
|
import { localTrackStopped } from '../functions';
|
|
|
17
|
+import logger from '../logger';
|
|
15
|
18
|
|
|
16
|
19
|
const videoClassName = 'video-preview-video';
|
|
17
|
20
|
|
|
|
@@ -30,6 +33,11 @@ export type Props = {
|
|
30
|
33
|
*/
|
|
31
|
34
|
dispatch: Function,
|
|
32
|
35
|
|
|
|
36
|
+ /**
|
|
|
37
|
+ * Dialog callback that indicates if the background preview was loaded.
|
|
|
38
|
+ */
|
|
|
39
|
+ loadedPreview: Function,
|
|
|
40
|
+
|
|
33
|
41
|
/**
|
|
34
|
42
|
* Represents the virtual background setted options.
|
|
35
|
43
|
*/
|
|
|
@@ -51,6 +59,11 @@ type State = {
|
|
51
|
59
|
*/
|
|
52
|
60
|
loading: boolean,
|
|
53
|
61
|
|
|
|
62
|
+ /**
|
|
|
63
|
+ * Flag that indicates if the local track was loaded.
|
|
|
64
|
+ */
|
|
|
65
|
+ localTrackLoaded: boolean,
|
|
|
66
|
+
|
|
54
|
67
|
/**
|
|
55
|
68
|
* Activate the selected device camera only.
|
|
56
|
69
|
*/
|
|
|
@@ -77,6 +90,7 @@ class VirtualBackgroundPreview extends PureComponent<Props, State> {
|
|
77
|
90
|
|
|
78
|
91
|
this.state = {
|
|
79
|
92
|
loading: false,
|
|
|
93
|
+ localTrackLoaded: false,
|
|
80
|
94
|
jitsiTrack: null
|
|
81
|
95
|
};
|
|
82
|
96
|
}
|
|
|
@@ -99,24 +113,42 @@ class VirtualBackgroundPreview extends PureComponent<Props, State> {
|
|
99
|
113
|
* @returns {void}
|
|
100
|
114
|
*/
|
|
101
|
115
|
async _setTracks() {
|
|
102
|
|
- const [ jitsiTrack ] = await createLocalTracksF({
|
|
103
|
|
- cameraDeviceId: this.props._currentCameraDeviceId,
|
|
104
|
|
- devices: [ 'video' ]
|
|
105
|
|
- });
|
|
|
116
|
+ try {
|
|
|
117
|
+ this.setState({ loading: true });
|
|
|
118
|
+ const [ jitsiTrack ] = await createLocalTracksF({
|
|
|
119
|
+ cameraDeviceId: this.props._currentCameraDeviceId,
|
|
|
120
|
+ devices: [ 'video' ]
|
|
|
121
|
+ });
|
|
|
122
|
+
|
|
|
123
|
+ this.setState({ localTrackLoaded: true });
|
|
106
|
124
|
|
|
|
125
|
+ // In case the component gets unmounted before the tracks are created
|
|
|
126
|
+ // avoid a leak by not setting the state
|
|
|
127
|
+ if (this._componentWasUnmounted) {
|
|
|
128
|
+ this._stopStream(jitsiTrack);
|
|
107
|
129
|
|
|
108
|
|
- // In case the component gets unmounted before the tracks are created
|
|
109
|
|
- // avoid a leak by not setting the state
|
|
110
|
|
- if (this._componentWasUnmounted) {
|
|
111
|
|
- this._stopStream(jitsiTrack);
|
|
|
130
|
+ return;
|
|
|
131
|
+ }
|
|
|
132
|
+ this.setState({
|
|
|
133
|
+ jitsiTrack,
|
|
|
134
|
+ loading: false
|
|
|
135
|
+ });
|
|
|
136
|
+ this.props.loadedPreview(true);
|
|
|
137
|
+ } catch (error) {
|
|
|
138
|
+ this.props.dispatch(hideDialog());
|
|
|
139
|
+ this.props.dispatch(
|
|
|
140
|
+ showWarningNotification({
|
|
|
141
|
+ titleKey: 'virtualBackground.backgroundEffectError',
|
|
|
142
|
+ description: 'Failed to access camera device.'
|
|
|
143
|
+ })
|
|
|
144
|
+ );
|
|
|
145
|
+ logger.error('Failed to access camera device. Error on apply background effect.');
|
|
112
|
146
|
|
|
113
|
147
|
return;
|
|
114
|
148
|
}
|
|
115
|
|
- this.setState({
|
|
116
|
|
- jitsiTrack
|
|
117
|
|
- });
|
|
118
|
149
|
|
|
119
|
|
- if (this.props.options.backgroundType === VIRTUAL_BACKGROUND_TYPE.DESKTOP_SHARE) {
|
|
|
150
|
+ if (this.props.options.backgroundType === VIRTUAL_BACKGROUND_TYPE.DESKTOP_SHARE
|
|
|
151
|
+ && this.state.localTrackLoaded) {
|
|
120
|
152
|
this._applyBackgroundEffect();
|
|
121
|
153
|
}
|
|
122
|
154
|
}
|
|
|
@@ -128,7 +160,9 @@ class VirtualBackgroundPreview extends PureComponent<Props, State> {
|
|
128
|
160
|
*/
|
|
129
|
161
|
async _applyBackgroundEffect() {
|
|
130
|
162
|
this.setState({ loading: true });
|
|
|
163
|
+ this.props.loadedPreview(false);
|
|
131
|
164
|
await this.props.dispatch(toggleBackgroundEffect(this.props.options, this.state.jitsiTrack));
|
|
|
165
|
+ this.props.loadedPreview(true);
|
|
132
|
166
|
this.setState({ loading: false });
|
|
133
|
167
|
}
|
|
134
|
168
|
|
|
|
@@ -212,7 +246,7 @@ class VirtualBackgroundPreview extends PureComponent<Props, State> {
|
|
212
|
246
|
if (!equals(this.props._currentCameraDeviceId, prevProps._currentCameraDeviceId)) {
|
|
213
|
247
|
this._setTracks();
|
|
214
|
248
|
}
|
|
215
|
|
- if (!equals(this.props.options, prevProps.options)) {
|
|
|
249
|
+ if (!equals(this.props.options, prevProps.options) && this.state.localTrackLoaded) {
|
|
216
|
250
|
if (prevProps.options.backgroundType === VIRTUAL_BACKGROUND_TYPE.DESKTOP_SHARE) {
|
|
217
|
251
|
prevProps.options.url.dispose();
|
|
218
|
252
|
}
|