Browse Source

feat(virtual-background): Desktop share as virtual background

j8
tudordan7 4 years ago
parent
commit
f5dd848daf

+ 11
- 1
react/features/virtual-background/components/VirtualBackgroundDialog.js View File

63
      */
63
      */
64
     _selectedThumbnail: string,
64
     _selectedThumbnail: string,
65
 
65
 
66
+    /**
67
+     * Returns the selected virtual source object.
68
+     */
69
+    _virtualSource: Object,
70
+
66
     /**
71
     /**
67
      * The redux {@code dispatch} function.
72
      * The redux {@code dispatch} function.
68
      */
73
      */
79
  *
84
  *
80
  * @returns {ReactElement}
85
  * @returns {ReactElement}
81
  */
86
  */
82
-function VirtualBackground({ _jitsiTrack, _selectedThumbnail, dispatch, t }: Props) {
87
+function VirtualBackground({ _jitsiTrack, _selectedThumbnail, _virtualSource, dispatch, t }: Props) {
83
     const [ options, setOptions ] = useState({});
88
     const [ options, setOptions ] = useState({});
84
     const localImages = jitsiLocalStorage.getItem('virtualBackgrounds');
89
     const localImages = jitsiLocalStorage.getItem('virtualBackgrounds');
85
     const [ storedImages, setStoredImages ] = useState((localImages && JSON.parse(localImages)) || []);
90
     const [ storedImages, setStoredImages ] = useState((localImages && JSON.parse(localImages)) || []);
86
     const [ loading, isloading ] = useState(false);
91
     const [ loading, isloading ] = useState(false);
92
+    const [ activeDesktopVideo ] = useState(_virtualSource?.videoType === 'desktop' ? _virtualSource : null);
87
 
93
 
88
     const deleteStoredImage = image => {
94
     const deleteStoredImage = image => {
89
         setStoredImages(storedImages.filter(item => item !== image));
95
         setStoredImages(storedImages.filter(item => item !== image));
180
     };
186
     };
181
 
187
 
182
     const applyVirtualBackground = async () => {
188
     const applyVirtualBackground = async () => {
189
+        if (activeDesktopVideo) {
190
+            await activeDesktopVideo.dispose();
191
+        }
183
         isloading(true);
192
         isloading(true);
184
         await dispatch(toggleBackgroundEffect(options, _jitsiTrack));
193
         await dispatch(toggleBackgroundEffect(options, _jitsiTrack));
185
         await isloading(false);
194
         await isloading(false);
289
  */
298
  */
290
 function _mapStateToProps(state): Object {
299
 function _mapStateToProps(state): Object {
291
     return {
300
     return {
301
+        _virtualSource: state['features/virtual-background'].virtualSource,
292
         _selectedThumbnail: state['features/virtual-background'].selectedThumbnail,
302
         _selectedThumbnail: state['features/virtual-background'].selectedThumbnail,
293
         _jitsiTrack: getLocalVideoTrack(state['features/base/tracks'])?.jitsiTrack
303
         _jitsiTrack: getLocalVideoTrack(state['features/base/tracks'])?.jitsiTrack
294
     };
304
     };

+ 8
- 1
react/features/virtual-background/components/VirtualBackgroundPreview.js View File

9
 import { getCurrentCameraDeviceId } from '../../base/settings';
9
 import { getCurrentCameraDeviceId } from '../../base/settings';
10
 import { createLocalTracksF } from '../../base/tracks/functions';
10
 import { createLocalTracksF } from '../../base/tracks/functions';
11
 import { toggleBackgroundEffect } from '../actions';
11
 import { toggleBackgroundEffect } from '../actions';
12
+import { localTrackStopped } from '../functions';
12
 
13
 
13
-const videoClassName = 'virtual-background-preview-video flipVideoX';
14
+const videoClassName = 'video-preview-video';
14
 
15
 
15
 /**
16
 /**
16
  * The type of the React {@code PureComponent} props of {@link VirtualBackgroundPreview}.
17
  * The type of the React {@code PureComponent} props of {@link VirtualBackgroundPreview}.
206
             this._setTracks();
207
             this._setTracks();
207
         }
208
         }
208
         if (!equals(this.props.options, prevProps.options)) {
209
         if (!equals(this.props.options, prevProps.options)) {
210
+            if (prevProps.options.backgroundType === 'desktop-share') {
211
+                prevProps.options.url.dispose();
212
+            }
209
             this._applyBackgroundEffect();
213
             this._applyBackgroundEffect();
210
         }
214
         }
215
+        if (this.props.options.url?.videoType === 'desktop') {
216
+            localTrackStopped(this.props.dispatch, this.props.options.url, this.state.jitsiTrack);
217
+        }
211
     }
218
     }
212
 
219
 
213
     /**
220
     /**

+ 27
- 0
react/features/virtual-background/functions.js View File

1
 // @flow
1
 // @flow
2
+
3
+import { JitsiTrackEvents } from '../base/lib-jitsi-meet';
4
+
5
+import { toggleBackgroundEffect } from './actions';
2
 let filterSupport;
6
 let filterSupport;
3
 
7
 
4
 /**
8
 /**
85
         img.src = base64image;
89
         img.src = base64image;
86
     });
90
     });
87
 }
91
 }
92
+
93
+/**
94
+ * Check if the local desktop track was stopped and apply none option on virtual background.
95
+ *
96
+ * @param {Function} dispatch - The Redux dispatch function.
97
+ * @param {Object} desktopTrack - The desktop track that needs to be checked if it was stopped.
98
+ * @param {Object} currentLocalTrack - The current local track where we apply none virtual
99
+ * background option if the desktop track was stopped.
100
+ * @returns {Promise}
101
+ */
102
+export function localTrackStopped(dispatch: Function, desktopTrack: Object, currentLocalTrack: Object) {
103
+    const noneOptions = {
104
+        enabled: false,
105
+        backgroundType: 'none',
106
+        selectedThumbnail: 'none',
107
+        backgroundEffectEnabled: false
108
+    };
109
+
110
+    desktopTrack
111
+    && desktopTrack.on(JitsiTrackEvents.LOCAL_TRACK_STOPPED, () => {
112
+        dispatch(toggleBackgroundEffect(noneOptions, currentLocalTrack));
113
+    });
114
+}

+ 2
- 13
react/features/virtual-background/middleware.js View File

1
 // @flow
1
 // @flow
2
 
2
 
3
-import { JitsiTrackEvents } from '../base/lib-jitsi-meet';
4
 import { MiddlewareRegistry } from '../base/redux';
3
 import { MiddlewareRegistry } from '../base/redux';
5
 import { getLocalVideoTrack } from '../base/tracks';
4
 import { getLocalVideoTrack } from '../base/tracks';
6
 
5
 
7
-import { toggleBackgroundEffect } from './actions';
6
+import { localTrackStopped } from './functions';
8
 
7
 
9
 /**
8
 /**
10
  * Middleware which intercepts the desktop video type on
9
  * Middleware which intercepts the desktop video type on
20
     const currentLocalTrack = getLocalVideoTrack(getState()['features/base/tracks']);
19
     const currentLocalTrack = getLocalVideoTrack(getState()['features/base/tracks']);
21
 
20
 
22
     if (virtualSource?.videoType === 'desktop') {
21
     if (virtualSource?.videoType === 'desktop') {
23
-        const noneOptions = {
24
-            enabled: false,
25
-            backgroundType: 'none',
26
-            selectedThumbnail: 'none',
27
-            backgroundEffectEnabled: false
28
-        };
29
-
30
-        virtualSource
31
-            && virtualSource.on(JitsiTrackEvents.LOCAL_TRACK_STOPPED, () => {
32
-                dispatch(toggleBackgroundEffect(noneOptions, currentLocalTrack.jitsiTrack));
33
-            });
22
+        localTrackStopped(dispatch, virtualSource, currentLocalTrack.jitsiTrack);
34
     }
23
     }
35
 
24
 
36
     return next(action);
25
     return next(action);

Loading…
Cancel
Save