瀏覽代碼

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

j8
tudordan7 4 年之前
父節點
當前提交
f5dd848daf

+ 11
- 1
react/features/virtual-background/components/VirtualBackgroundDialog.js 查看文件

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

+ 8
- 1
react/features/virtual-background/components/VirtualBackgroundPreview.js 查看文件

@@ -9,8 +9,9 @@ import { connect, equals } from '../../base/redux';
9 9
 import { getCurrentCameraDeviceId } from '../../base/settings';
10 10
 import { createLocalTracksF } from '../../base/tracks/functions';
11 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 17
  * The type of the React {@code PureComponent} props of {@link VirtualBackgroundPreview}.
@@ -206,8 +207,14 @@ class VirtualBackgroundPreview extends PureComponent<Props, State> {
206 207
             this._setTracks();
207 208
         }
208 209
         if (!equals(this.props.options, prevProps.options)) {
210
+            if (prevProps.options.backgroundType === 'desktop-share') {
211
+                prevProps.options.url.dispose();
212
+            }
209 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 查看文件

@@ -1,4 +1,8 @@
1 1
 // @flow
2
+
3
+import { JitsiTrackEvents } from '../base/lib-jitsi-meet';
4
+
5
+import { toggleBackgroundEffect } from './actions';
2 6
 let filterSupport;
3 7
 
4 8
 /**
@@ -85,3 +89,26 @@ export function resizeImage(base64image: any, width: number = 1920, height: numb
85 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 查看文件

@@ -1,10 +1,9 @@
1 1
 // @flow
2 2
 
3
-import { JitsiTrackEvents } from '../base/lib-jitsi-meet';
4 3
 import { MiddlewareRegistry } from '../base/redux';
5 4
 import { getLocalVideoTrack } from '../base/tracks';
6 5
 
7
-import { toggleBackgroundEffect } from './actions';
6
+import { localTrackStopped } from './functions';
8 7
 
9 8
 /**
10 9
  * Middleware which intercepts the desktop video type on
@@ -20,17 +19,7 @@ MiddlewareRegistry.register(store => next => action => {
20 19
     const currentLocalTrack = getLocalVideoTrack(getState()['features/base/tracks']);
21 20
 
22 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 25
     return next(action);

Loading…
取消
儲存