Browse Source

Merge pull request #249 from jitsi/fix_user_ids

fix(xmpp.js): User id format
dev1
Paweł Domas 9 years ago
parent
commit
3a03d86ed1
1 changed files with 21 additions and 7 deletions
  1. 21
    7
      modules/xmpp/xmpp.js

+ 21
- 7
modules/xmpp/xmpp.js View File

17
 import initRayo from "./strophe.rayo";
17
 import initRayo from "./strophe.rayo";
18
 import initStropheLogger from "./strophe.logger";
18
 import initStropheLogger from "./strophe.logger";
19
 
19
 
20
-let authenticatedUser = true;
21
-
22
 function createConnection(token, bosh = '/http-bind') {
20
 function createConnection(token, bosh = '/http-bind') {
23
     // Append token as URL param
21
     // Append token as URL param
24
     if (token) {
22
     if (token) {
38
         this.options = options;
36
         this.options = options;
39
         this.connectParams = {};
37
         this.connectParams = {};
40
         this.token = token;
38
         this.token = token;
39
+        this.authenticatedUser = false;
41
         this._initStrophePlugins(this);
40
         this._initStrophePlugins(this);
42
 
41
 
43
         this.connection = createConnection(token, options.bosh);
42
         this.connection = createConnection(token, options.bosh);
130
                 }.bind(this));
129
                 }.bind(this));
131
 
130
 
132
             if (password)
131
             if (password)
133
-                authenticatedUser = true;
132
+                this.authenticatedUser = true;
134
             if (this.connection && this.connection.connected &&
133
             if (this.connection && this.connection.connected &&
135
                 Strophe.getResourceFromJid(this.connection.jid)) {
134
                 Strophe.getResourceFromJid(this.connection.jid)) {
136
                 // .connected is true while connecting?
135
                 // .connected is true while connecting?
243
     }
242
     }
244
 
243
 
245
     createRoom (roomName, options, settings) {
244
     createRoom (roomName, options, settings) {
246
-        let tmpJid = Strophe.getNodeFromJid(this.connection.jid);
245
+        // By default MUC nickname is the resource part of the JID
246
+        let mucNickname = Strophe.getNodeFromJid(this.connection.jid);
247
         let roomjid = roomName  + "@" + this.options.hosts.muc + "/";
247
         let roomjid = roomName  + "@" + this.options.hosts.muc + "/";
248
+        let cfgNickname
249
+            = (options.useNicks && options.nick) ? options.nick : null;
250
+
251
+        if (cfgNickname) {
252
+            // Use nick if it's defined
253
+            mucNickname = options.nick;
254
+        } else if (!this.authenticatedUser) {
255
+            // node of the anonymous JID is very long - here we trim it a bit
256
+            mucNickname = mucNickname.substr(0, 8);
257
+        }
258
+        // Constant JIDs need some random part to be appended in order to be
259
+        // able to join the MUC more than once.
260
+        if (this.authenticatedUser || cfgNickname != null) {
261
+            mucNickname += "-" + RandomUtil.randomHexString(6);
262
+        }
263
+
264
+        roomjid += mucNickname;
248
 
265
 
249
-        roomjid += (options.useNicks)? options.nick || tmpJid :
250
-            (authenticatedUser? "-" + RandomUtil.randomHexString(6):
251
-                tmpJid.substr(0, 8));
252
         return this.connection.emuc.createRoom(roomjid, null, options,
266
         return this.connection.emuc.createRoom(roomjid, null, options,
253
             settings);
267
             settings);
254
     }
268
     }

Loading…
Cancel
Save