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.
master
Saúl Ibarra Corretgé 8 anos atrás
pai
commit
4ddc426966

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

68
  */
68
  */
69
 export const LOCK_STATE_CHANGED = Symbol('LOCK_STATE_CHANGED');
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
  * The type of the Redux action which sets the password to join or lock a
83
  * The type of the Redux action which sets the password to join or lock a
73
  * specific JitsiConference.
84
  * specific JitsiConference.

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

18
     CONFERENCE_WILL_JOIN,
18
     CONFERENCE_WILL_JOIN,
19
     CONFERENCE_WILL_LEAVE,
19
     CONFERENCE_WILL_LEAVE,
20
     LOCK_STATE_CHANGED,
20
     LOCK_STATE_CHANGED,
21
+    SET_LASTN,
21
     SET_PASSWORD,
22
     SET_PASSWORD,
22
     SET_ROOM
23
     SET_ROOM
23
 } from './actionTypes';
24
 } from './actionTypes';
28
 } from './constants';
29
 } from './constants';
29
 import { _addLocalTracksToConference } from './functions';
30
 import { _addLocalTracksToConference } from './functions';
30
 
31
 
32
+import type { Dispatch } from 'redux';
33
+
31
 /**
34
 /**
32
  * Adds conference (event) listeners.
35
  * Adds conference (event) listeners.
33
  *
36
  *
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
  * Sets the password to join or lock a specific JitsiConference.
310
  * Sets the password to join or lock a specific JitsiConference.
279
  *
311
  *

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

9
 import { TRACK_ADDED, TRACK_REMOVED } from '../tracks';
9
 import { TRACK_ADDED, TRACK_REMOVED } from '../tracks';
10
 
10
 
11
 import { createConference } from './actions';
11
 import { createConference } from './actions';
12
+import { SET_LASTN } from './actionTypes';
12
 import {
13
 import {
13
     _addLocalTracksToConference,
14
     _addLocalTracksToConference,
14
     _handleParticipantError,
15
     _handleParticipantError,
29
     case PIN_PARTICIPANT:
30
     case PIN_PARTICIPANT:
30
         return _pinParticipant(store, next, action);
31
         return _pinParticipant(store, next, action);
31
 
32
 
33
+    case SET_LASTN:
34
+        return _setLastN(store, next, action);
35
+
32
     case TRACK_ADDED:
36
     case TRACK_ADDED:
33
     case TRACK_REMOVED:
37
     case TRACK_REMOVED:
34
         return _trackAddedOrRemoved(store, next, action);
38
         return _trackAddedOrRemoved(store, next, action);
112
     return next(action);
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
  * Synchronizes local tracks from state with local tracks in JitsiConference
147
  * Synchronizes local tracks from state with local tracks in JitsiConference
117
  * instance.
148
  * instance.

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

4
  * The type of redux action to set the AppState API change event listener.
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
  * @protected
11
  * @protected
17
  * app is going to the background.
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
  * @protected
24
  * @protected
26
 export const _SET_BACKGROUND_VIDEO_MUTED
26
 export const _SET_BACKGROUND_VIDEO_MUTED
27
     = Symbol('_SET_BACKGROUND_VIDEO_MUTED');
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
  * The type of redux action which signals that the app state has changed (in
30
  * The type of redux action which signals that the app state has changed (in
43
  * terms of execution mode). The app state can be one of 'active', 'inactive',
31
  * terms of execution mode). The app state can be one of 'active', 'inactive',
44
  * or 'background'.
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
  * @public
39
  * @public

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

1
+import { setLastN } from '../../base/conference';
1
 import { setVideoMuted } from '../../base/media';
2
 import { setVideoMuted } from '../../base/media';
2
 
3
 
3
 import {
4
 import {
4
     _SET_APP_STATE_LISTENER,
5
     _SET_APP_STATE_LISTENER,
5
     _SET_BACKGROUND_VIDEO_MUTED,
6
     _SET_BACKGROUND_VIDEO_MUTED,
6
-    _SET_LASTN,
7
     APP_STATE_CHANGED
7
     APP_STATE_CHANGED
8
 } from './actionTypes';
8
 } from './actionTypes';
9
 
9
 
36
  */
36
  */
37
 export function _setBackgroundVideoMuted(muted: boolean) {
37
 export function _setBackgroundVideoMuted(muted: boolean) {
38
     return (dispatch, getState) => {
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
         const { audioOnly } = getState()['features/base/conference'];
43
         const { audioOnly } = getState()['features/base/conference'];
43
 
44
 
44
         if (!audioOnly) {
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
         if (muted) {
49
         if (muted) {

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

16
 } from './actions';
16
 } from './actions';
17
 import {
17
 import {
18
     _SET_APP_STATE_LISTENER,
18
     _SET_APP_STATE_LISTENER,
19
-    _SET_LASTN,
20
     APP_STATE_CHANGED
19
     APP_STATE_CHANGED
21
 } from './actionTypes';
20
 } from './actionTypes';
22
 
21
 
47
         break;
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
     case APP_STATE_CHANGED:
49
     case APP_STATE_CHANGED:
65
         _appStateChanged(store.dispatch, action.appState);
50
         _appStateChanged(store.dispatch, action.appState);
66
         break;
51
         break;

Carregando…
Cancelar
Salvar