Commit 2e50ecb9 authored by Davide Colombo's avatar Davide Colombo

add method to generate random resource and add random resource also for auto_login

parent a687e87e
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
- #573 xgettext build error: `'javascript' unknown` [jcbrand] - #573 xgettext build error: `'javascript' unknown` [jcbrand]
- #587 Fix issue when logging out with `auto_logout=true` [davec82] - #587 Fix issue when logging out with `auto_logout=true` [davec82]
- #589 Save scroll position on minimize and restore it on maximize [rlanvin] - #589 Save scroll position on minimize and restore it on maximize [rlanvin]
- #592 Add random resource for auto_login, add method generateResource to generate random resource [davec82]
## 0.10.1 (2016-02-06) ## 0.10.1 (2016-02-06)
......
...@@ -415,6 +415,10 @@ ...@@ -415,6 +415,10 @@
// Module-level functions // Module-level functions
// ---------------------- // ----------------------
this.generateResource = function () {
return '/converse.js-' + Math.floor(Math.random()*139749825).toString();
};
this.sendCSI = function (stat) { this.sendCSI = function (stat) {
/* Send out a Chat Status Notification (XEP-0352) */ /* Send out a Chat Status Notification (XEP-0352) */
if (converse.features[Strophe.NS.CSI] || true) { if (converse.features[Strophe.NS.CSI] || true) {
...@@ -4723,9 +4727,9 @@ ...@@ -4723,9 +4727,9 @@
if (jid) { if (jid) {
resource = Strophe.getResourceFromJid(jid); resource = Strophe.getResourceFromJid(jid);
if (!resource) { if (!resource) {
jid = jid.toLowerCase() + '/converse.js-' + Math.floor(Math.random()*139749825).toString(); jid = jid.toLowerCase() + converse.generateResource();
} else { } else {
jid = Strophe.getBareJidFromJid(jid).toLowerCase()+'/'+Strophe.getResourceFromJid(jid); jid = Strophe.getBareJidFromJid(jid).toLowerCase()+'/'+resource;
} }
} }
converse.connection.connect(jid, password, converse.onConnectStatusChanged); converse.connection.connect(jid, password, converse.onConnectStatusChanged);
...@@ -4893,7 +4897,12 @@ ...@@ -4893,7 +4897,12 @@
throw new Error("initConnection: If you use auto_login and "+ throw new Error("initConnection: If you use auto_login and "+
"authentication='login' then you also need to provide a password."); "authentication='login' then you also need to provide a password.");
} }
this.jid = Strophe.getBareJidFromJid(this.jid).toLowerCase()+'/'+Strophe.getResourceFromJid(this.jid); var resource = Strophe.getResourceFromJid(this.jid);
if (!resource) {
this.jid = this.jid.toLowerCase() + converse.generateResource();
} else {
this.jid = Strophe.getBareJidFromJid(this.jid).toLowerCase()+'/'+resource;
}
this.connection.connect(this.jid, this.password, this.onConnectStatusChanged); this.connection.connect(this.jid, this.password, this.onConnectStatusChanged);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment