Show spinner in controlbox when reconnecting

This commit is contained in:
JC Brand 2022-04-23 13:31:51 +02:00
parent 35b2c247f3
commit f93b30f7b3
6 changed files with 104 additions and 79 deletions

View File

@ -120,7 +120,7 @@ export const api = _converse.api = {
/** /**
* Terminates the connection. * Terminates the connection.
* *
* @method _converse.api.connection.disconnectkjjjkk * @method _converse.api.connection.disconnect
* @memberOf _converse.api.connection * @memberOf _converse.api.connection
*/ */
disconnect () { disconnect () {
@ -139,10 +139,15 @@ export const api = _converse.api = {
* @memberOf _converse.api.connection * @memberOf _converse.api.connection
*/ */
reconnect () { reconnect () {
if (_converse.connection?.reconnecting) { const { __, connection } = _converse;
return _converse.connection.debouncedReconnect(); connection.setConnectionStatus(
Strophe.Status.RECONNECTING,
__('The connection has dropped, attempting to reconnect.')
);
if (connection?.reconnecting) {
return connection.debouncedReconnect();
} else { } else {
return _converse.connection.reconnect(); return connection.reconnect();
} }
}, },

View File

@ -9,6 +9,9 @@ import { getOpenPromise } from '@converse/openpromise';
import { setUserJID, } from '@converse/headless/utils/init.js'; import { setUserJID, } from '@converse/headless/utils/init.js';
import { tearDown } from '@converse/headless/utils/core.js'; import { tearDown } from '@converse/headless/utils/core.js';
const i = Object.keys(Strophe.Status).reduce((max, k) => Math.max(max, Strophe.Status[k]), 0);
Strophe.Status.RECONNECTING = i + 1;
/** /**
* The Connection class manages the connection to the XMPP server. It's * The Connection class manages the connection to the XMPP server. It's
@ -154,11 +157,6 @@ export class Connection extends Strophe.Connection {
await setUserJID(api.settings.get("jid")); await setUserJID(api.settings.get("jid"));
} }
const { __ } = _converse;
this.setConnectionStatus(
Strophe.Status.RECONNECTING,
__('The connection has dropped, attempting to reconnect.')
);
/** /**
* Triggered when the connection has dropped, but Converse will attempt * Triggered when the connection has dropped, but Converse will attempt
* to reconnect again. * to reconnect again.

View File

@ -1,37 +1,42 @@
import { converse } from '@converse/headless/core.js';
const { Strophe } = converse.env;
export const REPORTABLE_STATUSES = [ export const REPORTABLE_STATUSES = [
0, // ERROR' Strophe.Status.ERROR,
1, // CONNECTING Strophe.Status.CONNECTING,
2, // CONNFAIL Strophe.Status.CONNFAIL,
3, // AUTHENTICATING Strophe.Status.AUTHENTICATING,
4, // AUTHFAIL Strophe.Status.AUTHFAIL,
7, // DISCONNECTING Strophe.Status.DISCONNECTING,
10 // RECONNECTING Strophe.Status.RECONNECTING,
]; ];
export const PRETTY_CONNECTION_STATUS = { export const PRETTY_CONNECTION_STATUS = Object.fromEntries([
0: 'Error', [Strophe.Status.ERROR, 'Error'],
1: 'Connecting', [Strophe.Status.CONNECTING, 'Connecting'],
2: 'Connection failure', [Strophe.Status.CONNFAIL, 'Connection failure'],
3: 'Authenticating', [Strophe.Status.AUTHENTICATING, 'Authenticating'],
4: 'Authentication failure', [Strophe.Status.AUTHFAIL, 'Authentication failure'],
5: 'Connected', [Strophe.Status.CONNECTED, 'Connected'],
6: 'Disconnected', [Strophe.Status.DISCONNECTED, 'Disconnected'],
7: 'Disconnecting', [Strophe.Status.DISCONNECTING, 'Disconnecting'],
8: 'Attached', [Strophe.Status.ATTACHED, 'Attached'],
9: 'Redirect', [Strophe.Status.REDIRECT, 'Redirect'],
10: 'Reconnecting' [Strophe.Status.CONNTIMEOUT, 'Connection timeout'],
}; [Strophe.Status.RECONNECTING, 'Reconnecting'],
]);
export const CONNECTION_STATUS_CSS_CLASS = { export const CONNECTION_STATUS_CSS_CLASS = Object.fromEntries([
'Error': 'error', [Strophe.Status.ERROR, 'error'],
'Connecting': 'info', [Strophe.Status.CONNECTING, 'info'],
'Connection failure': 'error', [Strophe.Status.CONNFAIL, 'error'],
'Authenticating': 'info', [Strophe.Status.AUTHENTICATING, 'info'],
'Authentication failure': 'error', [Strophe.Status.AUTHFAIL, 'error'],
'Connected': 'info', [Strophe.Status.CONNECTED, 'info'],
'Disconnected': 'error', [Strophe.Status.DISCONNECTED, 'error'],
'Disconnecting': 'warn', [Strophe.Status.DISCONNECTING, 'warn'],
'Attached': 'info', [Strophe.Status.ATTACHED, 'info'],
'Redirect': 'info', [Strophe.Status.REDIRECT, 'info'],
'Reconnecting': 'warn' [Strophe.Status.RECONNECTING, 'warn'],
}; ]);

View File

@ -34,6 +34,7 @@ class ControlBox extends CustomElement {
setModel () { setModel () {
this.model = _converse.chatboxes.get('controlbox'); this.model = _converse.chatboxes.get('controlbox');
this.listenTo(_converse.connfeedback, 'change:connection_status', () => this.requestUpdate());
this.listenTo(this.model, 'change:active-form', () => this.requestUpdate()); this.listenTo(this.model, 'change:active-form', () => this.requestUpdate());
this.listenTo(this.model, 'change:connected', () => this.requestUpdate()); this.listenTo(this.model, 'change:connected', () => this.requestUpdate());
this.listenTo(this.model, 'change:closed', () => !this.model.get('closed') && this.afterShown()); this.listenTo(this.model, 'change:closed', () => !this.model.get('closed') && this.afterShown());
@ -41,11 +42,7 @@ class ControlBox extends CustomElement {
} }
render () { render () {
return this.model ? tpl_controlbox({ return this.model ? tpl_controlbox(this) : '';
'sticky_controlbox': api.settings.get('sticky_controlbox'),
...this.model.toJSON(),
'close': ev => this.close(ev)
}) : '';
} }
close (ev) { close (ev) {

View File

@ -1,34 +1,54 @@
import tpl_spinner from "templates/spinner.js";
import { _converse, api, converse } from "@converse/headless/core.js";
import { html } from 'lit'; import { html } from 'lit';
import { _converse, api } from "@converse/headless/core";
export default o => html` const { Strophe } = converse.env;
<div class="flyout box-flyout">
<converse-dragresize></converse-dragresize>
<div class="chat-head controlbox-head"> function whenNotConnected (o) {
${o.sticky_controlbox const connection_status = _converse.connfeedback.get('connection_status');
? '' console.log("connection_status");
: html` console.log(connection_status);
<a class="chatbox-btn close-chatbox-button fa fa-times" @click=${o.close}></a> if ([Strophe.Status.RECONNECTING, Strophe.Status.CONNECTING].includes(connection_status)) {
`} return tpl_spinner();
</div> }
<div class="controlbox-panes"> if (o['active-form'] === 'register') {
<div class="controlbox-pane"> return html`<converse-register-panel></converse-register-panel>`;
${o.connected }
? html` return html`<converse-login-form id="converse-login-panel" class="controlbox-pane fade-in row no-gutters"></converse-login-form>}`;
<converse-user-profile></converse-user-profile> }
<converse-headlines-panel class="controlbox-section"></converse-headlines-panel>
<div id="chatrooms" class="controlbox-section">
<converse-rooms-list></converse-rooms-list> export default (el) => {
<converse-bookmarks></converse-bookmarks> const o = el.model.toJSON();
</div> const sticky_controlbox = api.settings.get('sticky_controlbox');
${ api.settings.get("authentication") === _converse.ANONYMOUS ? '' :
html`<div id="converse-roster" class="controlbox-section"><converse-roster></converse-roster></div>` return html`
}` <div class="flyout box-flyout">
: o['active-form'] === 'register' <converse-dragresize></converse-dragresize>
? html`<converse-register-panel></converse-register-panel>` <div class="chat-head controlbox-head">
: html`<converse-login-form id="converse-login-panel" class="controlbox-pane fade-in row no-gutters"></converse-login-form>` ${sticky_controlbox
} ? ''
: html`
<a class="chatbox-btn close-chatbox-button fa fa-times" @click=${(ev) => el.close(ev)}></a>
`}
</div> </div>
</div> <div class="controlbox-panes">
</div> <div class="controlbox-pane">
`; ${o.connected
? html`
<converse-user-profile></converse-user-profile>
<converse-headlines-panel class="controlbox-section"></converse-headlines-panel>
<div id="chatrooms" class="controlbox-section">
<converse-rooms-list></converse-rooms-list>
<converse-bookmarks></converse-bookmarks>
</div>
${ api.settings.get("authentication") === _converse.ANONYMOUS ? '' :
html`<div id="converse-roster" class="controlbox-section"><converse-roster></converse-roster></div>`
}`
: whenNotConnected(o)
}
</div>
</div>
</div>`
};

View File

@ -126,7 +126,7 @@ export default (el) => {
let feedback_class, pretty_status; let feedback_class, pretty_status;
if (REPORTABLE_STATUSES.includes(connection_status)) { if (REPORTABLE_STATUSES.includes(connection_status)) {
pretty_status = PRETTY_CONNECTION_STATUS[connection_status]; pretty_status = PRETTY_CONNECTION_STATUS[connection_status];
feedback_class = CONNECTION_STATUS_CSS_CLASS[pretty_status]; feedback_class = CONNECTION_STATUS_CSS_CLASS[connection_status];
} }
const conn_feedback_message = _converse.connfeedback.get('message'); const conn_feedback_message = _converse.connfeedback.get('message');
return html` return html`