Ver código fonte

[RN] Move setting last N action to base/conference

This is in preparation for an upcoming "audio only mode" feature. Setting last N
will also be required for it, so this patch factors out the action and makes it
public so other modules can reuse it.

In addition, if the value is set to undefined the configured default value (or
-1 if absent) is picked.
j8
Saúl Ibarra Corretgé 8 anos atrás
pai
commit
4ddc426966

+ 11
- 0
react/features/base/conference/actionTypes.js Ver arquivo

@@ -68,6 +68,17 @@ export const CONFERENCE_WILL_LEAVE = Symbol('CONFERENCE_WILL_LEAVE');
68 68
  */
69 69
 export const LOCK_STATE_CHANGED = Symbol('LOCK_STATE_CHANGED');
70 70
 
71
+/**
72
+ * The type of redux action which sets the video channel's lastN (value).
73
+ *
74
+ * {
75
+ *     type: SET_LASTN,
76
+ *     lastN: number
77
+ * }
78
+ *
79
+ */
80
+export const SET_LASTN = Symbol('SET_LASTN');
81
+
71 82
 /**
72 83
  * The type of the Redux action which sets the password to join or lock a
73 84
  * specific JitsiConference.

+ 32
- 0
react/features/base/conference/actions.js Ver arquivo

@@ -18,6 +18,7 @@ import {
18 18
     CONFERENCE_WILL_JOIN,
19 19
     CONFERENCE_WILL_LEAVE,
20 20
     LOCK_STATE_CHANGED,
21
+    SET_LASTN,
21 22
     SET_PASSWORD,
22 23
     SET_ROOM
23 24
 } from './actionTypes';
@@ -28,6 +29,8 @@ import {
28 29
 } from './constants';
29 30
 import { _addLocalTracksToConference } from './functions';
30 31
 
32
+import type { Dispatch } from 'redux';
33
+
31 34
 /**
32 35
  * Adds conference (event) listeners.
33 36
  *
@@ -274,6 +277,35 @@ function _lockStateChanged(conference, locked) {
274 277
     };
275 278
 }
276 279
 
280
+/**
281
+ * Sets the video channel's last N (value) of the current conference. A value of
282
+ * undefined shall be used to reset it to the default value.
283
+ *
284
+ * @param {(number|undefined)} lastN - The last N value to be set.
285
+ * @returns {Function}
286
+ */
287
+export function setLastN(lastN: ?number) {
288
+    return (dispatch: Dispatch<*>, getState: Function) => {
289
+        if (typeof lastN === 'undefined') {
290
+            const { config } = getState()['features/base/lib-jitsi-meet'];
291
+
292
+            /* eslint-disable no-param-reassign */
293
+
294
+            lastN = config.channelLastN;
295
+            if (typeof lastN === 'undefined') {
296
+                lastN = -1;
297
+            }
298
+
299
+            /* eslint-enable no-param-reassign */
300
+        }
301
+
302
+        dispatch({
303
+            type: SET_LASTN,
304
+            lastN
305
+        });
306
+    };
307
+}
308
+
277 309
 /**
278 310
  * Sets the password to join or lock a specific JitsiConference.
279 311
  *

+ 31
- 0
react/features/base/conference/middleware.js Ver arquivo

@@ -9,6 +9,7 @@ import { MiddlewareRegistry } from '../redux';
9 9
 import { TRACK_ADDED, TRACK_REMOVED } from '../tracks';
10 10
 
11 11
 import { createConference } from './actions';
12
+import { SET_LASTN } from './actionTypes';
12 13
 import {
13 14
     _addLocalTracksToConference,
14 15
     _handleParticipantError,
@@ -29,6 +30,9 @@ MiddlewareRegistry.register(store => next => action => {
29 30
     case PIN_PARTICIPANT:
30 31
         return _pinParticipant(store, next, action);
31 32
 
33
+    case SET_LASTN:
34
+        return _setLastN(store, next, action);
35
+
32 36
     case TRACK_ADDED:
33 37
     case TRACK_REMOVED:
34 38
         return _trackAddedOrRemoved(store, next, action);
@@ -112,6 +116,33 @@ function _pinParticipant(store, next, action) {
112 116
     return next(action);
113 117
 }
114 118
 
119
+/**
120
+ * Sets the last N (value) of the video channel in the conference.
121
+ *
122
+ * @param {Store} store - The Redux store in which the specified action is being
123
+ * dispatched.
124
+ * @param {Dispatch} next - The Redux dispatch function to dispatch the
125
+ * specified action to the specified store.
126
+ * @param {Action} action - The Redux action SET_LASTN which is being dispatched
127
+ * in the specified store.
128
+ * @private
129
+ * @returns {Object} The new state that is the result of the reduction of the
130
+ * specified action.
131
+ */
132
+function _setLastN(store, next, action) {
133
+    const { conference } = store.getState()['features/base/conference'];
134
+
135
+    if (conference) {
136
+        try {
137
+            conference.setLastN(action.lastN);
138
+        } catch (err) {
139
+            console.error(`Failed to set lastN: ${err}`);
140
+        }
141
+    }
142
+
143
+    return next(action);
144
+}
145
+
115 146
 /**
116 147
  * Synchronizes local tracks from state with local tracks in JitsiConference
117 148
  * instance.

+ 6
- 18
react/features/mobile/background/actionTypes.js Ver arquivo

@@ -4,8 +4,8 @@ import { Symbol } from '../../base/react';
4 4
  * The type of redux action to set the AppState API change event listener.
5 5
  *
6 6
  * {
7
- *      type: _SET_APP_STATE_LISTENER,
8
- *      listener: Function
7
+ *     type: _SET_APP_STATE_LISTENER,
8
+ *     listener: Function
9 9
  * }
10 10
  *
11 11
  * @protected
@@ -17,8 +17,8 @@ export const _SET_APP_STATE_LISTENER = Symbol('_SET_APP_STATE_LISTENER');
17 17
  * app is going to the background.
18 18
  *
19 19
  * {
20
- *      type: _SET_BACKGROUND_VIDEO_MUTED,
21
- *      muted: boolean
20
+ *     type: _SET_BACKGROUND_VIDEO_MUTED,
21
+ *     muted: boolean
22 22
  * }
23 23
  *
24 24
  * @protected
@@ -26,26 +26,14 @@ export const _SET_APP_STATE_LISTENER = Symbol('_SET_APP_STATE_LISTENER');
26 26
 export const _SET_BACKGROUND_VIDEO_MUTED
27 27
     = Symbol('_SET_BACKGROUND_VIDEO_MUTED');
28 28
 
29
-/**
30
- * The type of redux action which sets the video channel's lastN (value).
31
- *
32
- * {
33
- *      type: _SET_LASTN,
34
- *      lastN: boolean
35
- * }
36
- *
37
- * @protected
38
- */
39
-export const _SET_LASTN = Symbol('_SET_LASTN');
40
-
41 29
 /**
42 30
  * The type of redux action which signals that the app state has changed (in
43 31
  * terms of execution mode). The app state can be one of 'active', 'inactive',
44 32
  * or 'background'.
45 33
  *
46 34
  * {
47
- *      type: APP_STATE_CHANGED,
48
- *      appState: string
35
+ *     type: APP_STATE_CHANGED,
36
+ *     appState: string
49 37
  * }
50 38
  *
51 39
  * @public

+ 6
- 21
react/features/mobile/background/actions.js Ver arquivo

@@ -1,9 +1,9 @@
1
+import { setLastN } from '../../base/conference';
1 2
 import { setVideoMuted } from '../../base/media';
2 3
 
3 4
 import {
4 5
     _SET_APP_STATE_LISTENER,
5 6
     _SET_BACKGROUND_VIDEO_MUTED,
6
-    _SET_LASTN,
7 7
     APP_STATE_CHANGED
8 8
 } from './actionTypes';
9 9
 
@@ -36,29 +36,14 @@ export function _setAppStateListener(listener: ?Function) {
36 36
  */
37 37
 export function _setBackgroundVideoMuted(muted: boolean) {
38 38
     return (dispatch, getState) => {
39
-        // Disable remote video when we mute by setting lastN to 0.
40
-        // Skip it if the conference is in audio only mode, as it's
41
-        // already configured to have no video.
39
+        // Disable remote video when we mute by setting lastN to 0. Skip it if
40
+        // the conference is in audio-only mode, as it's already configured to
41
+        // have no video. Leave it as undefined when unmuting, the default value
42
+        // for last N will be chosen automatically.
42 43
         const { audioOnly } = getState()['features/base/conference'];
43 44
 
44 45
         if (!audioOnly) {
45
-            let lastN;
46
-
47
-            if (muted) {
48
-                lastN = 0;
49
-            } else {
50
-                const { config } = getState()['features/base/lib-jitsi-meet'];
51
-
52
-                lastN = config.channelLastN;
53
-                if (typeof lastN === 'undefined') {
54
-                    lastN = -1;
55
-                }
56
-            }
57
-
58
-            dispatch({
59
-                type: _SET_LASTN,
60
-                lastN
61
-            });
46
+            dispatch(setLastN(muted ? 0 : undefined));
62 47
         }
63 48
 
64 49
         if (muted) {

+ 0
- 15
react/features/mobile/background/middleware.js Ver arquivo

@@ -16,7 +16,6 @@ import {
16 16
 } from './actions';
17 17
 import {
18 18
     _SET_APP_STATE_LISTENER,
19
-    _SET_LASTN,
20 19
     APP_STATE_CHANGED
21 20
 } from './actionTypes';
22 21
 
@@ -47,20 +46,6 @@ MiddlewareRegistry.register(store => next => action => {
47 46
         break;
48 47
     }
49 48
 
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(`Failed to set lastN: ${err}`);
58
-            }
59
-        }
60
-
61
-        break;
62
-    }
63
-
64 49
     case APP_STATE_CHANGED:
65 50
         _appStateChanged(store.dispatch, action.appState);
66 51
         break;

Carregando…
Cancelar
Salvar