Browse Source

Added emailChange listener to API

j8
akshitkrnagpal 7 years ago
parent
commit
20444adbc9
4 changed files with 58 additions and 2 deletions
  1. 5
    2
      conference.js
  2. 14
    0
      doc/api.md
  3. 18
    0
      modules/API/API.js
  4. 21
    0
      modules/API/external/external_api.js

+ 5
- 2
conference.js View File

@@ -1955,7 +1955,8 @@ export default {
1955 1955
             }
1956 1956
         );
1957 1957
 
1958
-        APP.UI.addListener(UIEvents.EMAIL_CHANGED, this.changeLocalEmail);
1958
+        APP.UI.addListener(UIEvents.EMAIL_CHANGED,
1959
+            this.changeLocalEmail.bind(this));
1959 1960
         room.addCommandListener(this.commands.defaults.EMAIL, (data, from) => {
1960 1961
             APP.store.dispatch(participantUpdated({
1961 1962
                 conference: room,
@@ -2537,7 +2538,9 @@ export default {
2537 2538
         APP.store.dispatch(updateSettings({
2538 2539
             email: formattedEmail
2539 2540
         }));
2540
-
2541
+        APP.API.notifyEmailChanged(localId, {
2542
+            email: formattedEmail
2543
+        });
2541 2544
         sendData(commands.EMAIL, formattedEmail);
2542 2545
     },
2543 2546
 

+ 14
- 0
doc/api.md View File

@@ -194,6 +194,15 @@ changes. The listener will receive an object with the following structure:
194 194
 }
195 195
 ```
196 196
 
197
+* **emailChange** - event notifications about email
198
+changes. The listener will receive an object with the following structure:
199
+```javascript
200
+{
201
+"id": id, // the id of the participant that changed his email
202
+"email": email // the new email
203
+}
204
+```
205
+
197 206
 * **participantJoined** - event notifications about new participants who join the room. The listener will receive an object with the following structure:
198 207
 ```javascript
199 208
 {
@@ -290,6 +299,11 @@ You can get the display name of a participant in the conference with the followi
290 299
 var displayName = api.getDisplayName(participantId);
291 300
 ```
292 301
 
302
+You can get the email of a participant in the conference with the following API function:
303
+```javascript
304
+var email = api.getEmail(participantId);
305
+```
306
+
293 307
 You can get the iframe HTML element where Jitsi Meet is loaded with the following API function:
294 308
 ```javascript
295 309
 var iframe = api.getIFrame();

+ 18
- 0
modules/API/API.js View File

@@ -363,6 +363,24 @@ class API {
363 363
         });
364 364
     }
365 365
 
366
+    /**
367
+     * Notify external application (if API is enabled) that user changed their
368
+     * email.
369
+     *
370
+     * @param {string} id - User id.
371
+     * @param {string} email - The new email of the participant.
372
+     * @returns {void}
373
+     */
374
+    notifyEmailChanged(
375
+            id: string,
376
+            { email }: Object) {
377
+        this._sendEvent({
378
+            name: 'email-change',
379
+            email,
380
+            id
381
+        });
382
+    }
383
+
366 384
     /**
367 385
      * Notify external application (if API is enabled) that the conference has
368 386
      * been joined.

+ 21
- 0
modules/API/external/external_api.js View File

@@ -40,6 +40,7 @@ const events = {
40 40
     'audio-availability-changed': 'audioAvailabilityChanged',
41 41
     'audio-mute-status-changed': 'audioMuteStatusChanged',
42 42
     'display-name-change': 'displayNameChange',
43
+    'email-change': 'emailChange',
43 44
     'feedback-submitted': 'feedbackSubmitted',
44 45
     'incoming-message': 'incomingMessage',
45 46
     'outgoing-message': 'outgoingMessage',
@@ -398,6 +399,14 @@ export default class JitsiMeetExternalAPI extends EventEmitter {
398 399
                 }
399 400
                 break;
400 401
             }
402
+            case 'email-change': {
403
+                const user = this._participants[userID];
404
+
405
+                if (user) {
406
+                    user.email = data.email;
407
+                }
408
+                break;
409
+            }
401 410
             case 'avatar-changed': {
402 411
                 const user = this._participants[userID];
403 412
 
@@ -633,6 +642,18 @@ export default class JitsiMeetExternalAPI extends EventEmitter {
633 642
         return displayName;
634 643
     }
635 644
 
645
+    /**
646
+     * Returns the email of a participant.
647
+     *
648
+     * @param {string} participantId - The id of the participant.
649
+     * @returns {string} The email.
650
+     */
651
+    getEmail(participantId) {
652
+        const { email } = this._participants[participantId] || {};
653
+
654
+        return email;
655
+    }
656
+
636 657
     /**
637 658
      * Returns the formatted display name of a participant.
638 659
      *

Loading…
Cancel
Save