Lyubo Marinov 7 лет назад
Родитель
Сommit
fcca15c827
2 измененных файлов: 100 добавлений и 92 удалений
  1. 2
    3
      react/features/app/components/AbstractApp.js
  2. 98
    89
      react/features/base/participants/middleware.js

+ 2
- 3
react/features/app/components/AbstractApp.js Просмотреть файл

386
      * @returns {Store} - The redux store to be used by this
386
      * @returns {Store} - The redux store to be used by this
387
      * {@code AbstractApp}.
387
      * {@code AbstractApp}.
388
      */
388
      */
389
-    _maybeCreateStore(props) {
389
+    _maybeCreateStore({ store }) {
390
         // The application Jitsi Meet is architected with redux. However, I do
390
         // The application Jitsi Meet is architected with redux. However, I do
391
         // not want consumers of the App React Component to be forced into
391
         // not want consumers of the App React Component to be forced into
392
         // dealing with redux. If the consumer did not provide an external redux
392
         // dealing with redux. If the consumer did not provide an external redux
393
         // store, utilize an internal redux store.
393
         // store, utilize an internal redux store.
394
-        let store = props.store;
395
-
396
         if (typeof store === 'undefined') {
394
         if (typeof store === 'undefined') {
395
+            // eslint-disable-next-line no-param-reassign
397
             store = this._createStore();
396
             store = this._createStore();
398
 
397
 
399
             // This is temporary workaround to be able to dispatch actions from
398
             // This is temporary workaround to be able to dispatch actions from

+ 98
- 89
react/features/base/participants/middleware.js Просмотреть файл

1
 // @flow
1
 // @flow
2
 
2
 
3
-import UIEvents from '../../../../service/UI/UIEvents';
4
-
5
 import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../../app';
3
 import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../../app';
6
-import {
7
-    CONFERENCE_WILL_JOIN,
8
-    CONFERENCE_LEFT
9
-} from '../conference';
4
+import { CONFERENCE_LEFT, CONFERENCE_WILL_JOIN } from '../conference';
10
 import { MiddlewareRegistry } from '../redux';
5
 import { MiddlewareRegistry } from '../redux';
6
+import UIEvents from '../../../../service/UI/UIEvents';
11
 import { playSound, registerSound, unregisterSound } from '../sounds';
7
 import { playSound, registerSound, unregisterSound } from '../sounds';
12
 
8
 
13
 import {
9
 import {
43
  * Middleware that captures CONFERENCE_JOINED and CONFERENCE_LEFT actions and
39
  * Middleware that captures CONFERENCE_JOINED and CONFERENCE_LEFT actions and
44
  * updates respectively ID of local participant.
40
  * updates respectively ID of local participant.
45
  *
41
  *
46
- * @param {Store} store - Redux store.
42
+ * @param {Store} store - The redux store.
47
  * @returns {Function}
43
  * @returns {Function}
48
  */
44
  */
49
 MiddlewareRegistry.register(store => next => action => {
45
 MiddlewareRegistry.register(store => next => action => {
50
-    const { conference } = store.getState()['features/base/conference'];
51
-
52
-    if (action.type === PARTICIPANT_JOINED
53
-            || action.type === PARTICIPANT_LEFT) {
54
-        _maybePlaySounds(store, action);
55
-    }
56
-
57
     switch (action.type) {
46
     switch (action.type) {
58
     case APP_WILL_MOUNT:
47
     case APP_WILL_MOUNT:
59
         _registerSounds(store);
48
         _registerSounds(store);
77
         const participant = getLocalParticipant(store.getState());
66
         const participant = getLocalParticipant(store.getState());
78
 
67
 
79
         if (participant) {
68
         if (participant) {
80
-            const local = participant.id === action.participant.id;
69
+            const { id } = action.participant;
81
 
70
 
82
             store.dispatch(participantUpdated({
71
             store.dispatch(participantUpdated({
83
-                id: action.participant.id,
84
-                local,
72
+                id,
73
+                local: participant.id === id,
85
                 raisedHand: false
74
                 raisedHand: false
86
             }));
75
             }));
87
         }
76
         }
88
 
77
 
89
-        if (typeof APP === 'object') {
90
-            APP.UI.markDominantSpeaker(action.participant.id);
91
-        }
78
+        typeof APP === 'object'
79
+            && APP.UI.markDominantSpeaker(action.participant.id);
92
 
80
 
93
         break;
81
         break;
94
     }
82
     }
95
 
83
 
96
-    case KICK_PARTICIPANT:
84
+    case KICK_PARTICIPANT: {
85
+        const { conference } = store.getState()['features/base/conference'];
86
+
97
         conference.kickParticipant(action.id);
87
         conference.kickParticipant(action.id);
98
         break;
88
         break;
89
+    }
90
+
91
+    case MUTE_REMOTE_PARTICIPANT: {
92
+        const { conference } = store.getState()['features/base/conference'];
99
 
93
 
100
-    case MUTE_REMOTE_PARTICIPANT:
101
         conference.muteParticipant(action.id);
94
         conference.muteParticipant(action.id);
102
         break;
95
         break;
96
+    }
103
 
97
 
104
     // TODO Remove this middleware when the local display name update flow is
98
     // TODO Remove this middleware when the local display name update flow is
105
     // fully brought into redux.
99
     // fully brought into redux.
116
     }
110
     }
117
 
111
 
118
     case PARTICIPANT_JOINED:
112
     case PARTICIPANT_JOINED:
119
-    case PARTICIPANT_UPDATED: {
120
-        const { participant } = action;
121
-        const { id, local, raisedHand } = participant;
122
-
123
-        // Send an external update of the local participant's raised hand state
124
-        // if a new raised hand state is defined in the action.
125
-        if (typeof raisedHand !== 'undefined') {
126
-            if (local) {
127
-                conference.setLocalParticipantProperty(
128
-                    'raisedHand',
129
-                    raisedHand);
130
-            }
131
-
132
-            if (typeof APP === 'object') {
133
-                if (local) {
134
-                    APP.UI.onLocalRaiseHandChanged(raisedHand);
135
-                    APP.UI.setLocalRaisedHandStatus(raisedHand);
136
-                } else {
137
-                    const remoteParticipant
138
-                        = getParticipantById(store.getState(), id);
139
-
140
-                    remoteParticipant
141
-                        && APP.UI.setRaisedHandStatus(
142
-                            remoteParticipant.id,
143
-                            remoteParticipant.name,
144
-                            raisedHand);
145
-                }
146
-            }
147
-        }
148
-
149
-        // Notify external listeners of potential avatarURL changes.
150
-        if (typeof APP === 'object') {
151
-            const preUpdateAvatarURL
152
-                = getAvatarURLByParticipantId(store.getState(), id);
153
-
154
-            // Allow the redux update to go through and compare the old avatar
155
-            // to the new avatar and emit out change events if necessary.
156
-            const result = next(action);
157
-
158
-            const postUpdateAvatarURL
159
-                = getAvatarURLByParticipantId(store.getState(), id);
160
-
161
-            if (preUpdateAvatarURL !== postUpdateAvatarURL) {
162
-                const currentKnownId = local
163
-                    ? APP.conference.getMyUserId() : id;
164
-
165
-                APP.UI.refreshAvatarDisplay(
166
-                    currentKnownId, postUpdateAvatarURL);
167
-                APP.API.notifyAvatarChanged(
168
-                    currentKnownId, postUpdateAvatarURL);
169
-            }
113
+        _maybePlaySounds(store, action);
170
 
114
 
171
-            return result;
172
-        }
115
+        return _participantJoinedOrUpdated(store, next, action);
173
 
116
 
117
+    case PARTICIPANT_LEFT:
118
+        _maybePlaySounds(store, action);
174
         break;
119
         break;
175
-    }
120
+
121
+    case PARTICIPANT_UPDATED:
122
+        return _participantJoinedOrUpdated(store, next, action);
176
     }
123
     }
177
 
124
 
178
     return next(action);
125
     return next(action);
182
  * Initializes the local participant and signals that it joined.
129
  * Initializes the local participant and signals that it joined.
183
  *
130
  *
184
  * @private
131
  * @private
185
- * @param {Store} store - The Redux store.
132
+ * @param {Store} store - The redux store.
186
  * @param {Dispatch} next - The redux dispatch function to dispatch the
133
  * @param {Dispatch} next - The redux dispatch function to dispatch the
187
  * specified action to the specified store.
134
  * specified action to the specified store.
188
  * @param {Action} action - The redux action which is being dispatched
135
  * @param {Action} action - The redux action which is being dispatched
208
 /**
155
 /**
209
  * Plays sounds when participants join/leave conference.
156
  * Plays sounds when participants join/leave conference.
210
  *
157
  *
211
- * @param {Store} store - The Redux store.
212
- * @param {Action} action - The Redux action. Should be either
158
+ * @param {Store} store - The redux store.
159
+ * @param {Action} action - The redux action. Should be either
213
  * {@link PARTICIPANT_JOINED} or {@link PARTICIPANT_LEFT}.
160
  * {@link PARTICIPANT_JOINED} or {@link PARTICIPANT_LEFT}.
214
  * @private
161
  * @private
215
  * @returns {void}
162
  * @returns {void}
223
     // The intention there was to not play user joined notification in big
170
     // The intention there was to not play user joined notification in big
224
     // conferences where 100th person is joining.
171
     // conferences where 100th person is joining.
225
     if (!action.participant.local
172
     if (!action.participant.local
226
-        && (!startAudioMuted
227
-            || getParticipantCount(state) < startAudioMuted)) {
173
+            && (!startAudioMuted
174
+                || getParticipantCount(state) < startAudioMuted)) {
228
         if (action.type === PARTICIPANT_JOINED) {
175
         if (action.type === PARTICIPANT_JOINED) {
229
             dispatch(playSound(PARTICIPANT_JOINED_SOUND_ID));
176
             dispatch(playSound(PARTICIPANT_JOINED_SOUND_ID));
230
         } else if (action.type === PARTICIPANT_LEFT) {
177
         } else if (action.type === PARTICIPANT_LEFT) {
233
     }
180
     }
234
 }
181
 }
235
 
182
 
183
+/**
184
+ * Notifies the feature base/participants that the action
185
+ * {@code PARTICIPANT_JOINED} or {@code PARTICIPANT_UPDATED} is being dispatched
186
+ * within a specific redux store.
187
+ *
188
+ * @param {Store} store - The redux store in which the specified {@code action}
189
+ * is being dispatched.
190
+ * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
191
+ * specified {@code action} in the specified {@code store}.
192
+ * @param {Action} action - The redux action {@code PARTICIPANT_JOINED} or
193
+ * {@code PARTICIPANT_UPDATED} which is being dispatched in the specified
194
+ * {@code store}.
195
+ * @private
196
+ * @returns {Object} The value returned by {@code next(action)}.
197
+ */
198
+function _participantJoinedOrUpdated({ getState }, next, action) {
199
+    const { participant: { id, local, raisedHand } } = action;
200
+
201
+    // Send an external update of the local participant's raised hand state
202
+    // if a new raised hand state is defined in the action.
203
+    if (typeof raisedHand !== 'undefined') {
204
+        if (local) {
205
+            const { conference } = getState()['features/base/conference'];
206
+
207
+            conference.setLocalParticipantProperty('raisedHand', raisedHand);
208
+        }
209
+
210
+        if (typeof APP === 'object') {
211
+            if (local) {
212
+                APP.UI.onLocalRaiseHandChanged(raisedHand);
213
+                APP.UI.setLocalRaisedHandStatus(raisedHand);
214
+            } else {
215
+                const remoteParticipant = getParticipantById(getState(), id);
216
+
217
+                remoteParticipant
218
+                    && APP.UI.setRaisedHandStatus(
219
+                        remoteParticipant.id,
220
+                        remoteParticipant.name,
221
+                        raisedHand);
222
+            }
223
+        }
224
+    }
225
+
226
+    // Notify external listeners of potential avatarURL changes.
227
+    if (typeof APP === 'object') {
228
+        const oldAvatarURL = getAvatarURLByParticipantId(getState(), id);
229
+
230
+        // Allow the redux update to go through and compare the old avatar
231
+        // to the new avatar and emit out change events if necessary.
232
+        const result = next(action);
233
+        const newAvatarURL = getAvatarURLByParticipantId(getState(), id);
234
+
235
+        if (oldAvatarURL !== newAvatarURL) {
236
+            const currentKnownId = local ? APP.conference.getMyUserId() : id;
237
+
238
+            APP.UI.refreshAvatarDisplay(currentKnownId, newAvatarURL);
239
+            APP.API.notifyAvatarChanged(currentKnownId, newAvatarURL);
240
+        }
241
+
242
+        return result;
243
+    }
244
+
245
+    return next(action);
246
+}
247
+
236
 /**
248
 /**
237
  * Registers sounds related with the participants feature.
249
  * Registers sounds related with the participants feature.
238
  *
250
  *
239
- * @param {Store} store - The Redux store.
251
+ * @param {Store} store - The redux store.
240
  * @private
252
  * @private
241
  * @returns {void}
253
  * @returns {void}
242
  */
254
  */
243
 function _registerSounds({ dispatch }) {
255
 function _registerSounds({ dispatch }) {
244
     dispatch(
256
     dispatch(
245
         registerSound(PARTICIPANT_JOINED_SOUND_ID, PARTICIPANT_JOINED_FILE));
257
         registerSound(PARTICIPANT_JOINED_SOUND_ID, PARTICIPANT_JOINED_FILE));
246
-    dispatch(
247
-        registerSound(PARTICIPANT_LEFT_SOUND_ID, PARTICIPANT_LEFT_FILE));
258
+    dispatch(registerSound(PARTICIPANT_LEFT_SOUND_ID, PARTICIPANT_LEFT_FILE));
248
 }
259
 }
249
 
260
 
250
 /**
261
 /**
251
  * Unregisters sounds related with the participants feature.
262
  * Unregisters sounds related with the participants feature.
252
  *
263
  *
253
- * @param {Store} store - The Redux store.
264
+ * @param {Store} store - The redux store.
254
  * @private
265
  * @private
255
  * @returns {void}
266
  * @returns {void}
256
  */
267
  */
257
 function _unregisterSounds({ dispatch }) {
268
 function _unregisterSounds({ dispatch }) {
258
-    dispatch(
259
-        unregisterSound(PARTICIPANT_JOINED_SOUND_ID));
260
-    dispatch(
261
-        unregisterSound(PARTICIPANT_LEFT_SOUND_ID));
269
+    dispatch(unregisterSound(PARTICIPANT_JOINED_SOUND_ID));
270
+    dispatch(unregisterSound(PARTICIPANT_LEFT_SOUND_ID));
262
 }
271
 }

Загрузка…
Отмена
Сохранить