Parcourir la source

lastn: simplify computing the effective last N value

master
Saúl Ibarra Corretgé il y a 5 ans
Parent
révision
bf50a110c7

+ 0
- 11
react/features/base/lastn/actionTypes.js Voir le fichier

@@ -1,11 +0,0 @@
1
-// @flow
2
-
3
-/**
4
- * The type of (redux) action which sets the video channel's lastN (value).
5
- *
6
- * {
7
- *     type: SET_LASTN,
8
- *     lastN: number
9
- * }
10
- */
11
-export const SET_LASTN = 'SET_LASTN';

+ 0
- 34
react/features/base/lastn/actions.js Voir le fichier

@@ -1,34 +0,0 @@
1
-// @flow
2
-
3
-import { SET_LASTN } from './actionTypes';
4
-
5
-import type { Dispatch } from 'redux';
6
-
7
-/**
8
- * Sets the video channel's last N (value) of the current conference. A value of
9
- * undefined shall be used to reset it to the default value.
10
- *
11
- * @param {(number|undefined)} lastN - The last N value to be set.
12
- * @returns {Function}
13
- */
14
-export function setLastN(lastN: ?number) {
15
-    return (dispatch: Dispatch<any>, getState: Function) => {
16
-        if (typeof lastN === 'undefined') {
17
-            const config = getState()['features/base/config'];
18
-
19
-            /* eslint-disable no-param-reassign */
20
-
21
-            lastN = config.channelLastN;
22
-            if (typeof lastN === 'undefined') {
23
-                lastN = -1;
24
-            }
25
-
26
-            /* eslint-enable no-param-reassign */
27
-        }
28
-
29
-        dispatch({
30
-            type: SET_LASTN,
31
-            lastN
32
-        });
33
-    };
34
-}

+ 0
- 3
react/features/base/lastn/index.js Voir le fichier

@@ -1,6 +1,3 @@
1 1
 // @flow
2 2
 
3
-export * from './actions';
4
-export * from './actionTypes';
5
-
6 3
 import './middleware';

+ 31
- 123
react/features/base/lastn/middleware.js Voir le fichier

@@ -9,152 +9,60 @@ import { SET_AUDIO_ONLY } from '../audio-only';
9 9
 import { CONFERENCE_JOINED } from '../conference/actionTypes';
10 10
 import { MiddlewareRegistry } from '../redux';
11 11
 
12
-import { setLastN } from './actions';
13
-import { SET_LASTN } from './actionTypes';
14
-
15 12
 declare var APP: Object;
16
-
17 13
 const logger = getLogger('features/base/lastn');
18 14
 
19 15
 
20 16
 MiddlewareRegistry.register(store => next => action => {
17
+    const result = next(action);
18
+
21 19
     switch (action.type) {
22 20
     case APP_STATE_CHANGED:
23
-        return _appStateChanged(store, next, action);
24
-
25 21
     case CONFERENCE_JOINED:
26
-        return _conferenceJoined(store, next, action);
27
-
28 22
     case SET_AUDIO_ONLY:
29
-        return _setAudioOnly(store, next, action);
30
-
31 23
     case SET_FILMSTRIP_ENABLED:
32
-        return _setFilmstripEnabled(store, next, action);
33
-
34
-    case SET_LASTN:
35
-        return _setLastN(store, next, action);
24
+        _updateLastN(store);
25
+        break;
36 26
     }
37 27
 
38
-    return next(action);
28
+    return result;
39 29
 });
40 30
 
41 31
 /**
42
- * Adjusts the lasN value based on the app state.
32
+ * Updates the last N value in the conference based on the current state of the redux store.
43 33
  *
44
- * @param {Store} store - The redux store in which the specified {@code action}
45
- * is being dispatched.
46
- * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
47
- * specified {@code action} to the specified {@code store}.
48
- * @param {Action} action - The redux action {@code APP_STATE_CHANGED} which is
49
- * being dispatched in the specified {@code store}.
34
+ * @param {Store} store - The redux store.
50 35
  * @private
51
- * @returns {Object} The value returned by {@code next(action)}.
36
+ * @returns {void}
52 37
  */
53
-function _appStateChanged({ dispatch, getState }, next, action) {
54
-    const { enabled: audioOnly } = getState()['features/base/audio-only'];
55
-
56
-    if (!audioOnly) {
57
-        const { appState } = action;
58
-        const lastN = appState === 'active' ? undefined : 0;
59
-
60
-        dispatch(setLastN(lastN));
61
-        logger.log(`App state changed - updated lastN to ${String(lastN)}`);
38
+function _updateLastN({ getState }) {
39
+    const state = getState();
40
+    const { conference } = state['features/base/conference'];
41
+    const { enabled: audioOnly } = state['features/base/audio-only'];
42
+    const { appState } = state['features/background'];
43
+    const { enabled: filmStripEnabled } = state['features/filmstrip'];
44
+    const config = state['features/base/config'];
45
+
46
+    if (!conference) {
47
+        logger.debug('There is no active conference, not updating last N');
48
+
49
+        return;
62 50
     }
63 51
 
64
-    return next(action);
65
-}
66
-
67
-/**
68
- * Adjusts the lasN value upon joining a conference.
69
- *
70
- * @param {Store} store - The redux store in which the specified {@code action}
71
- * is being dispatched.
72
- * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
73
- * specified {@code action} to the specified {@code store}.
74
- * @param {Action} action - The redux action {@code CONFERENCE_JOINED} which is
75
- * being dispatched in the specified {@code store}.
76
- * @private
77
- * @returns {Object} The value returned by {@code next(action)}.
78
- */
79
-function _conferenceJoined({ dispatch, getState }, next, action) {
80
-    const { conference } = action;
81
-    const { enabled: audioOnly } = getState()['features/base/audio-only'];
82
-
83
-    audioOnly && conference.getLastN() !== 0 && dispatch(setLastN(0));
84
-
85
-    return next(action);
86
-}
87
-
88
-/**
89
- * Sets the audio-only flag for the current conference. When audio-only is set,
90
- * local video is muted and last N is set to 0 to avoid receiving remote video.
91
- *
92
- * @param {Store} store - The redux store in which the specified {@code action}
93
- * is being dispatched.
94
- * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
95
- * specified {@code action} to the specified {@code store}.
96
- * @param {Action} action - The redux action {@code SET_AUDIO_ONLY} which is
97
- * being dispatched in the specified {@code store}.
98
- * @private
99
- * @returns {Object} The value returned by {@code next(action)}.
100
- */
101
-function _setAudioOnly({ dispatch }, next, action) {
102
-    const { audioOnly } = action;
103
-
104
-    // Set lastN to 0 in case audio-only is desired; leave it as undefined,
105
-    // otherwise, and the default lastN value will be chosen automatically.
106
-    dispatch(setLastN(audioOnly ? 0 : undefined));
52
+    const defaultLastN = typeof config.channelLastN === 'undefined' ? -1 : config.channelLastN;
53
+    let lastN = defaultLastN;
107 54
 
108
-    return next(action);
109
-}
110
-
111
-/**
112
- * Notifies the feature filmstrip that the action {@link SET_FILMSTRIP_ENABLED}
113
- * is being dispatched within a specific redux store.
114
- *
115
- * @param {Store} store - The redux store in which the specified action is being
116
- * dispatched.
117
- * @param {Dispatch} next - The redux dispatch function to dispatch the
118
- * specified action to the specified store.
119
- * @param {Action} action - The redux action {@code SET_FILMSTRIP_ENABLED} which
120
- * is being dispatched in the specified store.
121
- * @private
122
- * @returns {Object} The value returned by {@code next(action)}.
123
- */
124
-function _setFilmstripEnabled({ dispatch, getState }, next, action) {
125
-    // FIXME This action is not currently dispatched on web.
126
-    if (typeof APP === 'undefined') {
127
-        const { enabled } = action;
128
-        const { enabled: audioOnly } = getState()['features/base/audio-only'];
129
-
130
-        audioOnly || dispatch(setLastN(enabled ? undefined : 1));
55
+    if (audioOnly || appState !== 'active') {
56
+        lastN = 0;
57
+    } else if (!filmStripEnabled) {
58
+        lastN = 1;
131 59
     }
132 60
 
133
-    return next(action);
134
-}
61
+    logger.info(`Setting last N to: ${lastN}`);
135 62
 
136
-/**
137
- * Sets the last N (value) of the video channel in the conference.
138
- *
139
- * @param {Store} store - The redux store in which the specified {@code action}
140
- * is being dispatched.
141
- * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
142
- * specified {@code action} to the specified {@code store}.
143
- * @param {Action} action - The redux action {@code SET_LASTN} which is being
144
- * dispatched in the specified {@code store}.
145
- * @private
146
- * @returns {Object} The value returned by {@code next(action)}.
147
- */
148
-function _setLastN({ getState }, next, action) {
149
-    const { conference } = getState()['features/base/conference'];
150
-
151
-    if (conference) {
152
-        try {
153
-            conference.setLastN(action.lastN);
154
-        } catch (err) {
155
-            logger.error(`Failed to set lastN: ${err}`);
156
-        }
63
+    try {
64
+        conference.setLastN(lastN);
65
+    } catch (err) {
66
+        logger.error(`Failed to set lastN: ${err}`);
157 67
     }
158
-
159
-    return next(action);
160 68
 }

Chargement…
Annuler
Enregistrer