浏览代码

[RN] Unpin participant and set last N to 1 if the filmstrip is disabled (Coding style: consistency)

j8
Lyubo Marinov 7 年前
父节点
当前提交
10f72f8e40
共有 2 个文件被更改,包括 105 次插入75 次删除
  1. 27
    41
      react/features/base/conference/middleware.js
  2. 78
    34
      react/features/filmstrip/middleware.js

+ 27
- 41
react/features/base/conference/middleware.js 查看文件

@@ -1,7 +1,5 @@
1 1
 // @flow
2 2
 
3
-import UIEvents from '../../../../service/UI/UIEvents';
4
-
5 3
 import {
6 4
     ACTION_PINNED,
7 5
     ACTION_UNPINNED,
@@ -18,6 +16,7 @@ import {
18 16
     PIN_PARTICIPANT
19 17
 } from '../participants';
20 18
 import { MiddlewareRegistry } from '../redux';
19
+import UIEvents from '../../../../service/UI/UIEvents';
21 20
 import { TRACK_ADDED, TRACK_REMOVED } from '../tracks';
22 21
 
23 22
 import {
@@ -97,16 +96,15 @@ MiddlewareRegistry.register(store => next => action => {
97 96
  * @param {Action} action - The redux action CONNECTION_ESTABLISHED which is
98 97
  * being dispatched in the specified store.
99 98
  * @private
100
- * @returns {Object} The new state that is the result of the reduction of the
101
- * specified action.
99
+ * @returns {Object} The value returned by {@code next(action)}.
102 100
  */
103
-function _connectionEstablished(store, next, action) {
101
+function _connectionEstablished({ dispatch }, next, action) {
104 102
     const result = next(action);
105 103
 
106 104
     // FIXME: workaround for the web version. Currently the creation of the
107 105
     // conference is handled by /conference.js
108 106
     if (typeof APP === 'undefined') {
109
-        store.dispatch(createConference());
107
+        dispatch(createConference());
110 108
     }
111 109
 
112 110
     return result;
@@ -123,8 +121,7 @@ function _connectionEstablished(store, next, action) {
123 121
  * @param {Action} action - The redux action {@link CONFERENCE_FAILED} or
124 122
  * {@link CONFERENCE_LEFT} which is being dispatched in the specified store.
125 123
  * @private
126
- * @returns {Object} The new state that is the result of the reduction of the
127
- * specified action.
124
+ * @returns {Object} The value returned by {@code next(action)}.
128 125
  */
129 126
 function _conferenceFailedOrLeft({ dispatch, getState }, next, action) {
130 127
     const result = next(action);
@@ -149,20 +146,17 @@ function _conferenceFailedOrLeft({ dispatch, getState }, next, action) {
149 146
  * @param {Action} action - The redux action CONFERENCE_JOINED which is being
150 147
  * dispatched in the specified store.
151 148
  * @private
152
- * @returns {Object} The new state that is the result of the reduction of the
153
- * specified action.
149
+ * @returns {Object} The value returned by {@code next(action)}.
154 150
  */
155
-function _conferenceJoined(store, next, action) {
151
+function _conferenceJoined({ dispatch, getState }, next, action) {
156 152
     const result = next(action);
157
-    const { audioOnly, conference }
158
-        = store.getState()['features/base/conference'];
153
+
154
+    const { audioOnly, conference } = getState()['features/base/conference'];
159 155
 
160 156
     // FIXME On Web the audio only mode for "start audio only" is toggled before
161 157
     // conference is added to the redux store ("on conference joined" action)
162 158
     // and the LastN value needs to be synchronized here.
163
-    if (audioOnly && conference.getLastN() !== 0) {
164
-        store.dispatch(setLastN(0));
165
-    }
159
+    audioOnly && (conference.getLastN() !== 0) && dispatch(setLastN(0));
166 160
 
167 161
     return result;
168 162
 }
@@ -179,11 +173,10 @@ function _conferenceJoined(store, next, action) {
179 173
  * @param {Action} action - The redux action PIN_PARTICIPANT which is being
180 174
  * dispatched in the specified store.
181 175
  * @private
182
- * @returns {Object} The new state that is the result of the reduction of the
183
- * specified action.
176
+ * @returns {Object} The value returned by {@code next(action)}.
184 177
  */
185
-function _pinParticipant(store, next, action) {
186
-    const state = store.getState();
178
+function _pinParticipant({ getState }, next, action) {
179
+    const state = getState();
187 180
     const { conference } = state['features/base/conference'];
188 181
 
189 182
     if (!conference) {
@@ -248,8 +241,7 @@ function _pinParticipant(store, next, action) {
248 241
  * @param {Action} action - The redux action SET_AUDIO_ONLY which is being
249 242
  * dispatched in the specified store.
250 243
  * @private
251
- * @returns {Object} The new state that is the result of the reduction of the
252
- * specified action.
244
+ * @returns {Object} The value returned by {@code next(action)}.
253 245
  */
254 246
 function _setAudioOnly({ dispatch, getState }, next, action) {
255 247
     const result = next(action);
@@ -286,11 +278,10 @@ function _setAudioOnly({ dispatch, getState }, next, action) {
286 278
  * @param {Action} action - The redux action SET_LASTN which is being dispatched
287 279
  * in the specified store.
288 280
  * @private
289
- * @returns {Object} The new state that is the result of the reduction of the
290
- * specified action.
281
+ * @returns {Object} The value returned by {@code next(action)}.
291 282
  */
292
-function _setLastN(store, next, action) {
293
-    const { conference } = store.getState()['features/base/conference'];
283
+function _setLastN({ getState }, next, action) {
284
+    const { conference } = getState()['features/base/conference'];
294 285
 
295 286
     if (conference) {
296 287
         try {
@@ -307,24 +298,21 @@ function _setLastN(store, next, action) {
307 298
  * Sets the maximum receive video quality and will turn off audio only mode if
308 299
  * enabled.
309 300
  *
310
- * @param {Store} store - The Redux store in which the specified action is being
301
+ * @param {Store} store - The redux store in which the specified action is being
311 302
  * dispatched.
312
- * @param {Dispatch} next - The Redux dispatch function to dispatch the
303
+ * @param {Dispatch} next - The redux dispatch function to dispatch the
313 304
  * specified action to the specified store.
314
- * @param {Action} action - The Redux action SET_RECEIVE_VIDEO_QUALITY which is
305
+ * @param {Action} action - The redux action SET_RECEIVE_VIDEO_QUALITY which is
315 306
  * being dispatched in the specified store.
316 307
  * @private
317
- * @returns {Object} The new state that is the result of the reduction of the
318
- * specified action.
308
+ * @returns {Object} The value returned by {@code next(action)}.
319 309
  */
320 310
 function _setReceiveVideoQuality({ dispatch, getState }, next, action) {
321 311
     const { audioOnly, conference } = getState()['features/base/conference'];
322 312
 
323 313
     if (conference) {
324 314
         conference.setReceiverVideoConstraint(action.receiveVideoQuality);
325
-        if (audioOnly) {
326
-            dispatch(toggleAudioOnly());
327
-        }
315
+        audioOnly && dispatch(toggleAudioOnly());
328 316
     }
329 317
 
330 318
     return next(action);
@@ -362,15 +350,14 @@ function _syncConferenceLocalTracksWithState({ getState }, action) {
362 350
 /**
363 351
  * Sets the maximum receive video quality.
364 352
  *
365
- * @param {Store} store - The Redux store in which the specified action is being
353
+ * @param {Store} store - The redux store in which the specified action is being
366 354
  * dispatched.
367
- * @param {Dispatch} next - The Redux dispatch function to dispatch the
355
+ * @param {Dispatch} next - The redux dispatch function to dispatch the
368 356
  * specified action to the specified store.
369
- * @param {Action} action - The Redux action DATA_CHANNEL_STATUS_CHANGED which
357
+ * @param {Action} action - The redux action DATA_CHANNEL_STATUS_CHANGED which
370 358
  * is being dispatched in the specified store.
371 359
  * @private
372
- * @returns {Object} The new state that is the result of the reduction of the
373
- * specified action.
360
+ * @returns {Object} The value returned by {@code next(action)}.
374 361
  */
375 362
 function _syncReceiveVideoQuality({ getState }, next, action) {
376 363
     const state = getState()['features/base/conference'];
@@ -391,8 +378,7 @@ function _syncReceiveVideoQuality({ getState }, next, action) {
391 378
  * @param {Action} action - The redux action TRACK_ADDED or TRACK_REMOVED which
392 379
  * is being dispatched in the specified store.
393 380
  * @private
394
- * @returns {Object} The new state that is the result of the reduction of the
395
- * specified action.
381
+ * @returns {Object} The value returned by {@code next(action)}.
396 382
  */
397 383
 function _trackAddedOrRemoved(store, next, action) {
398 384
     const track = action.track;

+ 78
- 34
react/features/filmstrip/middleware.js 查看文件

@@ -4,51 +4,95 @@ import { setLastN } from '../base/conference';
4 4
 import { SET_CALLEE_INFO_VISIBLE } from '../base/jwt';
5 5
 import { pinParticipant } from '../base/participants';
6 6
 import { MiddlewareRegistry } from '../base/redux';
7
-
8 7
 import Filmstrip from '../../../modules/UI/videolayout/Filmstrip';
9 8
 
10 9
 import { SET_FILMSTRIP_ENABLED } from './actionTypes';
11 10
 
12 11
 declare var APP: Object;
13 12
 
14
-MiddlewareRegistry.register(({ dispatch, getState }) => next => action => {
13
+MiddlewareRegistry.register(store => next => action => {
15 14
     switch (action.type) {
16 15
     case SET_CALLEE_INFO_VISIBLE:
17
-        if (typeof APP !== 'undefined') {
18
-            const oldValue
19
-                = Boolean(getState()['features/base/jwt'].calleeInfoVisible);
20
-            const result = next(action);
21
-            const newValue
22
-                = Boolean(getState()['features/base/jwt'].calleeInfoVisible);
23
-
24
-            oldValue === newValue
25
-
26
-                // FIXME The following accesses the private state filmstrip of
27
-                // Filmstrip. It is written with the understanding that
28
-                // Filmstrip will be rewritten in React and, consequently, will
29
-                // not need the middleware implemented here, Filmstrip.init, and
30
-                // UI.start.
31
-                || (Filmstrip.filmstrip
32
-                    && Filmstrip.toggleFilmstrip(!newValue));
33
-
34
-            return result;
35
-        }
36
-        break;
16
+        return _setCalleeInfoVisible(store, next, action);
37 17
 
38 18
     case SET_FILMSTRIP_ENABLED:
39
-        // FIXME: Only do this on mobile for now. The logic for participant
40
-        // pinning / unpinning is not on React yet so dispatching the action
41
-        // is not enough.
42
-        if (typeof APP === 'undefined') {
43
-            const { audioOnly } = getState()['features/base/conference'];
44
-            const { enabled } = action;
45
-
46
-            !enabled && dispatch(pinParticipant(null));
47
-            !audioOnly && dispatch(setLastN(enabled ? undefined : 1));
48
-        }
49
-        break;
50
-
19
+        return _setFilmstripEnabled(store, next, action);
51 20
     }
52 21
 
53 22
     return next(action);
54 23
 });
24
+
25
+/**
26
+ * Notifies the feature filmstrip that the action
27
+ * {@link SET_CALLEE_INFO_VISIBLE} is being dispatched within a specific redux
28
+ * store.
29
+ *
30
+ * @param {Store} store - The redux store in which the specified action is being
31
+ * dispatched.
32
+ * @param {Dispatch} next - The redux dispatch function to dispatch the
33
+ * specified action to the specified store.
34
+ * @param {Action} action - The redux action {@code SET_CALLEE_INFO_VISIBLE}
35
+ * which is being dispatched in the specified store.
36
+ * @private
37
+ * @returns {Object} The value returned by {@code next(action)}.
38
+ */
39
+function _setCalleeInfoVisible({ getState }, next, action) {
40
+    if (typeof APP !== 'undefined') {
41
+        const oldValue
42
+            = Boolean(getState()['features/base/jwt'].calleeInfoVisible);
43
+        const result = next(action);
44
+        const newValue
45
+            = Boolean(getState()['features/base/jwt'].calleeInfoVisible);
46
+
47
+        oldValue === newValue
48
+
49
+            // FIXME The following accesses the private state filmstrip of
50
+            // Filmstrip. It is written with the understanding that Filmstrip
51
+            // will be rewritten in React and, consequently, will not need the
52
+            // middleware implemented here, Filmstrip.init, and UI.start.
53
+            || (Filmstrip.filmstrip && Filmstrip.toggleFilmstrip(!newValue));
54
+
55
+        return result;
56
+    }
57
+
58
+    return next(action);
59
+}
60
+
61
+/**
62
+ * Notifies the feature filmstrip that the action {@link SET_FILMSTRIP_ENABLED}
63
+ * is being dispatched within a specific redux store.
64
+ *
65
+ * @param {Store} store - The redux store in which the specified action is being
66
+ * dispatched.
67
+ * @param {Dispatch} next - The redux dispatch function to dispatch the
68
+ * specified action to the specified store.
69
+ * @param {Action} action - The redux action {@code SET_FILMSTRIP_ENABLED} which
70
+ * is being dispatched in the specified store.
71
+ * @private
72
+ * @returns {Object} The value returned by {@code next(action)}.
73
+ */
74
+function _setFilmstripEnabled({ dispatch, getState }, next, action) {
75
+    const result = next(action);
76
+
77
+    // FIXME The logic for participant pinning / unpinning is not on React yet
78
+    // so dispatching the action is not enough. Hence, perform the following
79
+    // only where it will be sufficient i.e. mobile.
80
+    if (typeof APP === 'undefined') {
81
+        const state = getState();
82
+        const { enabled } = state['features/filmstrip'];
83
+        const { audioOnly } = state['features/base/conference'];
84
+
85
+        enabled || dispatch(pinParticipant(null));
86
+
87
+        // FIXME Audio-only mode fiddles with lastN as well. That's why we don't
88
+        // touch lastN in audio-only mode. But it's not clear what the value of
89
+        // lastN should be upon exit from audio-only mode if the filmstrip is
90
+        // disabled already. Currently, audio-only mode will set undefined
91
+        // regardless of whether the filmstrip is disabled. But we don't have a
92
+        // practical use case in which audio-only mode is exited while the
93
+        // filmstrip is disabled.
94
+        audioOnly || dispatch(setLastN(enabled ? undefined : 1));
95
+    }
96
+
97
+    return result;
98
+}

正在加载...
取消
保存