Sfoglia il codice sorgente

[RN] Disable remote video while in the background

Set the video channel "last N" property to 0, thus making the client not receive
any remote video.
j8
Saúl Ibarra Corretgé 8 anni fa
parent
commit
2d5f0479bd

+ 15
- 0
react/features/background/actionTypes.js Vedi File

@@ -27,6 +27,21 @@ export const _SET_APP_STATE_LISTENER
27 27
 export const _SET_BACKGROUND_VIDEO_MUTED
28 28
     = Symbol('_SET_BACKGROUND_VIDEO_MUTED');
29 29
 
30
+/**
31
+ * The type of redux action which signals that the video channel's lastN value
32
+ * must be changed.
33
+ *
34
+ * {
35
+ *      type: _SET_LASTN,
36
+ *      lastN: boolean
37
+ * }
38
+ *
39
+ * @protected
40
+ */
41
+export const _SET_LASTN
42
+    = Symbol('_SET_LASTN');
43
+
44
+
30 45
 /**
31 46
  * The type of redux action which signals that the app state has changed (in
32 47
  * terms of execution mode). The app state can be one of 'active', 'inactive',

+ 22
- 4
react/features/background/actions.js Vedi File

@@ -3,6 +3,7 @@ import { setVideoMuted } from '../base/media';
3 3
 import {
4 4
     _SET_APP_STATE_LISTENER,
5 5
     _SET_BACKGROUND_VIDEO_MUTED,
6
+    _SET_LASTN,
6 7
     APP_STATE_CHANGED
7 8
 } from './actionTypes';
8 9
 
@@ -54,6 +55,23 @@ export function _setAppStateListener(listener: ?Function) {
54 55
  */
55 56
 export function _setBackgroundVideoMuted(muted: boolean) {
56 57
     return (dispatch, getState) => {
58
+        // Disable remote video when we mute by setting lastN to 0.
59
+        // Skip it if the conference is in audio only mode, as it's
60
+        // already configured to have no video.
61
+        const { audioOnly } = getState()['features/base/conference'];
62
+
63
+        if (!audioOnly) {
64
+            const { config } = getState()['features/base/lib-jitsi-meet'];
65
+            const defaultLastN
66
+                = typeof config.channelLastN === 'undefined'
67
+                ? -1 : config.channelLastN;
68
+
69
+            dispatch({
70
+                type: _SET_LASTN,
71
+                lastN: muted ? 0 : defaultLastN
72
+            });
73
+        }
74
+
57 75
         if (muted) {
58 76
             const mediaState = getState()['features/base/media'];
59 77
 
@@ -62,16 +80,16 @@ export function _setBackgroundVideoMuted(muted: boolean) {
62 80
                 return;
63 81
             }
64 82
         } else {
65
-            const bgState = getState()['features/background'];
83
+            const { videoMuted } = getState()['features/background'];
66 84
 
67
-            if (!bgState.videoMuted) {
85
+            if (!videoMuted) {
68 86
                 // We didn't mute video, do nothing.
69 87
                 return;
70 88
             }
71 89
         }
72 90
 
73
-        // Remember that video was muted due to the app going to the background
74
-        // vs user's choice.
91
+        // Remember that local video was muted due to the app going to the
92
+        // background vs user's choice.
75 93
         dispatch({
76 94
             type: _SET_BACKGROUND_VIDEO_MUTED,
77 95
             muted

+ 15
- 0
react/features/background/middleware.js Vedi File

@@ -16,6 +16,7 @@ import {
16 16
 } from './actions';
17 17
 import {
18 18
     _SET_APP_STATE_LISTENER,
19
+    _SET_LASTN,
19 20
     APP_STATE_CHANGED
20 21
 } from './actionTypes';
21 22
 
@@ -46,6 +47,20 @@ MiddlewareRegistry.register(store => next => action => {
46 47
         break;
47 48
     }
48 49
 
50
+    case _SET_LASTN: {
51
+        const { conference } = store.getState()['features/base/conference'];
52
+
53
+        if (conference) {
54
+            try {
55
+                conference.setLastN(action.lastN);
56
+            } catch (err) {
57
+                console.warn(`Error setting lastN: ${err}`);
58
+            }
59
+        }
60
+
61
+        break;
62
+    }
63
+
49 64
     case APP_STATE_CHANGED:
50 65
         _appStateChanged(store.dispatch, action.appState);
51 66
         break;

Loading…
Annulla
Salva