Bladeren bron

share user email through commands

master
isymchych 10 jaren geleden
bovenliggende
commit
272cfea493

+ 25
- 11
app.js Bestand weergeven

14
 require("autosize");
14
 require("autosize");
15
 
15
 
16
 var Commands = {
16
 var Commands = {
17
-    CONNECTION_QUALITY: "connectionQuality"
17
+    CONNECTION_QUALITY: "connectionQuality",
18
+    EMAIL: "email"
18
 };
19
 };
19
 
20
 
20
 function createConference(connection, room) {
21
 function createConference(connection, room) {
39
         },
40
         },
40
 
41
 
41
         setNickname: function (nickname) {
42
         setNickname: function (nickname) {
42
-            // FIXME check if room is available etc.
43
             APP.settings.setDisplayName(nickname);
43
             APP.settings.setDisplayName(nickname);
44
             room.setDisplayName(nickname);
44
             room.setDisplayName(nickname);
45
         },
45
         },
46
 
46
 
47
-        setEmail: function (email) {
48
-            // FIXME room.setEmail
49
-        },
50
-
51
         setStartMuted: function (audio, video) {
47
         setStartMuted: function (audio, video) {
52
             // FIXME room.setStartMuted
48
             // FIXME room.setStartMuted
53
         },
49
         },
264
         }
260
         }
265
     );
261
     );
266
 
262
 
263
+     // share email with other users
264
+    function sendEmail(email) {
265
+        room.sendCommand(Commands.EMAIL, {
266
+            value: email,
267
+            attributes: {
268
+                id: room.myUserId()
269
+            }
270
+        });
271
+    }
272
+
273
+    APP.UI.addListener(UIEvents.EMAIL_CHANGED, function (email) {
274
+        APP.settings.setEmail(email);
275
+        APP.UI.setUserAvatar(room.myUserId(), data.value);
276
+        sendEmail(email);
277
+    });
278
+    var email = APP.settings.getEmail();
279
+    if (email) {
280
+        sendEmail(APP.settings.getEmail());
281
+    }
282
+    room.addCommandListener(Commands.EMAIL, function (data) {
283
+        APP.UI.setUserAvatar(data.attributes.id, data.value);
284
+    });
285
+
267
     return new Promise(function (resolve, reject) {
286
     return new Promise(function (resolve, reject) {
268
         room.on(
287
         room.on(
269
             ConferenceEvents.CONFERENCE_JOINED,
288
             ConferenceEvents.CONFERENCE_JOINED,
318
             APP.settings.setLanguage(language);
337
             APP.settings.setLanguage(language);
319
         });
338
         });
320
 
339
 
321
-        APP.UI.addListener(UIEvents.EMAIL_CHANGED, function (email) {
322
-            APP.conference.setEmail(email);
323
-            APP.settings.setEmail(email);
324
-        });
325
-
326
         APP.UI.addListener(
340
         APP.UI.addListener(
327
             UIEvents.START_MUTED_CHANGED,
341
             UIEvents.START_MUTED_CHANGED,
328
             function (startAudioMuted, startVideoMuted) {
342
             function (startAudioMuted, startVideoMuted) {

+ 21
- 16
modules/UI/UI.js Bestand weergeven

135
     VideoLayout.onDisplayNameChanged(id, displayName);
135
     VideoLayout.onDisplayNameChanged(id, displayName);
136
 };
136
 };
137
 
137
 
138
-UI.initConference = function (jid) {
138
+UI.initConference = function (id) {
139
     Toolbar.updateRoomUrl(window.location.href);
139
     Toolbar.updateRoomUrl(window.location.href);
140
     var meHTML = APP.translation.generateTranslationHTML("me");
140
     var meHTML = APP.translation.generateTranslationHTML("me");
141
-    var localId = APP.conference.localId();
142
-    $("#localNick").html(localId + " (" + meHTML + ")");
143
-
144
     var settings = Settings.getSettings();
141
     var settings = Settings.getSettings();
145
 
142
 
143
+    $("#localNick").html(settings.email || settings.uid + " (" + meHTML + ")");
144
+
146
     // Make sure we configure our avatar id, before creating avatar for us
145
     // Make sure we configure our avatar id, before creating avatar for us
147
-    Avatar.setUserAvatar(jid, settings.email || settings.uid);
146
+    UI.setUserAvatar(id, settings.email || settings.uid);
148
 
147
 
149
     // Add myself to the contact list.
148
     // Add myself to the contact list.
150
-    ContactList.addContact(jid);
149
+    ContactList.addContact(id);
151
 
150
 
152
     // Once we've joined the muc show the toolbar
151
     // Once we've joined the muc show the toolbar
153
     ToolbarToggler.showToolbar();
152
     ToolbarToggler.showToolbar();
154
 
153
 
155
-    var displayName = config.displayJids ? localId : settings.displayName;
154
+    var displayName = config.displayJids ? id : settings.displayName;
156
 
155
 
157
     if (displayName) {
156
     if (displayName) {
158
         UI.changeDisplayName('localVideoContainer', displayName);
157
         UI.changeDisplayName('localVideoContainer', displayName);
173
     });
172
     });
174
 
173
 
175
     UI.addListener(UIEvents.EMAIL_CHANGED, function (email) {
174
     UI.addListener(UIEvents.EMAIL_CHANGED, function (email) {
176
-        Avatar.setUserAvatar(APP.xmpp.myJid(), email);
175
+        UI.setUserAvatar(APP.conference.localId(), email);
177
     });
176
     });
178
 }
177
 }
179
 
178
 
382
 }
381
 }
383
 
382
 
384
 UI.addUser = function (jid, id, displayName) {
383
 UI.addUser = function (jid, id, displayName) {
385
-    messageHandler.notify(displayName,'notify.somebody',
386
-        'connected',
387
-        'notify.connected');
384
+    messageHandler.notify(
385
+        displayName,'notify.somebody', 'connected', 'notify.connected'
386
+    );
388
 
387
 
389
     if (!config.startAudioMuted ||
388
     if (!config.startAudioMuted ||
390
         config.startAudioMuted > APP.members.size())
389
         config.startAudioMuted > APP.members.size())
391
         UIUtil.playSoundNotification('userJoined');
390
         UIUtil.playSoundNotification('userJoined');
392
 
391
 
393
     // Configure avatar
392
     // Configure avatar
394
-    Avatar.setUserAvatar(jid, id);
393
+    UI.setUserAvatar(jid, id);
395
 
394
 
396
     // Add Peer's container
395
     // Add Peer's container
397
     VideoLayout.ensurePeerContainerExists(jid);
396
     VideoLayout.ensurePeerContainerExists(jid);
599
     return ToolbarToggler.dockToolbar(isDock);
598
     return ToolbarToggler.dockToolbar(isDock);
600
 };
599
 };
601
 
600
 
602
-UI.userAvatarChanged = function (resourceJid, thumbUrl, contactListUrl) {
603
-    VideoLayout.userAvatarChanged(resourceJid, thumbUrl);
604
-    ContactList.userAvatarChanged(resourceJid, contactListUrl);
605
-    if(resourceJid === APP.xmpp.myResource()) {
601
+UI.setUserAvatar = function (id, email) {
602
+    // update avatar
603
+    Avatar.setUserAvatar(id, email);
604
+
605
+    var thumbUrl = Avatar.getThumbUrl(id);
606
+    var contactListUrl = Avatar.getContactListUrl(id);
607
+
608
+    VideoLayout.changeUserAvatar(id, thumbUrl);
609
+    ContactList.changeUserAvatar(id, contactListUrl);
610
+    if (APP.conference.isLocalId(id)) {
606
         SettingsMenu.changeAvatar(thumbUrl);
611
         SettingsMenu.changeAvatar(thumbUrl);
607
     }
612
     }
608
 };
613
 };

+ 27
- 31
modules/UI/avatar/Avatar.js Bestand weergeven

1
-/* global Strophe, APP, MD5 */
2
-var Settings = require("../../settings/Settings");
3
-
1
+/* global MD5 */
4
 var users = {};
2
 var users = {};
5
 
3
 
6
 var Avatar = {
4
 var Avatar = {
8
     /**
6
     /**
9
      * Sets the user's avatar in the settings menu(if local user), contact list
7
      * Sets the user's avatar in the settings menu(if local user), contact list
10
      * and thumbnail
8
      * and thumbnail
11
-     * @param jid jid of the user
12
-     * @param id email or userID to be used as a hash
9
+     * @param id id of the user
10
+     * @param email email or nickname to be used as a hash
13
      */
11
      */
14
-    setUserAvatar: function (jid, id) {
15
-        if (id) {
16
-            if (users[jid] === id) {
12
+  setUserAvatar: function (id, email) {
13
+        if (email) {
14
+            if (users[id] === email) {
17
                 return;
15
                 return;
18
             }
16
             }
19
-            users[jid] = id;
17
+            users[id] = email;
20
         }
18
         }
21
-        var thumbUrl = this.getThumbUrl(jid);
22
-        var contactListUrl = this.getContactListUrl(jid);
23
-        var resourceJid = Strophe.getResourceFromJid(jid);
24
-
25
-        APP.UI.userAvatarChanged(resourceJid, thumbUrl, contactListUrl);
19
+        var thumbUrl = this.getThumbUrl(id);
20
+        var contactListUrl = this.getContactListUrl(id);
26
     },
21
     },
27
     /**
22
     /**
28
      * Returns image URL for the avatar to be displayed on large video area
23
      * Returns image URL for the avatar to be displayed on large video area
29
      * where current active speaker is presented.
24
      * where current active speaker is presented.
30
-     * @param jid full MUC jid of the user for whom we want to obtain avatar URL
25
+     * @param id id of the user for whom we want to obtain avatar URL
31
      */
26
      */
32
-    getActiveSpeakerUrl: function (jid) {
33
-        return this.getGravatarUrl(jid, 100);
27
+    getActiveSpeakerUrl: function (id) {
28
+        return this.getGravatarUrl(id, 100);
34
     },
29
     },
35
     /**
30
     /**
36
      * Returns image URL for the avatar to be displayed on small video thumbnail
31
      * Returns image URL for the avatar to be displayed on small video thumbnail
37
-     * @param jid full MUC jid of the user for whom we want to obtain avatar URL
32
+     * @param id id of the user for whom we want to obtain avatar URL
38
      */
33
      */
39
-    getThumbUrl: function (jid) {
40
-        return this.getGravatarUrl(jid, 100);
34
+    getThumbUrl: function (id) {
35
+        return this.getGravatarUrl(id, 100);
41
     },
36
     },
42
     /**
37
     /**
43
      * Returns the URL for the avatar to be displayed as contactlist item
38
      * Returns the URL for the avatar to be displayed as contactlist item
44
-     * @param jid full MUC jid of the user for whom we want to obtain avatar URL
39
+     * @param id id of the user for whom we want to obtain avatar URL
45
      */
40
      */
46
-    getContactListUrl: function (jid) {
47
-        return this.getGravatarUrl(jid, 30);
41
+    getContactListUrl: function (id) {
42
+        return this.getGravatarUrl(id, 30);
48
     },
43
     },
49
-    getGravatarUrl: function (jid, size) {
50
-        if (!jid) {
51
-            console.error("Get gravatar - jid is undefined");
44
+    getGravatarUrl: function (id, size) {
45
+        if (!id) {
46
+            console.error("Get gravatar - id is undefined");
52
             return null;
47
             return null;
53
         }
48
         }
54
-        var id = users[jid];
55
-        if (!id) {
49
+        var email = users[id];
50
+        if (!email) {
56
             console.warn(
51
             console.warn(
57
-                "No avatar stored yet for " + jid + " - using JID as ID");
58
-            id = jid;
52
+                "No avatar stored yet for " + id + " - using user id as ID"
53
+            );
54
+            email = id;
59
         }
55
         }
60
         return 'https://www.gravatar.com/avatar/' +
56
         return 'https://www.gravatar.com/avatar/' +
61
-            MD5.hexdigest(id.trim().toLowerCase()) +
57
+            MD5.hexdigest(email.trim().toLowerCase()) +
62
             "?d=wavatar&size=" + (size || "30");
58
             "?d=wavatar&size=" + (size || "30");
63
     }
59
     }
64
 
60
 

+ 2
- 2
modules/UI/side_pannels/contactlist/ContactList.js Bestand weergeven

180
         }
180
         }
181
     },
181
     },
182
 
182
 
183
-    userAvatarChanged: function (resourceJid, contactListUrl) {
183
+    changeUserAvatar: function (id, contactListUrl) {
184
         // set the avatar in the contact list
184
         // set the avatar in the contact list
185
-        var contact = $('#' + resourceJid + '>img');
185
+        var contact = $('#' + id + '>img');
186
         if (contact && contact.length > 0) {
186
         if (contact && contact.length > 0) {
187
             contact.get(0).src = contactListUrl;
187
             contact.get(0).src = contactListUrl;
188
         }
188
         }

+ 8
- 6
modules/UI/videolayout/VideoLayout.js Bestand weergeven

1001
         }
1001
         }
1002
     };
1002
     };
1003
 
1003
 
1004
-    my.userAvatarChanged = function(resourceJid, thumbUrl) {
1005
-        var smallVideo = VideoLayout.getSmallVideo(resourceJid);
1006
-        if(smallVideo)
1004
+    my.changeUserAvatar = function(id, thumbUrl) {
1005
+        var smallVideo = VideoLayout.getSmallVideo(id);
1006
+        if (smallVideo) {
1007
             smallVideo.avatarChanged(thumbUrl);
1007
             smallVideo.avatarChanged(thumbUrl);
1008
-        else
1008
+        } else {
1009
             console.warn(
1009
             console.warn(
1010
-                "Missed avatar update - no small video yet for " + resourceJid);
1011
-        LargeVideo.updateAvatar(resourceJid, thumbUrl);
1010
+                "Missed avatar update - no small video yet for " + id
1011
+            );
1012
+        }
1013
+        LargeVideo.updateAvatar(id, thumbUrl);
1012
     };
1014
     };
1013
 
1015
 
1014
     my.createEtherpadIframe = function(src, onloadHandler)
1016
     my.createEtherpadIframe = function(src, onloadHandler)

+ 4
- 0
modules/settings/Settings.js Bestand weergeven

87
         return email;
87
         return email;
88
     },
88
     },
89
 
89
 
90
+    getEmail: function () {
91
+        return email;
92
+    },
93
+
90
     getSettings: function () {
94
     getSettings: function () {
91
         return {
95
         return {
92
             email: email,
96
             email: email,

Laden…
Annuleren
Opslaan