Updates #721 Restore sessions when logging in anonymously
together with keepalive.
This commit is contained in:
parent
9a09409ead
commit
9bf00241de
|
@ -1,5 +1,8 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 2.0.2 (Unreleased)
|
||||||
|
- #721 keepalive not working with anonymous authentication [jcbrand]
|
||||||
|
|
||||||
## 2.0.1 (2016-11-07)
|
## 2.0.1 (2016-11-07)
|
||||||
- #203 New configuration setting [muc_domain](https://conversejs.org/docs/html/configuration.html#muc_domain) [jcbrand]
|
- #203 New configuration setting [muc_domain](https://conversejs.org/docs/html/configuration.html#muc_domain) [jcbrand]
|
||||||
- #705 White content after submitting password on chatrooms [jcbrand]
|
- #705 White content after submitting password on chatrooms [jcbrand]
|
||||||
|
|
|
@ -57,7 +57,7 @@
|
||||||
"po2json": "^0.4.4",
|
"po2json": "^0.4.4",
|
||||||
"requirejs": "2.3.2",
|
"requirejs": "2.3.2",
|
||||||
"requirejs-undertemplate": "~0.0.4",
|
"requirejs-undertemplate": "~0.0.4",
|
||||||
"strophe.js": "1.2.9",
|
"strophe.js": "https://github.com/strophe/strophejs#b82171f81db469050bf55fa5394b3283c9b3d3bd",
|
||||||
"strophejs-plugins": "0.0.7",
|
"strophejs-plugins": "0.0.7",
|
||||||
"text": "requirejs/text#2.0.15",
|
"text": "requirejs/text#2.0.15",
|
||||||
"underscore": "~1.8.3"
|
"underscore": "~1.8.3"
|
||||||
|
|
|
@ -46,13 +46,11 @@
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it("needs jid, rid and sid values when not using keepalive", mock.initConverse(function (converse) {
|
it("needs jid, rid and sid values when not using keepalive", mock.initConverse(function (converse) {
|
||||||
var authentication = converse.authentication;
|
|
||||||
var jid = converse.jid;
|
var jid = converse.jid;
|
||||||
delete converse.jid;
|
delete converse.jid;
|
||||||
converse.authentication = "prebind";
|
converse.authentication = "prebind";
|
||||||
expect(converse.logIn.bind(converse)).toThrow(
|
expect(converse.logIn.bind(converse)).toThrow(
|
||||||
new Error("attemptPreboundSession: If you use prebind and not keepalive, then you MUST supply JID, RID and SID values"));
|
new Error("attemptPreboundSession: If you use prebind and not keepalive, then you MUST supply JID, RID and SID values or a prebind_url."));
|
||||||
converse.authentication= authentication;
|
|
||||||
converse.bosh_service_url = undefined;
|
converse.bosh_service_url = undefined;
|
||||||
converse.jid = jid;
|
converse.jid = jid;
|
||||||
}));
|
}));
|
||||||
|
|
|
@ -1757,31 +1757,30 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
this.startNewBOSHSession = function () {
|
this.startNewBOSHSession = function () {
|
||||||
|
var that = this;
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: this.prebind_url,
|
url: this.prebind_url,
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
success: function (response) {
|
success: function (response) {
|
||||||
this.connection.attach(
|
that.connection.attach(
|
||||||
response.jid,
|
response.jid,
|
||||||
response.sid,
|
response.sid,
|
||||||
response.rid,
|
response.rid,
|
||||||
this.onConnectStatusChanged
|
that.onConnectStatusChanged
|
||||||
);
|
);
|
||||||
}.bind(this),
|
},
|
||||||
error: function (response) {
|
error: function (response) {
|
||||||
delete this.connection;
|
delete that.connection;
|
||||||
this.emit('noResumeableSession');
|
that.emit('noResumeableSession');
|
||||||
}.bind(this)
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
this.attemptPreboundSession = function (tokens) {
|
this.attemptPreboundSession = function (tokens) {
|
||||||
/* Handle session resumption or initialization when prebind is being used.
|
/* Handle session resumption or initialization when prebind is being used.
|
||||||
*/
|
*/
|
||||||
if (this.jid && this.sid && this.rid) {
|
if (this.keepalive) {
|
||||||
return this.connection.attach(this.jid, this.sid, this.rid, this.onConnectStatusChanged);
|
|
||||||
} else if (this.keepalive) {
|
|
||||||
if (!this.jid) {
|
if (!this.jid) {
|
||||||
throw new Error("attemptPreboundSession: when using 'keepalive' with 'prebind, "+
|
throw new Error("attemptPreboundSession: when using 'keepalive' with 'prebind, "+
|
||||||
"you must supply the JID of the current user.");
|
"you must supply the JID of the current user.");
|
||||||
|
@ -1792,18 +1791,16 @@
|
||||||
this.log("Could not restore session for jid: "+this.jid+" Error message: "+e.message);
|
this.log("Could not restore session for jid: "+this.jid+" Error message: "+e.message);
|
||||||
this.clearSession(); // If there's a roster, we want to clear it (see #555)
|
this.clearSession(); // If there's a roster, we want to clear it (see #555)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// No keepalive, or session resumption has failed.
|
||||||
|
if (this.jid && this.sid && this.rid) {
|
||||||
|
return this.connection.attach(this.jid, this.sid, this.rid, this.onConnectStatusChanged);
|
||||||
|
} else if (this.prebind_url) {
|
||||||
|
return this.startNewBOSHSession();
|
||||||
} else {
|
} else {
|
||||||
throw new Error("attemptPreboundSession: If you use prebind and not keepalive, "+
|
throw new Error("attemptPreboundSession: If you use prebind and not keepalive, "+
|
||||||
"then you MUST supply JID, RID and SID values");
|
"then you MUST supply JID, RID and SID values or a prebind_url.");
|
||||||
}
|
|
||||||
// We haven't been able to attach yet. Let's see if there
|
|
||||||
// is a prebind_url, otherwise there's nothing with which
|
|
||||||
// we can attach.
|
|
||||||
if (this.prebind_url) {
|
|
||||||
this.startNewBOSHSession();
|
|
||||||
} else {
|
|
||||||
delete this.connection;
|
|
||||||
this.emit('noResumeableSession');
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1844,7 +1841,7 @@
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.attemptNonPreboundSession = function () {
|
this.attemptNonPreboundSession = function (credentials) {
|
||||||
/* Handle session resumption or initialization when prebind is not being used.
|
/* Handle session resumption or initialization when prebind is not being used.
|
||||||
*
|
*
|
||||||
* Two potential options exist and are handled in this method:
|
* Two potential options exist and are handled in this method:
|
||||||
|
@ -1860,7 +1857,11 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.auto_login) {
|
if (this.auto_login) {
|
||||||
if (this.credentials_url) {
|
if (credentials) {
|
||||||
|
// When credentials are passed in, they override prebinding
|
||||||
|
// or credentials fetching via HTTP
|
||||||
|
this.autoLogin(credentials);
|
||||||
|
} else if (this.credentials_url) {
|
||||||
this.fetchLoginCredentials().done(this.autoLogin.bind(this));
|
this.fetchLoginCredentials().done(this.autoLogin.bind(this));
|
||||||
} else if (!this.jid) {
|
} else if (!this.jid) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
|
@ -1870,24 +1871,19 @@
|
||||||
"username and password can be fetched (via credentials_url)."
|
"username and password can be fetched (via credentials_url)."
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
// Probably ANONYMOUS login
|
||||||
this.autoLogin();
|
this.autoLogin();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.logIn = function (credentials) {
|
this.logIn = function (credentials) {
|
||||||
if (credentials || this.authentication === converse.ANONYMOUS) {
|
// We now try to resume or automatically set up a new session.
|
||||||
// When credentials are passed in, they override prebinding
|
// Otherwise the user will be shown a login form.
|
||||||
// or credentials fetching via HTTP
|
if (this.authentication === converse.PREBIND) {
|
||||||
this.autoLogin(credentials);
|
this.attemptPreboundSession();
|
||||||
} else {
|
} else {
|
||||||
// We now try to resume or automatically set up a new session.
|
this.attemptNonPreboundSession(credentials);
|
||||||
// Otherwise the user will be shown a login form.
|
|
||||||
if (this.authentication === converse.PREBIND) {
|
|
||||||
this.attemptPreboundSession();
|
|
||||||
} else {
|
|
||||||
this.attemptNonPreboundSession();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user