Re-add the `keepalive` options.

It's unlikely that `keepalive` needs to be set to `false`, but there are
some edge cases where it might be useful.

Here's a breakdown of the different configurations of `keepalive` and `auto_join`:

---

* auto_login: false, keepalive: true

This is the default config. Users need to log in manually, but then
Converse will try to reconnect them when the page reloads.

* auto_login: true, keepalive: true

Also very popular configuration. Used with `credentials_url` or `prebind_url`.

* auto_login = `true`, keepalive = `false`

Not sure what this could be useful for. No currently known application.

* auto_login = `false`, keepalive = `false`

Useful when you want some kind of specific action to trigger login, but
you don't want to maintain that state across page reloads.

Also relevant when using a websocket connection with anonymous login.
With websocket it's impossible to maintain anonymous sessions across page
reload because the the session gets removed server-side as soon as the
websocket connection drops and the server won't accept a full JID with
password for an anonymous connection anyway (which could happen upon
page reload when Converse tries to login in again if `keepalive` was `true`).
This commit is contained in:
JC Brand 2019-07-26 17:53:18 +02:00
parent b6b085189b
commit ea36d53f78
3 changed files with 15 additions and 6 deletions

View File

@ -28,6 +28,7 @@
By setting this option to `false` and `view_mode` to `'embedded'`, it's now possible to
"embed" the full app and not just a single chat. To embed just a single chat, it's now
necessary to explicitly set `singleton` to `true`.
- Re-add the previously removed config option [keepalive](https://conversejs.org/docs/html/configuration.html#keepalive)
- New event: [chatBoxBlurred](https://conversejs.org/docs/html/api/-_converse.html#event:chatBoxBlurred)
- New event: [chatReconnected](https://conversejs.org/docs/html/api/-_converse.html#event:chatReconnected)
- #316: Add support for XEP-0198 Stream Management

View File

@ -758,6 +758,15 @@ messaging instead.
This value may be provided together with a ``password`` instead of supplying a
`credentials_url`_ when setting ``auto_login`` to ``true``.
.. _`keepalive`:
keepalive
---------
* Default: ``true``
Determines whether Converse will attempt to keep you logged in across page loads.
.. _`locales`:

View File

@ -218,6 +218,7 @@ _converse.default_settings = {
geouri_replacement: 'https://www.openstreetmap.org/?mlat=$1&mlon=$2#map=18/$1/$2',
idle_presence_timeout: 300, // Seconds after which an idle presence is sent
jid: undefined,
keepalive: true,
locales_url: 'locale/{{{locale}}}/LC_MESSAGES/converse.json',
locales: [
'af', 'ar', 'bg', 'ca', 'cs', 'de', 'eo', 'es', 'eu', 'en', 'fr', 'gl',
@ -525,7 +526,7 @@ function clearSession () {
* Creates a new Strophe.Connection instance and if applicable, attempt to
* restore the BOSH session or if `auto_login` is true, attempt to log in.
*/
_converse.initConnection = async function () {
_converse.initConnection = function () {
if (!_converse.connection) {
if (!_converse.bosh_service_url && ! _converse.websocket_url) {
throw new Error("initConnection: you must supply a value for either the bosh_service_url or websocket_url or both.");
@ -541,17 +542,15 @@ _converse.initConnection = async function () {
Object.assign(
_converse.default_connection_options,
_converse.connection_options,
{'keepalive': true}
{'keepalive': _converse.keepalive}
)
);
} else {
throw new Error("initConnection: this browser does not support "+
"websockets and bosh_service_url wasn't specified.");
}
if (_converse.auto_login) {
if (_converse.auto_login || _converse.keepalive) {
_converse.api.user.login();
} else if (_converse.api.connection.isType('bosh')) {
await _converse.restoreBOSHSession();
}
}
setUpXMLLogging();
@ -654,7 +653,7 @@ function setUpXMLLogging () {
async function finishInitialization () {
initClientConfig();
initPlugins();
await _converse.initConnection();
_converse.initConnection();
_converse.registerGlobalEventHandlers();
if (!Backbone.history.started) {
Backbone.history.start();