Fixes #1196. Use alternative connection method upon connfail

This commit is contained in:
JC Brand 2019-06-04 15:10:03 +02:00
parent 297f3d9efb
commit 51f2ab9100
3 changed files with 29 additions and 3 deletions

View File

@ -26,6 +26,7 @@
- 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
- #1196: Use alternative connection method upon connfail
- #1296: `embedded` view mode shows `chatbox-navback` arrow in header
- #1330: Missing room name in MUC invitation popup
- #1445: Participants list uses big font in embedded mode

View File

@ -1460,16 +1460,41 @@ _converse.api = {
* Can be called once the XMPP connection has dropped and we want
* to attempt reconnection.
* Only needs to be called once, if reconnect fails Converse will
* attempt to reconnect every two seconds.
* attempt to reconnect every two seconds, alternating between BOSH and
* Websocket if URLs for both were provided.
* @method reconnect
* @memberOf _converse.api.connection
*/
reconnect () {
if (_converse.connfeedback.get('connection_status') === Strophe.Status.RECONNECTING) {
const conn_status = _converse.connfeedback.get('connection_status');
if (conn_status === Strophe.Status.CONNFAIL) {
if (_converse.api.connection.isType('websocket') && _converse.bosh_service_url) {
_converse.connection._proto = new Strophe.Bosh(_converse.connection);
_converse.connection.service = _converse.bosh_service_url;
} else if (_converse.api.connection.isType('bosh') && _converse.websocket_url) {
_converse.connection._proto = new Strophe.Websocket(_converse.connection);
_converse.connection.service = _converse.websocket_url;
}
}
if ([Strophe.Status.RECONNECTING, Strophe.Status.CONNFAIL].includes(conn_status)) {
debouncedReconnect();
} else {
reconnect();
}
},
/**
* Utility method to determine the type of connection we have
* @method isType
* @memberOf _converse.api.connection
* @returns {boolean}
*/
isType (type) {
if (type.toLowerCase() === 'websocket') {
return _converse.connection._proto instanceof Strophe.Websocket;
} else if (type.toLowerCase() === 'bosh') {
return _converse.connection._proto instanceof Strophe.Bosh;
}
}
},

View File

@ -1724,7 +1724,7 @@ converse.plugins.add('converse-muc', {
_converse.api.listen.on('statusInitialized', () => {
window.addEventListener(_converse.unloadevent, () => {
const using_websocket = _converse.connection._proto instanceof Strophe.Websocket;
const using_websocket = _converse.api.connection.isType('websocket');
if (using_websocket && !_converse.enable_smacks) {
// For non-SMACKS websocket connections, we disconnect all
// chatrooms when the page unloads.