Przeglądaj źródła

Merge pull request #249 from jitsi/fix_user_ids

fix(xmpp.js): User id format
dev1
Paweł Domas 9 lat temu
rodzic
commit
3a03d86ed1
1 zmienionych plików z 21 dodań i 7 usunięć
  1. 21
    7
      modules/xmpp/xmpp.js

+ 21
- 7
modules/xmpp/xmpp.js Wyświetl plik

@@ -17,8 +17,6 @@ import initPing from "./strophe.ping";
17 17
 import initRayo from "./strophe.rayo";
18 18
 import initStropheLogger from "./strophe.logger";
19 19
 
20
-let authenticatedUser = true;
21
-
22 20
 function createConnection(token, bosh = '/http-bind') {
23 21
     // Append token as URL param
24 22
     if (token) {
@@ -38,6 +36,7 @@ export default class XMPP {
38 36
         this.options = options;
39 37
         this.connectParams = {};
40 38
         this.token = token;
39
+        this.authenticatedUser = false;
41 40
         this._initStrophePlugins(this);
42 41
 
43 42
         this.connection = createConnection(token, options.bosh);
@@ -130,7 +129,7 @@ export default class XMPP {
130 129
                 }.bind(this));
131 130
 
132 131
             if (password)
133
-                authenticatedUser = true;
132
+                this.authenticatedUser = true;
134 133
             if (this.connection && this.connection.connected &&
135 134
                 Strophe.getResourceFromJid(this.connection.jid)) {
136 135
                 // .connected is true while connecting?
@@ -243,12 +242,27 @@ export default class XMPP {
243 242
     }
244 243
 
245 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 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 266
         return this.connection.emuc.createRoom(roomjid, null, options,
253 267
             settings);
254 268
     }

Ładowanie…
Anuluj
Zapisz