|
@@ -61,7 +61,7 @@ const DEFAULT_STATE = {
|
61
|
61
|
pinnedParticipant: undefined,
|
62
|
62
|
remote: new Map(),
|
63
|
63
|
sortedRemoteParticipants: new Map(),
|
64
|
|
- speakersList: []
|
|
64
|
+ speakersList: new Map()
|
65
|
65
|
};
|
66
|
66
|
|
67
|
67
|
/**
|
|
@@ -96,12 +96,28 @@ ReducerRegistry.register('features/base/participants', (state = DEFAULT_STATE, a
|
96
|
96
|
case DOMINANT_SPEAKER_CHANGED: {
|
97
|
97
|
const { participant } = action;
|
98
|
98
|
const { id, previousSpeakers = [] } = participant;
|
99
|
|
- const { dominantSpeaker, local } = state;
|
100
|
|
- const speakersList = [];
|
|
99
|
+ const { dominantSpeaker, local, speakersList } = state;
|
|
100
|
+ const newSpeakers = [ id, ...previousSpeakers ];
|
|
101
|
+ const sortedSpeakersList = Array.from(speakersList);
|
101
|
102
|
|
102
|
103
|
// Update the speakers list.
|
103
|
|
- id !== local?.id && speakersList.push(id);
|
104
|
|
- speakersList.push(...previousSpeakers.filter(p => p !== local?.id));
|
|
104
|
+ for (const speaker of newSpeakers) {
|
|
105
|
+ if (!state.speakersList.has(speaker) && speaker !== local?.id) {
|
|
106
|
+ const remoteParticipant = state.remote.get(speaker);
|
|
107
|
+
|
|
108
|
+ remoteParticipant && sortedSpeakersList.push([ speaker, _getDisplayName(remoteParticipant.name) ]);
|
|
109
|
+ }
|
|
110
|
+ }
|
|
111
|
+
|
|
112
|
+ // Also check if any of the existing speakers have been kicked off the list.
|
|
113
|
+ for (const existingSpeaker of sortedSpeakersList.keys()) {
|
|
114
|
+ if (!newSpeakers.find(s => s === existingSpeaker)) {
|
|
115
|
+ sortedSpeakersList.filter(sortedSpeaker => sortedSpeaker[0] !== existingSpeaker);
|
|
116
|
+ }
|
|
117
|
+ }
|
|
118
|
+
|
|
119
|
+ // Keep the remote speaker list sorted alphabetically.
|
|
120
|
+ sortedSpeakersList.sort((a, b) => a[1].localeCompare(b[1]));
|
105
|
121
|
|
106
|
122
|
// Only one dominant speaker is allowed.
|
107
|
123
|
if (dominantSpeaker) {
|
|
@@ -112,7 +128,7 @@ ReducerRegistry.register('features/base/participants', (state = DEFAULT_STATE, a
|
112
|
128
|
return {
|
113
|
129
|
...state,
|
114
|
130
|
dominantSpeaker: id,
|
115
|
|
- speakersList
|
|
131
|
+ speakersList: new Map(sortedSpeakersList)
|
116
|
132
|
};
|
117
|
133
|
}
|
118
|
134
|
|
|
@@ -227,8 +243,7 @@ ReducerRegistry.register('features/base/participants', (state = DEFAULT_STATE, a
|
227
|
243
|
state.remote.set(id, participant);
|
228
|
244
|
|
229
|
245
|
// Insert the new participant.
|
230
|
|
- const displayName = name
|
231
|
|
- ?? (typeof interfaceConfig === 'object' ? interfaceConfig.DEFAULT_REMOTE_DISPLAY_NAME : 'Fellow Jitser');
|
|
246
|
+ const displayName = _getDisplayName(name);
|
232
|
247
|
const sortedRemoteParticipants = Array.from(state.sortedRemoteParticipants);
|
233
|
248
|
|
234
|
249
|
sortedRemoteParticipants.push([ id, displayName ]);
|
|
@@ -297,7 +312,7 @@ ReducerRegistry.register('features/base/participants', (state = DEFAULT_STATE, a
|
297
|
312
|
}
|
298
|
313
|
|
299
|
314
|
// Remove the participant from the list of speakers.
|
300
|
|
- state.speakersList = state.speakersList.filter(speaker => speaker !== id);
|
|
315
|
+ state.speakersList.has(id) && state.speakersList.delete(id);
|
301
|
316
|
|
302
|
317
|
if (pinnedParticipant === id) {
|
303
|
318
|
state.pinnedParticipant = undefined;
|
|
@@ -314,6 +329,17 @@ ReducerRegistry.register('features/base/participants', (state = DEFAULT_STATE, a
|
314
|
329
|
return state;
|
315
|
330
|
});
|
316
|
331
|
|
|
332
|
+/**
|
|
333
|
+ * Returns the participant's display name, default string if display name is not set on the participant.
|
|
334
|
+ *
|
|
335
|
+ * @param {string} name - The display name of the participant.
|
|
336
|
+ * @returns {string}
|
|
337
|
+ */
|
|
338
|
+ function _getDisplayName(name) {
|
|
339
|
+ return name
|
|
340
|
+ ?? (typeof interfaceConfig === 'object' ? interfaceConfig.DEFAULT_REMOTE_DISPLAY_NAME : 'Fellow Jitser');
|
|
341
|
+}
|
|
342
|
+
|
317
|
343
|
/**
|
318
|
344
|
* Loops trough the participants in the state in order to check if all participants are moderators.
|
319
|
345
|
*
|
|
@@ -335,32 +361,6 @@ function _isEveryoneModerator(state) {
|
335
|
361
|
return false;
|
336
|
362
|
}
|
337
|
363
|
|
338
|
|
-
|
339
|
|
-/**
|
340
|
|
- * Updates a specific property for a participant.
|
341
|
|
- *
|
342
|
|
- * @param {State} state - The redux state.
|
343
|
|
- * @param {string} id - The ID of the participant.
|
344
|
|
- * @param {string} property - The property to update.
|
345
|
|
- * @param {*} value - The new value.
|
346
|
|
- * @returns {boolean} - True if a participant was updated and false otherwise.
|
347
|
|
- */
|
348
|
|
-function _updateParticipantProperty(state, id, property, value) {
|
349
|
|
- const { remote, local } = state;
|
350
|
|
-
|
351
|
|
- if (remote.has(id)) {
|
352
|
|
- remote.set(id, set(remote.get(id), property, value));
|
353
|
|
-
|
354
|
|
- return true;
|
355
|
|
- } else if (local?.id === id) {
|
356
|
|
- state.local = set(local, property, value);
|
357
|
|
-
|
358
|
|
- return true;
|
359
|
|
- }
|
360
|
|
-
|
361
|
|
- return false;
|
362
|
|
-}
|
363
|
|
-
|
364
|
364
|
/**
|
365
|
365
|
* Reducer function for a single participant.
|
366
|
366
|
*
|
|
@@ -458,3 +458,28 @@ function _participantJoined({ participant }) {
|
458
|
458
|
role: role || PARTICIPANT_ROLE.NONE
|
459
|
459
|
};
|
460
|
460
|
}
|
|
461
|
+
|
|
462
|
+/**
|
|
463
|
+ * Updates a specific property for a participant.
|
|
464
|
+ *
|
|
465
|
+ * @param {State} state - The redux state.
|
|
466
|
+ * @param {string} id - The ID of the participant.
|
|
467
|
+ * @param {string} property - The property to update.
|
|
468
|
+ * @param {*} value - The new value.
|
|
469
|
+ * @returns {boolean} - True if a participant was updated and false otherwise.
|
|
470
|
+ */
|
|
471
|
+ function _updateParticipantProperty(state, id, property, value) {
|
|
472
|
+ const { remote, local } = state;
|
|
473
|
+
|
|
474
|
+ if (remote.has(id)) {
|
|
475
|
+ remote.set(id, set(remote.get(id), property, value));
|
|
476
|
+
|
|
477
|
+ return true;
|
|
478
|
+ } else if (local?.id === id) {
|
|
479
|
+ state.local = set(local, property, value);
|
|
480
|
+
|
|
481
|
+ return true;
|
|
482
|
+ }
|
|
483
|
+
|
|
484
|
+ return false;
|
|
485
|
+}
|