Procházet zdrojové kódy

e2ee: broadcast e2ee enabled status using presnce

master
Saúl Ibarra Corretgé před 5 roky
rodič
revize
2ad6bfbc20

+ 42
- 11
react/features/base/participants/middleware.js Zobrazit soubor

@@ -196,6 +196,9 @@ StateListenerRegistry.register(
196 196
                 JitsiConferenceEvents.PARTICIPANT_PROPERTY_CHANGED,
197 197
                 (participant, propertyName, oldValue, newValue) => {
198 198
                     switch (propertyName) {
199
+                    case 'e2eeEnabled':
200
+                        _e2eeUpdated(store, conference, participant.getId(), newValue);
201
+                        break;
199 202
                     case 'features_e2ee':
200 203
                         store.dispatch(participantUpdated({
201 204
                             conference,
@@ -218,8 +221,7 @@ StateListenerRegistry.register(
218 221
                         }));
219 222
                         break;
220 223
                     case 'raisedHand': {
221
-                        _raiseHandUpdated(
222
-                            store, conference, participant.getId(), newValue);
224
+                        _raiseHandUpdated(store, conference, participant.getId(), newValue);
223 225
                         break;
224 226
                     }
225 227
                     default:
@@ -229,13 +231,34 @@ StateListenerRegistry.register(
229 231
 
230 232
                 });
231 233
         } else {
232
-            // We left the conference, raise hand of the local participant must be updated.
233
-            _raiseHandUpdated(
234
-                store, conference, undefined, false);
234
+            const localParticipantId = getLocalParticipant(store.getState).getId();
235
+
236
+            // We left the conference, the local participant must be updated.
237
+            _e2eeUpdated(store, conference, localParticipantId, false);
238
+            _raiseHandUpdated(store, conference, localParticipantId, false);
235 239
         }
236 240
     }
237 241
 );
238 242
 
243
+/**
244
+ * Handles a E2EE enabled status update.
245
+ *
246
+ * @param {Function} dispatch - The Redux dispatch function.
247
+ * @param {Object} conference - The conference for which we got an update.
248
+ * @param {string} participantId - The ID of the participant from which we got an update.
249
+ * @param {boolean} newValue - The new value of the E2EE enabled     status.
250
+ * @returns {void}
251
+ */
252
+function _e2eeUpdated({ dispatch }, conference, participantId, newValue) {
253
+    const e2eeEnabled = newValue === 'true';
254
+
255
+    dispatch(participantUpdated({
256
+        conference,
257
+        id: participantId,
258
+        e2eeEnabled
259
+    }));
260
+}
261
+
239 262
 /**
240 263
  * Initializes the local participant and signals that it joined.
241 264
  *
@@ -331,7 +354,7 @@ function _maybePlaySounds({ getState, dispatch }, action) {
331 354
  * @returns {Object} The value returned by {@code next(action)}.
332 355
  */
333 356
 function _participantJoinedOrUpdated({ dispatch, getState }, next, action) {
334
-    const { participant: { avatarURL, email, id, local, name, raisedHand } } = action;
357
+    const { participant: { avatarURL, e2eeEnabled, email, id, local, name, raisedHand } } = action;
335 358
 
336 359
     // Send an external update of the local participant's raised hand state
337 360
     // if a new raised hand state is defined in the action.
@@ -346,6 +369,16 @@ function _participantJoinedOrUpdated({ dispatch, getState }, next, action) {
346 369
         }
347 370
     }
348 371
 
372
+    // Send an external update of the local participant's E2EE enabled state
373
+    // if a new state is defined in the action.
374
+    if (typeof e2eeEnabled !== 'undefined') {
375
+        if (local) {
376
+            const { conference } = getState()['features/base/conference'];
377
+
378
+            conference && conference.setLocalParticipantProperty('e2eeEnabled', e2eeEnabled);
379
+        }
380
+    }
381
+
349 382
     // Allow the redux update to go through and compare the old avatar
350 383
     // to the new avatar and emit out change events if necessary.
351 384
     const result = next(action);
@@ -378,25 +411,23 @@ function _participantJoinedOrUpdated({ dispatch, getState }, next, action) {
378 411
  *
379 412
  * @param {Function} dispatch - The Redux dispatch function.
380 413
  * @param {Object} conference - The conference for which we got an update.
381
- * @param {string?} participantId - The ID of the participant from which we got an update. If undefined,
382
- * we update the local participant.
414
+ * @param {string} participantId - The ID of the participant from which we got an update.
383 415
  * @param {boolean} newValue - The new value of the raise hand status.
384 416
  * @returns {void}
385 417
  */
386 418
 function _raiseHandUpdated({ dispatch, getState }, conference, participantId, newValue) {
387 419
     const raisedHand = newValue === 'true';
388
-    const pid = participantId || getLocalParticipant(getState()).id;
389 420
 
390 421
     dispatch(participantUpdated({
391 422
         conference,
392
-        id: pid,
423
+        id: participantId,
393 424
         raisedHand
394 425
     }));
395 426
 
396 427
     if (raisedHand) {
397 428
         dispatch(showNotification({
398 429
             titleArguments: {
399
-                name: getParticipantDisplayName(getState, pid)
430
+                name: getParticipantDisplayName(getState, participantId)
400 431
             },
401 432
             titleKey: 'notify.raisedHand'
402 433
         }, NOTIFICATION_TIMEOUT));

+ 11
- 1
react/features/e2ee/middleware.js Zobrazit soubor

@@ -1,6 +1,7 @@
1 1
 // @flow
2 2
 
3 3
 import { getCurrentConference } from '../base/conference';
4
+import { getLocalParticipant, participantUpdated } from '../base/participants';
4 5
 import { MiddlewareRegistry, StateListenerRegistry } from '../base/redux';
5 6
 
6 7
 import { SET_E2EE_KEY } from './actionTypes';
@@ -13,7 +14,7 @@ import logger from './logger';
13 14
  * @param {Store} store - The redux store.
14 15
  * @returns {Function}
15 16
  */
16
-MiddlewareRegistry.register(({ getState }) => next => action => {
17
+MiddlewareRegistry.register(({ dispatch, getState }) => next => action => {
17 18
     switch (action.type) {
18 19
     case SET_E2EE_KEY: {
19 20
         const conference = getCurrentConference(getState);
@@ -21,6 +22,15 @@ MiddlewareRegistry.register(({ getState }) => next => action => {
21 22
         if (conference) {
22 23
             logger.debug(`New E2EE key: ${action.key}`);
23 24
             conference.setE2EEKey(action.key);
25
+
26
+            // Broadccast that we enabled / disabled E2EE.
27
+            const participant = getLocalParticipant(getState);
28
+
29
+            dispatch(participantUpdated({
30
+                e2eeEnabled: Boolean(action.key),
31
+                id: participant.id,
32
+                local: true
33
+            }));
24 34
         }
25 35
 
26 36
         break;

Načítá se…
Zrušit
Uložit