Browse Source

Protect against late PARTICIPANT_JOINED

Like the preceding commit "ref(base/conference): clear the 'conference'
field on WILL_LEAVE", this commit is part of the story how we are to
deal with conferences which take noticeable time to leave.

If a leave is delayed and the leaving JitsiConference manages to sneak a
PARTICIPANT_JOINED in, it may create a remote participant who even
collides with the local participant.
master
Lyubo Marinov 7 years ago
parent
commit
8cfc83f18c
1 changed files with 30 additions and 4 deletions
  1. 30
    4
      react/features/base/participants/actions.js

+ 30
- 4
react/features/base/participants/actions.js View File

@@ -235,14 +235,40 @@ export function participantDisplayNameChanged(id, displayName = '') {
235 235
  * }}
236 236
  */
237 237
 export function participantJoined(participant) {
238
-    if (!participant.local && !participant.conference) {
238
+    // Only the local participant is not identified with an id-conference pair.
239
+    if (participant.local) {
240
+        return {
241
+            type: PARTICIPANT_JOINED,
242
+            participant
243
+        };
244
+    }
245
+
246
+    // In other words, a remote participant is identified with an id-conference
247
+    // pair.
248
+    const { conference } = participant;
249
+
250
+    if (!conference) {
239 251
         throw Error(
240 252
             'A remote participant must be associated with a JitsiConference!');
241 253
     }
242 254
 
243
-    return {
244
-        type: PARTICIPANT_JOINED,
245
-        participant
255
+    return (dispatch, getState) => {
256
+        // A remote participant is only expected to join in a joined or joining
257
+        // conference. The following check is really necessary because a
258
+        // JitsiConference may have moved into leaving but may still manage to
259
+        // sneak a PARTICIPANT_JOINED in if its leave is delayed for any purpose
260
+        // (which is not outragous given that leaving involves network
261
+        // requests.)
262
+        const stateFeaturesBaseConference
263
+            = getState()['features/base/conference'];
264
+
265
+        if (conference === stateFeaturesBaseConference.conference
266
+                || conference === stateFeaturesBaseConference.joining) {
267
+            return dispatch({
268
+                type: PARTICIPANT_JOINED,
269
+                participant
270
+            });
271
+        }
246 272
     };
247 273
 }
248 274
 

Loading…
Cancel
Save