浏览代码

[RN] Simplify the source code

master
Lyubomir Marinov 8 年前
父节点
当前提交
9f93ce86be

+ 14
- 17
react/features/base/conference/actionTypes.js 查看文件

1
 import { Symbol } from '../react';
1
 import { Symbol } from '../react';
2
 
2
 
3
 /**
3
 /**
4
- * Action type to signal that we are joining the conference.
4
+ * The type of the Redux action which signals that a specific conference has
5
+ * been joined.
5
  *
6
  *
6
  * {
7
  * {
7
- *      type: CONFERENCE_JOINED,
8
- *      conference: {
9
- *          jitsiConference: JitsiConference
10
- *      }
8
+ *     type: CONFERENCE_JOINED,
9
+ *     conference: JitsiConference
11
  * }
10
  * }
12
  */
11
  */
13
 export const CONFERENCE_JOINED = Symbol('CONFERENCE_JOINED');
12
 export const CONFERENCE_JOINED = Symbol('CONFERENCE_JOINED');
14
 
13
 
15
 /**
14
 /**
16
- * Action type to signal that we have left the conference.
15
+ * The type of the Redux action which signals that a specific conference has
16
+ * been left.
17
  *
17
  *
18
  * {
18
  * {
19
- *      type: CONFERENCE_LEFT,
20
- *      conference: {
21
- *          jitsiConference: JitsiConference
22
- *      }
19
+ *     type: CONFERENCE_LEFT,
20
+ *     conference: JitsiConference
23
  * }
21
  * }
24
  */
22
  */
25
 export const CONFERENCE_LEFT = Symbol('CONFERENCE_LEFT');
23
 export const CONFERENCE_LEFT = Symbol('CONFERENCE_LEFT');
26
 
24
 
27
 /**
25
 /**
28
- * Action type to signal that we will leave the specified conference.
26
+ * The type of the Redux action which signals that a specific conference will be
27
+ * left.
29
  *
28
  *
30
  * {
29
  * {
31
- *      type: CONFERENCE_WILL_LEAVE,
32
- *      conference: {
33
- *          jitsiConference: JitsiConference
34
- *      }
30
+ *     type: CONFERENCE_WILL_LEAVE,
31
+ *     conference: JitsiConference
35
  * }
32
  * }
36
  */
33
  */
37
 export const CONFERENCE_WILL_LEAVE = Symbol('CONFERENCE_WILL_LEAVE');
34
 export const CONFERENCE_WILL_LEAVE = Symbol('CONFERENCE_WILL_LEAVE');
41
  * conference to be joined.
38
  * conference to be joined.
42
  *
39
  *
43
  * {
40
  * {
44
- *      type: SET_ROOM,
45
- *      room: string
41
+ *     type: SET_ROOM,
42
+ *     room: string
46
  * }
43
  * }
47
  */
44
  */
48
 export const SET_ROOM = Symbol('SET_ROOM');
45
 export const SET_ROOM = Symbol('SET_ROOM');

+ 76
- 84
react/features/base/conference/actions.js 查看文件

19
 import './middleware';
19
 import './middleware';
20
 import './reducer';
20
 import './reducer';
21
 
21
 
22
-const JitsiConferenceEvents = JitsiMeetJS.events.conference;
23
-
24
 /**
22
 /**
25
- * Initializes a new conference.
23
+ * Adds conference (event) listeners.
26
  *
24
  *
27
- * @returns {Function}
25
+ * @param {JitsiConference} conference - The JitsiConference instance.
26
+ * @param {Dispatch} dispatch - The Redux dispatch function.
27
+ * @private
28
+ * @returns {void}
28
  */
29
  */
29
-export function createConference() {
30
-    return (dispatch, getState) => {
31
-        const state = getState();
32
-        const connection = state['features/base/connection'].jitsiConnection;
33
-        const room = state['features/base/conference'].room;
30
+function _addConferenceListeners(conference, dispatch) {
31
+    const JitsiConferenceEvents = JitsiMeetJS.events.conference;
34
 
32
 
35
-        if (!connection) {
36
-            throw new Error('Cannot create conference without connection');
37
-        }
38
-        if (typeof room === 'undefined' || room === '') {
39
-            throw new Error('Cannot join conference without room name');
40
-        }
33
+    conference.on(
34
+            JitsiConferenceEvents.CONFERENCE_JOINED,
35
+            (...args) => dispatch(_conferenceJoined(conference, ...args)));
36
+    conference.on(
37
+            JitsiConferenceEvents.CONFERENCE_LEFT,
38
+            (...args) => dispatch(_conferenceLeft(conference, ...args)));
41
 
39
 
42
-        // TODO Take options from config.
43
-        const conference
44
-            = connection.initJitsiConference(room, { openSctp: true });
40
+    conference.on(
41
+            JitsiConferenceEvents.DOMINANT_SPEAKER_CHANGED,
42
+            (...args) => dispatch(dominantSpeakerChanged(...args)));
43
+
44
+    conference.on(
45
+            JitsiConferenceEvents.TRACK_ADDED,
46
+            t => t && !t.isLocal() && dispatch(trackAdded(t)));
47
+    conference.on(
48
+            JitsiConferenceEvents.TRACK_REMOVED,
49
+            t => t && !t.isLocal() && dispatch(trackRemoved(t)));
45
 
50
 
46
-        _setupConferenceListeners(conference, dispatch);
51
+    conference.on(
52
+            JitsiConferenceEvents.USER_JOINED,
53
+            (id, user) => dispatch(participantJoined({
54
+                id,
55
+                name: user.getDisplayName(),
56
+                role: user.getRole()
57
+            })));
58
+    conference.on(
59
+            JitsiConferenceEvents.USER_LEFT,
60
+            (...args) => dispatch(participantLeft(...args)));
61
+    conference.on(
62
+            JitsiConferenceEvents.USER_ROLE_CHANGED,
63
+            (...args) => dispatch(participantRoleChanged(...args)));
47
 
64
 
48
-        conference.join();
49
-    };
65
+    conference.addCommandListener(
66
+            EMAIL_COMMAND,
67
+            (data, id) => dispatch(changeParticipantEmail(id, data.value)));
50
 }
68
 }
51
 
69
 
52
 /**
70
 /**
70
 
88
 
71
         dispatch({
89
         dispatch({
72
             type: CONFERENCE_JOINED,
90
             type: CONFERENCE_JOINED,
73
-            conference: {
74
-                jitsiConference: conference
75
-            }
91
+            conference
76
         });
92
         });
77
     };
93
     };
78
 }
94
 }
79
 
95
 
80
 /**
96
 /**
81
- * Signal that we have left the conference.
97
+ * Signals that a specific conference has been left.
82
  *
98
  *
83
  * @param {JitsiConference} conference - The JitsiConference instance which was
99
  * @param {JitsiConference} conference - The JitsiConference instance which was
84
  * left by the local participant.
100
  * left by the local participant.
85
  * @returns {{
101
  * @returns {{
86
  *      type: CONFERENCE_LEFT,
102
  *      type: CONFERENCE_LEFT,
87
- *      conference: {
88
- *          jitsiConference: JitsiConference
89
- *      }
103
+ *      conference: JitsiConference
90
  *  }}
104
  *  }}
91
  */
105
  */
92
 function _conferenceLeft(conference) {
106
 function _conferenceLeft(conference) {
93
     return {
107
     return {
94
         type: CONFERENCE_LEFT,
108
         type: CONFERENCE_LEFT,
95
-        conference: {
96
-            jitsiConference: conference
97
-        }
109
+        conference
98
     };
110
     };
99
 }
111
 }
100
 
112
 
101
 /**
113
 /**
102
- * Signal the intention of the application to have the local participant leave a
103
- * specific conference. Similar in fashion to CONFERENCE_LEFT. Contrary to it
114
+ * Signals the intention of the application to have the local participant leave
115
+ * a specific conference. Similar in fashion to CONFERENCE_LEFT. Contrary to it
104
  * though, it's not guaranteed because CONFERENCE_LEFT may be triggered by
116
  * though, it's not guaranteed because CONFERENCE_LEFT may be triggered by
105
  * lib-jitsi-meet and not the application.
117
  * lib-jitsi-meet and not the application.
106
  *
118
  *
108
  * be left by the local participant.
120
  * be left by the local participant.
109
  * @returns {{
121
  * @returns {{
110
  *      type: CONFERENCE_LEFT,
122
  *      type: CONFERENCE_LEFT,
111
- *      conference: {
112
- *          jitsiConference: JitsiConference
113
- *      }
123
+ *      conference: JitsiConference
114
  *  }}
124
  *  }}
115
  */
125
  */
116
 export function conferenceWillLeave(conference) {
126
 export function conferenceWillLeave(conference) {
117
     return {
127
     return {
118
         type: CONFERENCE_WILL_LEAVE,
128
         type: CONFERENCE_WILL_LEAVE,
119
-        conference: {
120
-            jitsiConference: conference
129
+        conference
130
+    };
131
+}
132
+
133
+/**
134
+ * Initializes a new conference.
135
+ *
136
+ * @returns {Function}
137
+ */
138
+export function createConference() {
139
+    return (dispatch, getState) => {
140
+        const state = getState();
141
+        const connection = state['features/base/connection'].connection;
142
+
143
+        if (!connection) {
144
+            throw new Error('Cannot create conference without connection');
121
         }
145
         }
146
+
147
+        const room = state['features/base/conference'].room;
148
+
149
+        if (typeof room === 'undefined' || room === '') {
150
+            throw new Error('Cannot join conference without room name');
151
+        }
152
+
153
+        // TODO Take options from config.
154
+        const conference
155
+            = connection.initJitsiConference(room, { openSctp: true });
156
+
157
+        _addConferenceListeners(conference, dispatch);
158
+
159
+        conference.join();
122
     };
160
     };
123
 }
161
 }
124
 
162
 
138
         room
176
         room
139
     };
177
     };
140
 }
178
 }
141
-
142
-/**
143
- * Setup various conference event handlers.
144
- *
145
- * @param {JitsiConference} conference - The JitsiConference instance.
146
- * @param {Dispatch} dispatch - The Redux dispatch function.
147
- * @private
148
- * @returns {void}
149
- */
150
-function _setupConferenceListeners(conference, dispatch) {
151
-    conference.on(
152
-            JitsiConferenceEvents.CONFERENCE_JOINED,
153
-            () => dispatch(_conferenceJoined(conference)));
154
-    conference.on(
155
-            JitsiConferenceEvents.CONFERENCE_LEFT,
156
-            () => dispatch(_conferenceLeft(conference)));
157
-
158
-    conference.on(
159
-            JitsiConferenceEvents.DOMINANT_SPEAKER_CHANGED,
160
-            id => dispatch(dominantSpeakerChanged(id)));
161
-
162
-    conference.on(
163
-            JitsiConferenceEvents.TRACK_ADDED,
164
-            t => t && !t.isLocal() && dispatch(trackAdded(t)));
165
-    conference.on(
166
-            JitsiConferenceEvents.TRACK_REMOVED,
167
-            t => t && !t.isLocal() && dispatch(trackRemoved(t)));
168
-
169
-    conference.on(
170
-            JitsiConferenceEvents.USER_JOINED,
171
-            (id, user) => dispatch(participantJoined({
172
-                id,
173
-                name: user.getDisplayName(),
174
-                role: user.getRole()
175
-            })));
176
-    conference.on(
177
-            JitsiConferenceEvents.USER_LEFT,
178
-            id => dispatch(participantLeft(id)));
179
-    conference.on(
180
-            JitsiConferenceEvents.USER_ROLE_CHANGED,
181
-            (id, role) => dispatch(participantRoleChanged(id, role)));
182
-
183
-    conference.addCommandListener(
184
-            EMAIL_COMMAND,
185
-            (data, id) => dispatch(changeParticipantEmail(id, data.value)));
186
-}

+ 30
- 31
react/features/base/conference/middleware.js 查看文件

95
         pin = !localParticipant || !localParticipant.pinned;
95
         pin = !localParticipant || !localParticipant.pinned;
96
     }
96
     }
97
     if (pin) {
97
     if (pin) {
98
-        const conference = state['features/base/conference'].jitsiConference;
98
+        const conference = state['features/base/conference'].conference;
99
 
99
 
100
         try {
100
         try {
101
             conference.pinParticipant(id);
101
             conference.pinParticipant(id);
107
     return next(action);
107
     return next(action);
108
 }
108
 }
109
 
109
 
110
+/**
111
+ * Synchronizes local tracks from state with local tracks in JitsiConference
112
+ * instance.
113
+ *
114
+ * @param {Store} store - Redux store.
115
+ * @param {Object} action - Action object.
116
+ * @private
117
+ * @returns {Promise}
118
+ */
119
+function _syncConferenceLocalTracksWithState(store, action) {
120
+    const state = store.getState()['features/base/conference'];
121
+    const conference = state.conference;
122
+    let promise;
123
+
124
+    // XXX The conference may already be in the process of being left, that's
125
+    // why we should not add/remove local tracks to such conference.
126
+    if (conference && conference !== state.leaving) {
127
+        const track = action.track.jitsiTrack;
128
+
129
+        if (action.type === TRACK_ADDED) {
130
+            promise = _addLocalTracksToConference(conference, [ track ]);
131
+        } else {
132
+            promise = _removeLocalTracksFromConference(conference, [ track ]);
133
+        }
134
+    }
135
+
136
+    return promise || Promise.resolve();
137
+}
138
+
110
 /**
139
 /**
111
  * Notifies the feature base/conference that the action TRACK_ADDED
140
  * Notifies the feature base/conference that the action TRACK_ADDED
112
  * or TRACK_REMOVED is being dispatched within a specific Redux store.
141
  * or TRACK_REMOVED is being dispatched within a specific Redux store.
132
 
161
 
133
     return next(action);
162
     return next(action);
134
 }
163
 }
135
-
136
-/**
137
- * Synchronizes local tracks from state with local tracks in JitsiConference
138
- * instance.
139
- *
140
- * @param {Store} store - Redux store.
141
- * @param {Object} action - Action object.
142
- * @private
143
- * @returns {Promise}
144
- */
145
-function _syncConferenceLocalTracksWithState(store, action) {
146
-    const conferenceState = store.getState()['features/base/conference'];
147
-    const conference = conferenceState.jitsiConference;
148
-    const leavingConference = conferenceState.leavingJitsiConference;
149
-    let promise;
150
-
151
-    // XXX The conference in state might be already in 'leaving' state, that's
152
-    // why we should not add/remove local tracks to such conference.
153
-    if (conference && conference !== leavingConference) {
154
-        const track = action.track.jitsiTrack;
155
-
156
-        if (action.type === TRACK_ADDED) {
157
-            promise = _addLocalTracksToConference(conference, [ track ]);
158
-        } else {
159
-            promise = _removeLocalTracksFromConference(conference, [ track ]);
160
-        }
161
-    }
162
-
163
-    return promise || Promise.resolve();
164
-}

+ 103
- 52
react/features/base/conference/reducer.js 查看文件

1
-import { ReducerRegistry, setStateProperty } from '../redux';
1
+import JitsiMeetJS from '../lib-jitsi-meet';
2
+import {
3
+    ReducerRegistry,
4
+    setStateProperties,
5
+    setStateProperty
6
+} from '../redux';
2
 
7
 
3
 import {
8
 import {
4
     CONFERENCE_JOINED,
9
     CONFERENCE_JOINED,
8
 } from './actionTypes';
13
 } from './actionTypes';
9
 import { isRoomValid } from './functions';
14
 import { isRoomValid } from './functions';
10
 
15
 
11
-const INITIAL_STATE = {
12
-    jitsiConference: null,
16
+/**
17
+ * Listen for actions that contain the conference object, so that it can be
18
+ * stored for use by other action creators.
19
+ */
20
+ReducerRegistry.register('features/base/conference', (state = {}, action) => {
21
+    switch (action.type) {
22
+    case CONFERENCE_JOINED:
23
+        return _conferenceJoined(state, action);
13
 
24
 
14
-    /**
15
-     * Instance of JitsiConference that is currently in 'leaving' state.
16
-     */
17
-    leavingJitsiConference: null,
25
+    case CONFERENCE_LEFT:
26
+        return _conferenceLeft(state, action);
18
 
27
 
19
-    /**
20
-     * The name of the room of the conference (to be) joined (i.e.
21
-     * {@link #jitsiConference}).
22
-     *
23
-     * @type {string}
24
-     */
25
-    room: null
26
-};
28
+    case CONFERENCE_WILL_LEAVE:
29
+        return _conferenceWillLeave(state, action);
30
+
31
+    case SET_ROOM:
32
+        return _setRoom(state, action);
33
+    }
34
+
35
+    return state;
36
+});
27
 
37
 
28
 /**
38
 /**
29
- * Listen for actions that contain the conference object, so that it can be
30
- * stored for use by other action creators.
39
+ * Reduces a specific Redux action CONFERENCE_JOINED of the feature
40
+ * base/conference.
41
+ *
42
+ * @param {Object} state - The Redux state of the feature base/conference.
43
+ * @param {Action} action - The Redux action CONFERENCE_JOINED to reduce.
44
+ * @private
45
+ * @returns {Object} The new state of the feature base/conference after the
46
+ * reduction of the specified action.
47
+ */
48
+function _conferenceJoined(state, action) {
49
+    return (
50
+        setStateProperties(state, {
51
+            /**
52
+             * The JitsiConference instance represented by the Redux state of
53
+             * the feature base/conference.
54
+             *
55
+             * @type {JitsiConference}
56
+             */
57
+            conference: action.conference,
58
+            leaving: undefined
59
+        }));
60
+}
61
+
62
+/**
63
+ * Reduces a specific Redux action CONFERENCE_LEFT of the feature
64
+ * base/conference.
65
+ *
66
+ * @param {Object} state - The Redux state of the feature base/conference.
67
+ * @param {Action} action - The Redux action CONFERENCE_LEFT to reduce.
68
+ * @private
69
+ * @returns {Object} The new state of the feature base/conference after the
70
+ * reduction of the specified action.
31
  */
71
  */
32
-ReducerRegistry.register('features/base/conference',
33
-    (state = INITIAL_STATE, action) => {
34
-        switch (action.type) {
35
-        case CONFERENCE_JOINED:
36
-            return (
37
-                setStateProperty(
38
-                        state,
39
-                        'jitsiConference',
40
-                        action.conference.jitsiConference));
41
-
42
-        case CONFERENCE_LEFT:
43
-            if (state.jitsiConference === action.conference.jitsiConference) {
44
-                return {
45
-                    ...state,
46
-                    jitsiConference: null,
47
-                    leavingJitsiConference: state.leavingJitsiConference
48
-                        === action.conference.jitsiConference
49
-                            ? null
50
-                            : state.leavingJitsiConference
51
-                };
52
-            }
53
-            break;
54
-
55
-        case CONFERENCE_WILL_LEAVE:
56
-            return (
57
-                setStateProperty(
58
-                        state,
59
-                        'leavingJitsiConference',
60
-                        action.conference.jitsiConference));
61
-
62
-        case SET_ROOM:
63
-            return _setRoom(state, action);
64
-        }
72
+function _conferenceLeft(state, action) {
73
+    const conference = action.conference;
65
 
74
 
75
+    if (state.conference !== conference) {
66
         return state;
76
         return state;
67
-    });
77
+    }
78
+
79
+    return (
80
+        setStateProperties(state, {
81
+            conference: undefined,
82
+            leaving: undefined
83
+        }));
84
+}
85
+
86
+/**
87
+ * Reduces a specific Redux action CONFERENCE_WILL_LEAVE of the feature
88
+ * base/conference.
89
+ *
90
+ * @param {Object} state - The Redux state of the feature base/conference.
91
+ * @param {Action} action - The Redux action CONFERENCE_WILL_LEAVE to reduce.
92
+ * @private
93
+ * @returns {Object} The new state of the feature base/conference after the
94
+ * reduction of the specified action.
95
+ */
96
+function _conferenceWillLeave(state, action) {
97
+    const conference = action.conference;
98
+
99
+    if (state.conference !== conference) {
100
+        return state;
101
+    }
102
+
103
+    return (
104
+        setStateProperties(state, {
105
+            /**
106
+             * The JitsiConference instance which is currently in the process of
107
+             * being left.
108
+             *
109
+             * @type {JitsiConference}
110
+             */
111
+            leaving: conference
112
+        }));
113
+}
68
 
114
 
69
 /**
115
 /**
70
  * Reduces a specific Redux action SET_ROOM of the feature base/conference.
116
  * Reduces a specific Redux action SET_ROOM of the feature base/conference.
85
         // Technically, there are multiple values which don't represent valid
131
         // Technically, there are multiple values which don't represent valid
86
         // room names. Practically, each of them is as bad as the rest of them
132
         // room names. Practically, each of them is as bad as the rest of them
87
         // because we can't use any of them to join a conference.
133
         // because we can't use any of them to join a conference.
88
-        room = INITIAL_STATE.room;
134
+        room = undefined;
89
     }
135
     }
90
 
136
 
137
+    /**
138
+     * The name of the room of the conference (to be) joined.
139
+     *
140
+     * @type {string}
141
+     */
91
     return setStateProperty(state, 'room', room);
142
     return setStateProperty(state, 'room', room);
92
 }
143
 }

+ 2
- 2
react/features/base/connection/actions.js 查看文件

105
 export function disconnect() {
105
 export function disconnect() {
106
     return (dispatch, getState) => {
106
     return (dispatch, getState) => {
107
         const state = getState();
107
         const state = getState();
108
-        const conference = state['features/base/conference'].jitsiConference;
109
-        const connection = state['features/base/connection'].jitsiConnection;
108
+        const conference = state['features/base/conference'].conference;
109
+        const connection = state['features/base/connection'].connection;
110
 
110
 
111
         let promise;
111
         let promise;
112
 
112
 

+ 3
- 3
react/features/base/connection/reducer.js 查看文件

35
  * reduction of the specified action.
35
  * reduction of the specified action.
36
  */
36
  */
37
 function _connectionDisconnected(state, action) {
37
 function _connectionDisconnected(state, action) {
38
-    if (state.jitsiConnection === action.connection) {
39
-        return setStateProperty(state, 'jitsiConnection', undefined);
38
+    if (state.connection === action.connection) {
39
+        return setStateProperty(state, 'connection', undefined);
40
     }
40
     }
41
 
41
 
42
     return state;
42
     return state;
53
  * reduction of the specified action.
53
  * reduction of the specified action.
54
  */
54
  */
55
 function _connectionEstablished(state, action) {
55
 function _connectionEstablished(state, action) {
56
-    return setStateProperty(state, 'jitsiConnection', action.connection);
56
+    return setStateProperty(state, 'connection', action.connection);
57
 }
57
 }
58
 
58
 
59
 /**
59
 /**

+ 1
- 3
react/features/base/participants/middleware.js 查看文件

17
 MiddlewareRegistry.register(store => next => action => {
17
 MiddlewareRegistry.register(store => next => action => {
18
     switch (action.type) {
18
     switch (action.type) {
19
     case CONFERENCE_JOINED:
19
     case CONFERENCE_JOINED:
20
-        store.dispatch(
21
-            localParticipantIdChanged(
22
-                action.conference.jitsiConference.myUserId()));
20
+        store.dispatch(localParticipantIdChanged(action.conference.myUserId()));
23
         break;
21
         break;
24
 
22
 
25
     case CONFERENCE_LEFT:
23
     case CONFERENCE_LEFT:

+ 59
- 5
react/features/base/redux/functions.js 查看文件

1
+/**
2
+ * Sets specific properties of a specific state to specific values and prevents
3
+ * unnecessary state changes.
4
+ *
5
+ * @param {Object} target - The state on which the specified properties are to
6
+ * be set.
7
+ * @param {Object} source - The map of properties to values which are to be set
8
+ * on the specified target.
9
+ * @returns {Object} The specified target if the values of the specified
10
+ * properties equal the specified values; otherwise, a new state constructed
11
+ * from the specified target by setting the specified properties to the
12
+ * specified values.
13
+ */
14
+export function setStateProperties(target, source) {
15
+    let t = target;
16
+
17
+    for (const property in source) { // eslint-disable-line guard-for-in
18
+        t = setStateProperty(t, property, source[property], t === target);
19
+    }
20
+
21
+    return t;
22
+}
23
+
1
 /**
24
 /**
2
  * Sets a specific property of a specific state to a specific value. Prevents
25
  * 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
26
  * unnecessary state changes (when the specified <tt>value</tt> is equal to the
15
  * <tt>property</tt> to the specified <tt>value</tt>.
38
  * <tt>property</tt> to the specified <tt>value</tt>.
16
  */
39
  */
17
 export function setStateProperty(state, property, value) {
40
 export function setStateProperty(state, property, value) {
41
+    return _setStateProperty(state, property, value, /* copyOnWrite */ false);
42
+}
43
+
44
+/* eslint-disable max-params */
45
+
46
+/**
47
+ * Sets a specific property of a specific state to a specific value. Prevents
48
+ * unnecessary state changes (when the specified <tt>value</tt> is equal to the
49
+ * value of the specified <tt>property</tt> of the specified <tt>state</tt>).
50
+ *
51
+ * @param {Object} state - The (Redux) state from which a state is to be
52
+ * constructed by setting the specified <tt>property</tt> to the specified
53
+ * <tt>value</tt>.
54
+ * @param {string} property - The property of <tt>state</tt> which is to be
55
+ * assigned the specified <tt>value</tt>.
56
+ * @param {*} value - The value to assign to the specified <tt>property</tt>.
57
+ * @param {boolean} copyOnWrite - If the specified <tt>state</tt> is to not be
58
+ * modified, <tt>true</tt>; otherwise, <tt>false</tt>.
59
+ * @returns {Object} The specified <tt>state</tt> if the value of the specified
60
+ * <tt>property</tt> equals the specified <tt>value/tt> or <tt>copyOnWrite</tt>
61
+ * is truthy; otherwise, a new state constructed from the specified
62
+ * <tt>state</tt> by setting the specified <tt>property</tt> to the specified
63
+ * <tt>value</tt>.
64
+ */
65
+function _setStateProperty(state, property, value, copyOnWrite) {
18
     // Delete state properties that are to be set to undefined. (It is a matter
66
     // Delete state properties that are to be set to undefined. (It is a matter
19
     // of personal preference, mostly.)
67
     // of personal preference, mostly.)
20
     if (typeof value === 'undefined'
68
     if (typeof value === 'undefined'
21
             && Object.prototype.hasOwnProperty.call(state, property)) {
69
             && Object.prototype.hasOwnProperty.call(state, property)) {
22
-        const newState = { ...state };
70
+        const newState = copyOnWrite ? { ...state } : state;
23
 
71
 
24
         if (delete newState[property]) {
72
         if (delete newState[property]) {
25
             return newState;
73
             return newState;
27
     }
75
     }
28
 
76
 
29
     if (state[property] !== value) {
77
     if (state[property] !== value) {
30
-        return {
31
-            ...state,
32
-            [property]: value
33
-        };
78
+        if (copyOnWrite) {
79
+            return {
80
+                ...state,
81
+                [property]: value
82
+            };
83
+        }
84
+
85
+        state[property] = value;
34
     }
86
     }
35
 
87
 
36
     return state;
88
     return state;
37
 }
89
 }
90
+
91
+/* eslint-enable max-params */

+ 1
- 4
react/features/conference/components/Conference.native.js 查看文件

1
 import React, { Component } from 'react';
1
 import React, { Component } from 'react';
2
 import { connect as reactReduxConnect } from 'react-redux';
2
 import { connect as reactReduxConnect } from 'react-redux';
3
 
3
 
4
-import {
5
-    connect,
6
-    disconnect
7
-} from '../../base/connection';
4
+import { connect, disconnect } from '../../base/connection';
8
 import { Container } from '../../base/react';
5
 import { Container } from '../../base/react';
9
 import { FilmStrip } from '../../filmStrip';
6
 import { FilmStrip } from '../../filmStrip';
10
 import { LargeVideo } from '../../largeVideo';
7
 import { LargeVideo } from '../../largeVideo';

+ 1
- 1
react/features/largeVideo/actions.js 查看文件

20
 export function selectParticipant() {
20
 export function selectParticipant() {
21
     return (dispatch, getState) => {
21
     return (dispatch, getState) => {
22
         const state = getState();
22
         const state = getState();
23
-        const conference = state['features/base/conference'].jitsiConference;
23
+        const conference = state['features/base/conference'].conference;
24
 
24
 
25
         if (conference) {
25
         if (conference) {
26
             const largeVideo = state['features/largeVideo'];
26
             const largeVideo = state['features/largeVideo'];

正在加载...
取消
保存