Parcourir la source

Reduce the complexity of the source code

j8
Lyubomir Marinov il y a 8 ans
Parent
révision
02e3f6b3a2

+ 25
- 30
react/features/base/conference/actions.js Voir le fichier

@@ -6,10 +6,7 @@ import {
6 6
     participantLeft,
7 7
     participantRoleChanged
8 8
 } from '../participants';
9
-import {
10
-    trackAdded,
11
-    trackRemoved
12
-} from '../tracks';
9
+import { trackAdded, trackRemoved } from '../tracks';
13 10
 
14 11
 import {
15 12
     CONFERENCE_JOINED,
@@ -46,7 +43,7 @@ export function createConference() {
46 43
         const conference
47 44
             = connection.initJitsiConference(room, { openSctp: true });
48 45
 
49
-        dispatch(_setupConferenceListeners(conference));
46
+        _setupConferenceListeners(conference, dispatch);
50 47
 
51 48
         conference.join();
52 49
     };
@@ -60,11 +57,12 @@ export function createConference() {
60 57
  * joined by the local participant.
61 58
  * @returns {Function}
62 59
  */
63
-export function conferenceJoined(conference) {
60
+function _conferenceJoined(conference) {
64 61
     return (dispatch, getState) => {
65
-        const localTracks = getState()['features/base/tracks']
66
-            .filter(t => t.local)
67
-            .map(t => t.jitsiTrack);
62
+        const localTracks
63
+            = getState()['features/base/tracks']
64
+                .filter(t => t.local)
65
+                .map(t => t.jitsiTrack);
68 66
 
69 67
         if (localTracks.length) {
70 68
             _addLocalTracksToConference(conference, localTracks);
@@ -91,7 +89,7 @@ export function conferenceJoined(conference) {
91 89
  *      }
92 90
  *  }}
93 91
  */
94
-export function conferenceLeft(conference) {
92
+function _conferenceLeft(conference) {
95 93
     return {
96 94
         type: CONFERENCE_LEFT,
97 95
         conference: {
@@ -144,48 +142,45 @@ export function setRoom(room) {
144 142
 /**
145 143
  * Setup various conference event handlers.
146 144
  *
147
- * @param {JitsiConference} conference - Conference instance.
145
+ * @param {JitsiConference} conference - The JitsiConference instance.
146
+ * @param {Dispatch} dispatch - The Redux dispatch function.
148 147
  * @private
149
- * @returns {Function}
148
+ * @returns {void}
150 149
  */
151
-function _setupConferenceListeners(conference) {
152
-    return dispatch => {
153
-        conference.on(
150
+function _setupConferenceListeners(conference, dispatch) {
151
+    conference.on(
154 152
             JitsiConferenceEvents.CONFERENCE_JOINED,
155
-            () => dispatch(conferenceJoined(conference)));
156
-        conference.on(
153
+            () => dispatch(_conferenceJoined(conference)));
154
+    conference.on(
157 155
             JitsiConferenceEvents.CONFERENCE_LEFT,
158
-            () => dispatch(conferenceLeft(conference)));
156
+            () => dispatch(_conferenceLeft(conference)));
159 157
 
160
-        conference.on(
158
+    conference.on(
161 159
             JitsiConferenceEvents.DOMINANT_SPEAKER_CHANGED,
162 160
             id => dispatch(dominantSpeakerChanged(id)));
163 161
 
164
-        conference.on(
162
+    conference.on(
165 163
             JitsiConferenceEvents.TRACK_ADDED,
166
-            track =>
167
-                track && !track.isLocal() && dispatch(trackAdded(track)));
168
-        conference.on(
164
+            t => t && !t.isLocal() && dispatch(trackAdded(t)));
165
+    conference.on(
169 166
             JitsiConferenceEvents.TRACK_REMOVED,
170
-            track =>
171
-                track && !track.isLocal() && dispatch(trackRemoved(track)));
167
+            t => t && !t.isLocal() && dispatch(trackRemoved(t)));
172 168
 
173
-        conference.on(
169
+    conference.on(
174 170
             JitsiConferenceEvents.USER_JOINED,
175 171
             (id, user) => dispatch(participantJoined({
176 172
                 id,
177 173
                 name: user.getDisplayName(),
178 174
                 role: user.getRole()
179 175
             })));
180
-        conference.on(
176
+    conference.on(
181 177
             JitsiConferenceEvents.USER_LEFT,
182 178
             id => dispatch(participantLeft(id)));
183
-        conference.on(
179
+    conference.on(
184 180
             JitsiConferenceEvents.USER_ROLE_CHANGED,
185 181
             (id, role) => dispatch(participantRoleChanged(id, role)));
186 182
 
187
-        conference.addCommandListener(
183
+    conference.addCommandListener(
188 184
             EMAIL_COMMAND,
189 185
             (data, id) => dispatch(changeParticipantEmail(id, data.value)));
190
-    };
191 186
 }

+ 78
- 26
react/features/base/conference/middleware.js Voir le fichier

@@ -1,14 +1,13 @@
1
+import { CONNECTION_ESTABLISHED } from '../connection';
1 2
 import {
2 3
     getLocalParticipant,
3 4
     getParticipantById,
4 5
     PIN_PARTICIPANT
5 6
 } from '../participants';
6 7
 import { MiddlewareRegistry } from '../redux';
7
-import {
8
-    TRACK_ADDED,
9
-    TRACK_REMOVED
10
-} from '../tracks';
8
+import { TRACK_ADDED, TRACK_REMOVED } from '../tracks';
11 9
 
10
+import { createConference } from './actions';
12 11
 import {
13 12
     _addLocalTracksToConference,
14 13
     _handleParticipantError,
@@ -16,45 +15,68 @@ import {
16 15
 } from './functions';
17 16
 
18 17
 /**
19
- * This middleware intercepts TRACK_ADDED and TRACK_REMOVED actions to sync
20
- * conference's local tracks with local tracks in state. Also captures
21
- * PIN_PARTICIPANT action to pin participant in conference.
18
+ * Implements the middleware of the feature base/conference.
22 19
  *
23 20
  * @param {Store} store - Redux store.
24 21
  * @returns {Function}
25 22
  */
26 23
 MiddlewareRegistry.register(store => next => action => {
27 24
     switch (action.type) {
25
+    case CONNECTION_ESTABLISHED:
26
+        return _connectionEstablished(store, next, action);
27
+
28 28
     case PIN_PARTICIPANT:
29
-        pinParticipant(store, action.participant.id);
30
-        break;
29
+        return _pinParticipant(store, next, action);
31 30
 
32 31
     case TRACK_ADDED:
33
-    case TRACK_REMOVED: {
34
-        const track = action.track;
35
-
36
-        if (track && track.local) {
37
-            return syncConferenceLocalTracksWithState(store, action)
38
-                .then(() => next(action));
39
-        }
40
-        break;
41
-    }
32
+    case TRACK_REMOVED:
33
+        return _trackAddedOrRemoved(store, next, action);
42 34
     }
43 35
 
44 36
     return next(action);
45 37
 });
46 38
 
47 39
 /**
48
- * Pins remote participant in conference, ignores local participant.
40
+ * Notifies the feature base/conference that the action CONNECTION_ESTABLISHED
41
+ * is being dispatched within a specific Redux store.
49 42
  *
50
- * @param {Store} store - Redux store.
51
- * @param {string|null} id - Participant id or null if no one is currently
52
- * pinned.
53
- * @returns {void}
43
+ * @param {Store} store - The Redux store in which the specified action is being
44
+ * dispatched.
45
+ * @param {Dispatch} next - The Redux dispatch function to dispatch the
46
+ * specified action to the specified store.
47
+ * @param {Action} action - The Redux action CONNECTION_ESTABLISHED which is
48
+ * being dispatched in the specified store.
49
+ * @private
50
+ * @returns {Object} The new state that is the result of the reduction of the
51
+ * specified action.
52
+ */
53
+function _connectionEstablished(store, next, action) {
54
+    const result = next(action);
55
+
56
+    store.dispatch(createConference());
57
+
58
+    return result;
59
+}
60
+
61
+/**
62
+ * Notifies the feature base/conference that the action PIN_PARTICIPANT is being
63
+ * dispatched within a specific Redux store. Pins the specified remote
64
+ * participant in the associated conference, ignores the local participant.
65
+ *
66
+ * @param {Store} store - The Redux store in which the specified action is being
67
+ * dispatched.
68
+ * @param {Dispatch} next - The Redux dispatch function to dispatch the
69
+ * specified action to the specified store.
70
+ * @param {Action} action - The Redux action PIN_PARTICIPANT which is being
71
+ * dispatched in the specified store.
72
+ * @private
73
+ * @returns {Object} The new state that is the result of the reduction of the
74
+ * specified action.
54 75
  */
55
-function pinParticipant(store, id) {
76
+function _pinParticipant(store, next, action) {
56 77
     const state = store.getState();
57 78
     const participants = state['features/base/participants'];
79
+    const id = action.participant.id;
58 80
     const participantById = getParticipantById(participants, id);
59 81
     let pin;
60 82
 
@@ -81,16 +103,46 @@ function pinParticipant(store, id) {
81 103
             _handleParticipantError(err);
82 104
         }
83 105
     }
106
+
107
+    return next(action);
108
+}
109
+
110
+/**
111
+ * Notifies the feature base/conference that the action TRACK_ADDED
112
+ * or TRACK_REMOVED is being dispatched within a specific Redux store.
113
+ *
114
+ * @param {Store} store - The Redux store in which the specified action is being
115
+ * dispatched.
116
+ * @param {Dispatch} next - The Redux dispatch function to dispatch the
117
+ * specified action to the specified store.
118
+ * @param {Action} action - The Redux action TRACK_ADDED or TRACK_REMOVED which
119
+ * is being dispatched in the specified store.
120
+ * @private
121
+ * @returns {Object} The new state that is the result of the reduction of the
122
+ * specified action.
123
+ */
124
+function _trackAddedOrRemoved(store, next, action) {
125
+    const track = action.track;
126
+
127
+    if (track && track.local) {
128
+        return (
129
+            _syncConferenceLocalTracksWithState(store, action)
130
+                .then(() => next(action)));
131
+    }
132
+
133
+    return next(action);
84 134
 }
85 135
 
86 136
 /**
87
- * Syncs local tracks from state with local tracks in JitsiConference instance.
137
+ * Synchronizes local tracks from state with local tracks in JitsiConference
138
+ * instance.
88 139
  *
89 140
  * @param {Store} store - Redux store.
90 141
  * @param {Object} action - Action object.
142
+ * @private
91 143
  * @returns {Promise}
92 144
  */
93
-function syncConferenceLocalTracksWithState(store, action) {
145
+function _syncConferenceLocalTracksWithState(store, action) {
94 146
     const conferenceState = store.getState()['features/base/conference'];
95 147
     const conference = conferenceState.jitsiConference;
96 148
     const leavingConference = conferenceState.leavingJitsiConference;

+ 14
- 19
react/features/base/conference/reducer.js Voir le fichier

@@ -1,4 +1,4 @@
1
-import { ReducerRegistry } from '../redux';
1
+import { ReducerRegistry, setStateProperty } from '../redux';
2 2
 
3 3
 import {
4 4
     CONFERENCE_JOINED,
@@ -33,10 +33,11 @@ ReducerRegistry.register('features/base/conference',
33 33
     (state = INITIAL_STATE, action) => {
34 34
         switch (action.type) {
35 35
         case CONFERENCE_JOINED:
36
-            return {
37
-                ...state,
38
-                jitsiConference: action.conference.jitsiConference
39
-            };
36
+            return (
37
+                setStateProperty(
38
+                        state,
39
+                        'jitsiConference',
40
+                        action.conference.jitsiConference));
40 41
 
41 42
         case CONFERENCE_LEFT:
42 43
             if (state.jitsiConference === action.conference.jitsiConference) {
@@ -52,10 +53,11 @@ ReducerRegistry.register('features/base/conference',
52 53
             break;
53 54
 
54 55
         case CONFERENCE_WILL_LEAVE:
55
-            return {
56
-                ...state,
57
-                leavingJitsiConference: action.conference.jitsiConference
58
-            };
56
+            return (
57
+                setStateProperty(
58
+                        state,
59
+                        'leavingJitsiConference',
60
+                        action.conference.jitsiConference));
59 61
 
60 62
         case SET_ROOM: {
61 63
             let room = action.room;
@@ -63,16 +65,9 @@ ReducerRegistry.register('features/base/conference',
63 65
             // Technically, there're multiple values which don't represent
64 66
             // valid room names. Practically, each of them is as bad as the rest
65 67
             // of them because we can't use any of them to join a conference.
66
-            if (!isRoomValid(room)) {
67
-                room = INITIAL_STATE.room;
68
-            }
69
-            if (state.room !== room) {
70
-                return {
71
-                    ...state,
72
-                    room
73
-                };
74
-            }
75
-            break;
68
+            isRoomValid(room) || (room = INITIAL_STATE.room);
69
+
70
+            return setStateProperty(state, 'room', room);
76 71
         }
77 72
         }
78 73
 

+ 84
- 86
react/features/base/connection/actions.js Voir le fichier

@@ -1,8 +1,6 @@
1
-import {
2
-    conferenceWillLeave,
3
-    createConference
4
-} from '../conference';
1
+import { conferenceWillLeave } from '../conference';
5 2
 import JitsiMeetJS from '../lib-jitsi-meet';
3
+
6 4
 import {
7 5
     CONNECTION_DISCONNECTED,
8 6
     CONNECTION_ESTABLISHED,
@@ -21,90 +19,81 @@ const JitsiConnectionEvents = JitsiMeetJS.events.connection;
21 19
 export function connect() {
22 20
     return (dispatch, getState) => {
23 21
         const state = getState();
24
-        const connectionOpts
22
+        const connectionOptions
25 23
             = state['features/base/connection'].connectionOptions;
26 24
         const room = state['features/base/conference'].room;
27
-        const connection = new JitsiMeetJS.JitsiConnection(
28
-            connectionOpts.appId,
29
-            connectionOpts.token,
30
-            {
31
-                ...connectionOpts,
32
-                bosh: connectionOpts.bosh + (
33
-                    room ? `?room=${room}` : ''
34
-                )
35
-            }
36
-        );
37
-
38
-        return new Promise((resolve, reject) => {
39
-            connection.addEventListener(
25
+        const connection
26
+            = new JitsiMeetJS.JitsiConnection(
27
+                connectionOptions.appId,
28
+                connectionOptions.token,
29
+                {
30
+                    ...connectionOptions,
31
+                    bosh: connectionOptions.bosh + (room ? `?room=${room}` : '')
32
+                });
33
+
34
+        connection.addEventListener(
40 35
                 JitsiConnectionEvents.CONNECTION_DISCONNECTED,
41
-                handleConnectionDisconnected);
42
-            connection.addEventListener(
36
+                connectionDisconnected);
37
+        connection.addEventListener(
43 38
                 JitsiConnectionEvents.CONNECTION_ESTABLISHED,
44
-                handleConnectionEstablished);
45
-            connection.addEventListener(
39
+                connectionEstablished);
40
+        connection.addEventListener(
46 41
                 JitsiConnectionEvents.CONNECTION_FAILED,
47
-                handleConnectionFailed);
48
-
49
-            connection.connect();
50
-
51
-            /**
52
-             * Dispatches CONNECTION_DISCONNECTED action when connection is
53
-             * disconnected.
54
-             *
55
-             * @param {string} message - Disconnect reason.
56
-             * @returns {void}
57
-             */
58
-            function handleConnectionDisconnected(message) {
59
-                connection.removeEventListener(
42
+                connectionFailed);
43
+
44
+        connection.connect();
45
+
46
+        /**
47
+         * Dispatches CONNECTION_DISCONNECTED action when connection is
48
+         * disconnected.
49
+         *
50
+         * @param {string} message - Disconnect reason.
51
+         * @returns {void}
52
+         */
53
+        function connectionDisconnected(message) {
54
+            connection.removeEventListener(
60 55
                     JitsiConnectionEvents.CONNECTION_DISCONNECTED,
61
-                    handleConnectionDisconnected);
62
-
63
-                dispatch(_connectionDisconnected(connection, message));
64
-            }
65
-
66
-            /**
67
-             * Resolves external promise when connection is established.
68
-             *
69
-             * @returns {void}
70
-             */
71
-            function handleConnectionEstablished() {
72
-                unsubscribe();
73
-                resolve(connection);
74
-            }
75
-
76
-            /**
77
-             * Rejects external promise when connection fails.
78
-             *
79
-             * @param {JitsiConnectionErrors} err - Connection error.
80
-             * @returns {void}
81
-             */
82
-            function handleConnectionFailed(err) {
83
-                unsubscribe();
84
-                console.error('CONNECTION FAILED:', err);
85
-                reject(err);
86
-            }
87
-
88
-            /**
89
-             * Unsubscribes connection instance from CONNECTION_ESTABLISHED
90
-             * and CONNECTION_FAILED events.
91
-             *
92
-             * @returns {void}
93
-             */
94
-            function unsubscribe() {
95
-                connection.removeEventListener(
56
+                    connectionDisconnected);
57
+
58
+            dispatch(_connectionDisconnected(connection, message));
59
+        }
60
+
61
+        /**
62
+         * Resolves external promise when connection is established.
63
+         *
64
+         * @returns {void}
65
+         */
66
+        function connectionEstablished() {
67
+            unsubscribe();
68
+            dispatch(_connectionEstablished(connection));
69
+        }
70
+
71
+        /**
72
+         * Rejects external promise when connection fails.
73
+         *
74
+         * @param {JitsiConnectionErrors} err - Connection error.
75
+         * @returns {void}
76
+         */
77
+        function connectionFailed(err) {
78
+            unsubscribe();
79
+            console.error('CONNECTION FAILED:', err);
80
+            dispatch(_connectionFailed(connection, err));
81
+        }
82
+
83
+        /**
84
+         * Unsubscribes connection instance from CONNECTION_ESTABLISHED
85
+         * and CONNECTION_FAILED events.
86
+         *
87
+         * @returns {void}
88
+         */
89
+        function unsubscribe() {
90
+            connection.removeEventListener(
96 91
                     JitsiConnectionEvents.CONNECTION_ESTABLISHED,
97
-                    handleConnectionEstablished
98
-                );
99
-                connection.removeEventListener(
92
+                    connectionEstablished);
93
+            connection.removeEventListener(
100 94
                     JitsiConnectionEvents.CONNECTION_FAILED,
101
-                    handleConnectionFailed
102
-                );
103
-            }
104
-        })
105
-        .catch(err => dispatch(_connectionFailed(err)))
106
-        .then(con => dispatch(_connectionEstablished(con)))
107
-        .then(() => dispatch(createConference()));
95
+                    connectionFailed);
96
+        }
108 97
     };
109 98
 }
110 99
 
@@ -162,8 +151,7 @@ export function setDomain(domain) {
162 151
 /**
163 152
  * Create an action for when the signaling connection has been lost.
164 153
  *
165
- * @param {JitsiConnection} connection - The JitsiConnection which was
166
- * disconnected.
154
+ * @param {JitsiConnection} connection - The JitsiConnection which disconnected.
167 155
  * @param {string} message - Error message.
168 156
  * @private
169 157
  * @returns {{
@@ -183,9 +171,13 @@ function _connectionDisconnected(connection, message) {
183 171
 /**
184 172
  * Create an action for when the signaling connection has been established.
185 173
  *
186
- * @param {JitsiConnection} connection - JitsiConnection instance.
174
+ * @param {JitsiConnection} connection - The JitsiConnection which was
175
+ * established.
187 176
  * @private
188
- * @returns {{type: CONNECTION_ESTABLISHED, connection: JitsiConnection}}
177
+ * @returns {{
178
+ *     type: CONNECTION_ESTABLISHED,
179
+ *     connection: JitsiConnection
180
+ * }}
189 181
  */
190 182
 function _connectionEstablished(connection) {
191 183
     return {
@@ -197,13 +189,19 @@ function _connectionEstablished(connection) {
197 189
 /**
198 190
  * Create an action for when the signaling connection could not be created.
199 191
  *
192
+ * @param {JitsiConnection} connection - The JitsiConnection which failed.
200 193
  * @param {string} error - Error message.
201 194
  * @private
202
- * @returns {{type: CONNECTION_FAILED, error: string}}
195
+ * @returns {{
196
+ *     type: CONNECTION_FAILED,
197
+ *     connection: JitsiConnection,
198
+ *     error: string
199
+ * }}
203 200
  */
204
-function _connectionFailed(error) {
201
+function _connectionFailed(connection, error) {
205 202
     return {
206 203
         type: CONNECTION_FAILED,
204
+        connection,
207 205
         error
208 206
     };
209 207
 }

+ 69
- 52
react/features/base/connection/reducer.js Voir le fichier

@@ -1,4 +1,4 @@
1
-import { ReducerRegistry } from '../redux';
1
+import { ReducerRegistry, setStateProperty } from '../redux';
2 2
 
3 3
 import {
4 4
     CONNECTION_DISCONNECTED,
@@ -7,62 +7,64 @@ import {
7 7
 } from './actionTypes';
8 8
 
9 9
 /**
10
- * Initial Redux state.
11
- *
12
- * @type {{
13
- *      jitsiConnection: (JitsiConnection|null),
14
- *      connectionOptions: Object
15
- *  }}
10
+ * Reduces the Redux actions of the feature base/connection.
16 11
  */
17
-const INITIAL_STATE = {
18
-    jitsiConnection: null,
19
-    connectionOptions: null
20
-};
12
+ReducerRegistry.register('features/base/connection', (state = {}, action) => {
13
+    switch (action.type) {
14
+    case CONNECTION_DISCONNECTED:
15
+        return _connectionDisconnected(state, action);
21 16
 
22
-/**
23
- * Listen for actions that contain the connection object, so that
24
- * it can be stored for use by other action creators.
25
- */
26
-ReducerRegistry.register('features/base/connection',
27
-    (state = INITIAL_STATE, action) => {
28
-        switch (action.type) {
29
-        case CONNECTION_DISCONNECTED:
30
-            if (state.jitsiConnection === action.connection) {
31
-                return {
32
-                    ...state,
33
-                    jitsiConnection: null
34
-                };
35
-            }
17
+    case CONNECTION_ESTABLISHED:
18
+        return _connectionEstablished(state, action);
36 19
 
37
-            return state;
20
+    case SET_DOMAIN:
21
+        return _setDomain(state, action);
22
+    }
38 23
 
39
-        case CONNECTION_ESTABLISHED:
40
-            return {
41
-                ...state,
42
-                jitsiConnection: action.connection
43
-            };
24
+    return state;
25
+});
44 26
 
45
-        case SET_DOMAIN:
46
-            return {
47
-                ...state,
48
-                connectionOptions: {
49
-                    ...state.connectionOptions,
50
-                    ...buildConnectionOptions(action.domain)
51
-                }
52
-            };
27
+/**
28
+ * Reduces a specific Redux action CONNECTION_DISCONNECTED of the feature
29
+ * base/connection.
30
+ *
31
+ * @param {Object} state - The Redux state of the feature base/connection.
32
+ * @param {Action} action - The Redux action CONNECTION_DISCONNECTED to reduce.
33
+ * @private
34
+ * @returns {Object} The new state of the feature base/connection after the
35
+ * reduction of the specified action.
36
+ */
37
+function _connectionDisconnected(state, action) {
38
+    if (state.jitsiConnection === action.connection) {
39
+        return setStateProperty(state, 'jitsiConnection', undefined);
40
+    }
53 41
 
54
-        default:
55
-            return state;
56
-        }
57
-    });
42
+    return state;
43
+}
44
+
45
+/**
46
+ * Reduces a specific Redux action CONNECTION_ESTABLISHED of the feature
47
+ * base/connection.
48
+ *
49
+ * @param {Object} state - The Redux state of the feature base/connection.
50
+ * @param {Action} action - The Redux action CONNECTION_ESTABLISHED to reduce.
51
+ * @private
52
+ * @returns {Object} The new state of the feature base/connection after the
53
+ * reduction of the specified action.
54
+ */
55
+function _connectionEstablished(state, action) {
56
+    return setStateProperty(state, 'jitsiConnection', action.connection);
57
+}
58 58
 
59 59
 /**
60
- * Builds connection options based on domain.
60
+ * Constructs options to be passed to the constructor of JitsiConnection based
61
+ * on a specific domain.
61 62
  *
62
- * @param {string} domain - Domain name.
63
+ * @param {string} domain - The domain with which the returned options are to be
64
+ * populated.
63 65
  * @returns {Object}
64 66
  */
65
-function buildConnectionOptions(domain) {
67
+function _constructConnectionOptions(domain) {
66 68
     // FIXME The HTTPS scheme for the BOSH URL works with meet.jit.si on both
67 69
     // mobile & Web. It also works with beta.meet.jit.si on Web. Unfortunately,
68 70
     // it doesn't work with beta.meet.jit.si on mobile. Temporarily, use the
@@ -79,15 +81,11 @@ function buildConnectionOptions(domain) {
79 81
                 boshProtocol = windowLocation.protocol;
80 82
             }
81 83
         }
82
-        if (!boshProtocol) {
83
-            boshProtocol = 'http:';
84
-        }
84
+        boshProtocol || (boshProtocol = 'http:');
85 85
     }
86 86
 
87 87
     // Default to the HTTPS scheme for the BOSH URL.
88
-    if (!boshProtocol) {
89
-        boshProtocol = 'https:';
90
-    }
88
+    boshProtocol || (boshProtocol = 'https:');
91 89
 
92 90
     return {
93 91
         bosh: `${boshProtocol}//${domain}/http-bind`,
@@ -98,3 +96,22 @@ function buildConnectionOptions(domain) {
98 96
         }
99 97
     };
100 98
 }
99
+
100
+/**
101
+ * Reduces a specific Redux action SET_DOMAIN of the feature base/connection.
102
+ *
103
+ * @param {Object} state - The Redux state of the feature base/connection.
104
+ * @param {Action} action - The Redux action SET_DOMAIN to reduce.
105
+ * @private
106
+ * @returns {Object} The new state of the feature base/connection after the
107
+ * reduction of the specified action.
108
+ */
109
+function _setDomain(state, action) {
110
+    return {
111
+        ...state,
112
+        connectionOptions: {
113
+            ...state.connectionOptions,
114
+            ..._constructConnectionOptions(action.domain)
115
+        }
116
+    };
117
+}

+ 3
- 30
react/features/base/participants/reducer.js Voir le fichier

@@ -1,6 +1,6 @@
1 1
 /* global MD5 */
2 2
 
3
-import { ReducerRegistry } from '../redux';
3
+import { ReducerRegistry, setStateProperty } from '../redux';
4 4
 
5 5
 import {
6 6
     DOMINANT_SPEAKER_CHANGED,
@@ -55,7 +55,7 @@ function participant(state, action) {
55 55
     case DOMINANT_SPEAKER_CHANGED:
56 56
         // Only one dominant speaker is allowed.
57 57
         return (
58
-            _setStateProperty(
58
+            setStateProperty(
59 59
                     state,
60 60
                     'dominantSpeaker',
61 61
                     state.id === action.participant.id));
@@ -123,7 +123,7 @@ function participant(state, action) {
123 123
     case PIN_PARTICIPANT:
124 124
         // Currently, only one pinned participant is allowed.
125 125
         return (
126
-            _setStateProperty(
126
+            setStateProperty(
127 127
                     state,
128 128
                     'pinned',
129 129
                     state.id === action.participant.id));
@@ -201,30 +201,3 @@ function _getAvatarURL(participantId, email) {
201 201
 
202 202
     return urlPref + avatarId + urlSuf;
203 203
 }
204
-
205
-/**
206
- * Sets a specific property of a specific state to a specific value. Prevents
207
- * unnecessary state changes (when the specified <tt>value</tt> is equal to the
208
- * value of the specified <tt>property</tt> of the specified <tt>state</tt>).
209
- *
210
- * @param {Object} state - The (Redux) state from which a new state is to be
211
- * constructed by setting the specified <tt>property</tt> to the specified
212
- * <tt>value</tt>.
213
- * @param {string} property - The property of <tt>state</tt> which is to be
214
- * assigned the specified <tt>value</tt> (in the new state).
215
- * @param {*} value - The value to assign to the specified <tt>property</tt>.
216
- * @returns {Object} The specified <tt>state</tt> if the value of the specified
217
- * <tt>property</tt> equals the specified <tt>value/tt>; otherwise, a new state
218
- * constructed from the specified <tt>state</tt> by setting the specified
219
- * <tt>property</tt> to the specified <tt>value</tt>.
220
- */
221
-function _setStateProperty(state, property, value) {
222
-    if (state[property] !== value) {
223
-        return {
224
-            ...state,
225
-            [property]: value
226
-        };
227
-    }
228
-
229
-    return state;
230
-}

+ 37
- 0
react/features/base/redux/functions.js Voir le fichier

@@ -0,0 +1,37 @@
1
+/**
2
+ * Sets a specific property of a specific state to a specific value. Prevents
3
+ * unnecessary state changes (when the specified <tt>value</tt> is equal to the
4
+ * value of the specified <tt>property</tt> of the specified <tt>state</tt>).
5
+ *
6
+ * @param {Object} state - The (Redux) state from which a new state is to be
7
+ * constructed by setting the specified <tt>property</tt> to the specified
8
+ * <tt>value</tt>.
9
+ * @param {string} property - The property of <tt>state</tt> which is to be
10
+ * assigned the specified <tt>value</tt> (in the new state).
11
+ * @param {*} value - The value to assign to the specified <tt>property</tt>.
12
+ * @returns {Object} The specified <tt>state</tt> if the value of the specified
13
+ * <tt>property</tt> equals the specified <tt>value/tt>; otherwise, a new state
14
+ * constructed from the specified <tt>state</tt> by setting the specified
15
+ * <tt>property</tt> to the specified <tt>value</tt>.
16
+ */
17
+export function setStateProperty(state, property, value) {
18
+    // Delete state properties that are to be set to undefined. (It is a matter
19
+    // of personal preference, mostly.)
20
+    if (typeof value === 'undefined'
21
+            && Object.prototype.hasOwnProperty.call(state, property)) {
22
+        const newState = { ...state };
23
+
24
+        if (delete newState[property]) {
25
+            return newState;
26
+        }
27
+    }
28
+
29
+    if (state[property] !== value) {
30
+        return {
31
+            ...state,
32
+            [property]: value
33
+        };
34
+    }
35
+
36
+    return state;
37
+}

+ 1
- 0
react/features/base/redux/index.js Voir le fichier

@@ -1,2 +1,3 @@
1
+export * from './functions';
1 2
 export { default as MiddlewareRegistry } from './MiddlewareRegistry';
2 3
 export { default as ReducerRegistry } from './ReducerRegistry';

+ 2
- 1
react/features/base/tracks/middleware.js Voir le fichier

@@ -109,7 +109,8 @@ function _mutedChanged(store, action, mediaType) {
109 109
  * @param {Action} action - The Redux action <tt>TRACK_UPDATED</tt> which is
110 110
  * being dispatched in the specified <tt>store</tt>.
111 111
  * @private
112
- * @returns {void}
112
+ * @returns {Object} The new state that is the result of the reduction of the
113
+ * specified <tt>action</tt>.
113 114
  */
114 115
 function _trackUpdated(store, next, action) {
115 116
     // Determine the muted state of the local track before the update.

+ 0
- 1
react/features/filmStrip/components/FilmStrip.js Voir le fichier

@@ -95,7 +95,6 @@ class FilmStrip extends Component {
95 95
  * @param {Object} state - Redux state.
96 96
  * @returns {{
97 97
  *      participants: Participant[],
98
- *      tracks: (JitsiLocalTrack|JitsiRemoteTrack)[]
99 98
  *  }}
100 99
  */
101 100
 function mapStateToProps(state) {

Chargement…
Annuler
Enregistrer