Browse Source

e2ee: broadcast e2ee enabled status using presnce

master
Saúl Ibarra Corretgé 5 years ago
parent
commit
2ad6bfbc20
2 changed files with 53 additions and 12 deletions
  1. 42
    11
      react/features/base/participants/middleware.js
  2. 11
    1
      react/features/e2ee/middleware.js

+ 42
- 11
react/features/base/participants/middleware.js View File

196
                 JitsiConferenceEvents.PARTICIPANT_PROPERTY_CHANGED,
196
                 JitsiConferenceEvents.PARTICIPANT_PROPERTY_CHANGED,
197
                 (participant, propertyName, oldValue, newValue) => {
197
                 (participant, propertyName, oldValue, newValue) => {
198
                     switch (propertyName) {
198
                     switch (propertyName) {
199
+                    case 'e2eeEnabled':
200
+                        _e2eeUpdated(store, conference, participant.getId(), newValue);
201
+                        break;
199
                     case 'features_e2ee':
202
                     case 'features_e2ee':
200
                         store.dispatch(participantUpdated({
203
                         store.dispatch(participantUpdated({
201
                             conference,
204
                             conference,
218
                         }));
221
                         }));
219
                         break;
222
                         break;
220
                     case 'raisedHand': {
223
                     case 'raisedHand': {
221
-                        _raiseHandUpdated(
222
-                            store, conference, participant.getId(), newValue);
224
+                        _raiseHandUpdated(store, conference, participant.getId(), newValue);
223
                         break;
225
                         break;
224
                     }
226
                     }
225
                     default:
227
                     default:
229
 
231
 
230
                 });
232
                 });
231
         } else {
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
  * Initializes the local participant and signals that it joined.
263
  * Initializes the local participant and signals that it joined.
241
  *
264
  *
331
  * @returns {Object} The value returned by {@code next(action)}.
354
  * @returns {Object} The value returned by {@code next(action)}.
332
  */
355
  */
333
 function _participantJoinedOrUpdated({ dispatch, getState }, next, action) {
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
     // Send an external update of the local participant's raised hand state
359
     // Send an external update of the local participant's raised hand state
337
     // if a new raised hand state is defined in the action.
360
     // if a new raised hand state is defined in the 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
     // Allow the redux update to go through and compare the old avatar
382
     // Allow the redux update to go through and compare the old avatar
350
     // to the new avatar and emit out change events if necessary.
383
     // to the new avatar and emit out change events if necessary.
351
     const result = next(action);
384
     const result = next(action);
378
  *
411
  *
379
  * @param {Function} dispatch - The Redux dispatch function.
412
  * @param {Function} dispatch - The Redux dispatch function.
380
  * @param {Object} conference - The conference for which we got an update.
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
  * @param {boolean} newValue - The new value of the raise hand status.
415
  * @param {boolean} newValue - The new value of the raise hand status.
384
  * @returns {void}
416
  * @returns {void}
385
  */
417
  */
386
 function _raiseHandUpdated({ dispatch, getState }, conference, participantId, newValue) {
418
 function _raiseHandUpdated({ dispatch, getState }, conference, participantId, newValue) {
387
     const raisedHand = newValue === 'true';
419
     const raisedHand = newValue === 'true';
388
-    const pid = participantId || getLocalParticipant(getState()).id;
389
 
420
 
390
     dispatch(participantUpdated({
421
     dispatch(participantUpdated({
391
         conference,
422
         conference,
392
-        id: pid,
423
+        id: participantId,
393
         raisedHand
424
         raisedHand
394
     }));
425
     }));
395
 
426
 
396
     if (raisedHand) {
427
     if (raisedHand) {
397
         dispatch(showNotification({
428
         dispatch(showNotification({
398
             titleArguments: {
429
             titleArguments: {
399
-                name: getParticipantDisplayName(getState, pid)
430
+                name: getParticipantDisplayName(getState, participantId)
400
             },
431
             },
401
             titleKey: 'notify.raisedHand'
432
             titleKey: 'notify.raisedHand'
402
         }, NOTIFICATION_TIMEOUT));
433
         }, NOTIFICATION_TIMEOUT));

+ 11
- 1
react/features/e2ee/middleware.js View File

1
 // @flow
1
 // @flow
2
 
2
 
3
 import { getCurrentConference } from '../base/conference';
3
 import { getCurrentConference } from '../base/conference';
4
+import { getLocalParticipant, participantUpdated } from '../base/participants';
4
 import { MiddlewareRegistry, StateListenerRegistry } from '../base/redux';
5
 import { MiddlewareRegistry, StateListenerRegistry } from '../base/redux';
5
 
6
 
6
 import { SET_E2EE_KEY } from './actionTypes';
7
 import { SET_E2EE_KEY } from './actionTypes';
13
  * @param {Store} store - The redux store.
14
  * @param {Store} store - The redux store.
14
  * @returns {Function}
15
  * @returns {Function}
15
  */
16
  */
16
-MiddlewareRegistry.register(({ getState }) => next => action => {
17
+MiddlewareRegistry.register(({ dispatch, getState }) => next => action => {
17
     switch (action.type) {
18
     switch (action.type) {
18
     case SET_E2EE_KEY: {
19
     case SET_E2EE_KEY: {
19
         const conference = getCurrentConference(getState);
20
         const conference = getCurrentConference(getState);
21
         if (conference) {
22
         if (conference) {
22
             logger.debug(`New E2EE key: ${action.key}`);
23
             logger.debug(`New E2EE key: ${action.key}`);
23
             conference.setE2EEKey(action.key);
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
         break;
36
         break;

Loading…
Cancel
Save