Pārlūkot izejas kodu

share user email through commands

master
isymchych 9 gadus atpakaļ
vecāks
revīzija
272cfea493

+ 25
- 11
app.js Parādīt failu

@@ -14,7 +14,8 @@ require("jQuery-Impromptu");
14 14
 require("autosize");
15 15
 
16 16
 var Commands = {
17
-    CONNECTION_QUALITY: "connectionQuality"
17
+    CONNECTION_QUALITY: "connectionQuality",
18
+    EMAIL: "email"
18 19
 };
19 20
 
20 21
 function createConference(connection, room) {
@@ -39,15 +40,10 @@ function createConference(connection, room) {
39 40
         },
40 41
 
41 42
         setNickname: function (nickname) {
42
-            // FIXME check if room is available etc.
43 43
             APP.settings.setDisplayName(nickname);
44 44
             room.setDisplayName(nickname);
45 45
         },
46 46
 
47
-        setEmail: function (email) {
48
-            // FIXME room.setEmail
49
-        },
50
-
51 47
         setStartMuted: function (audio, video) {
52 48
             // FIXME room.setStartMuted
53 49
         },
@@ -264,6 +260,29 @@ function initConference(connection, roomName) {
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 286
     return new Promise(function (resolve, reject) {
268 287
         room.on(
269 288
             ConferenceEvents.CONFERENCE_JOINED,
@@ -318,11 +337,6 @@ function init() {
318 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 340
         APP.UI.addListener(
327 341
             UIEvents.START_MUTED_CHANGED,
328 342
             function (startAudioMuted, startVideoMuted) {

+ 21
- 16
modules/UI/UI.js Parādīt failu

@@ -135,24 +135,23 @@ UI.changeDisplayName = function (id, displayName) {
135 135
     VideoLayout.onDisplayNameChanged(id, displayName);
136 136
 };
137 137
 
138
-UI.initConference = function (jid) {
138
+UI.initConference = function (id) {
139 139
     Toolbar.updateRoomUrl(window.location.href);
140 140
     var meHTML = APP.translation.generateTranslationHTML("me");
141
-    var localId = APP.conference.localId();
142
-    $("#localNick").html(localId + " (" + meHTML + ")");
143
-
144 141
     var settings = Settings.getSettings();
145 142
 
143
+    $("#localNick").html(settings.email || settings.uid + " (" + meHTML + ")");
144
+
146 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 148
     // Add myself to the contact list.
150
-    ContactList.addContact(jid);
149
+    ContactList.addContact(id);
151 150
 
152 151
     // Once we've joined the muc show the toolbar
153 152
     ToolbarToggler.showToolbar();
154 153
 
155
-    var displayName = config.displayJids ? localId : settings.displayName;
154
+    var displayName = config.displayJids ? id : settings.displayName;
156 155
 
157 156
     if (displayName) {
158 157
         UI.changeDisplayName('localVideoContainer', displayName);
@@ -173,7 +172,7 @@ function registerListeners() {
173 172
     });
174 173
 
175 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,16 +381,16 @@ function onDtmfSupportChanged(dtmfSupport) {
382 381
 }
383 382
 
384 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 388
     if (!config.startAudioMuted ||
390 389
         config.startAudioMuted > APP.members.size())
391 390
         UIUtil.playSoundNotification('userJoined');
392 391
 
393 392
     // Configure avatar
394
-    Avatar.setUserAvatar(jid, id);
393
+    UI.setUserAvatar(jid, id);
395 394
 
396 395
     // Add Peer's container
397 396
     VideoLayout.ensurePeerContainerExists(jid);
@@ -599,10 +598,16 @@ UI.dockToolbar = function (isDock) {
599 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 611
         SettingsMenu.changeAvatar(thumbUrl);
607 612
     }
608 613
 };

+ 27
- 31
modules/UI/avatar/Avatar.js Parādīt failu

@@ -1,6 +1,4 @@
1
-/* global Strophe, APP, MD5 */
2
-var Settings = require("../../settings/Settings");
3
-
1
+/* global MD5 */
4 2
 var users = {};
5 3
 
6 4
 var Avatar = {
@@ -8,57 +6,55 @@ var Avatar = {
8 6
     /**
9 7
      * Sets the user's avatar in the settings menu(if local user), contact list
10 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 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 23
      * Returns image URL for the avatar to be displayed on large video area
29 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 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 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 47
             return null;
53 48
         }
54
-        var id = users[jid];
55
-        if (!id) {
49
+        var email = users[id];
50
+        if (!email) {
56 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 56
         return 'https://www.gravatar.com/avatar/' +
61
-            MD5.hexdigest(id.trim().toLowerCase()) +
57
+            MD5.hexdigest(email.trim().toLowerCase()) +
62 58
             "?d=wavatar&size=" + (size || "30");
63 59
     }
64 60
 

+ 2
- 2
modules/UI/side_pannels/contactlist/ContactList.js Parādīt failu

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

+ 8
- 6
modules/UI/videolayout/VideoLayout.js Parādīt failu

@@ -1001,14 +1001,16 @@ var VideoLayout = (function (my) {
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 1007
             smallVideo.avatarChanged(thumbUrl);
1008
-        else
1008
+        } else {
1009 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 1016
     my.createEtherpadIframe = function(src, onloadHandler)

+ 4
- 0
modules/settings/Settings.js Parādīt failu

@@ -87,6 +87,10 @@ var Settings = {
87 87
         return email;
88 88
     },
89 89
 
90
+    getEmail: function () {
91
+        return email;
92
+    },
93
+
90 94
     getSettings: function () {
91 95
         return {
92 96
             email: email,

Notiek ielāde…
Atcelt
Saglabāt