@@ -1460,16 +1460,41 @@ _converse.api = {
1460
1460
* Can be called once the XMPP connection has dropped and we want
1461
1461
* to attempt reconnection.
1462
1462
* Only needs to be called once, if reconnect fails Converse will
1463
- * attempt to reconnect every two seconds.
1463
+ * attempt to reconnect every two seconds, alternating between BOSH and
1464
+ * Websocket if URLs for both were provided.
1464
1465
* @method reconnect
1465
1466
* @memberOf _converse.api.connection
1466
1467
*/
1467
1468
reconnect ( ) {
1468
- if ( _converse . connfeedback . get ( 'connection_status' ) === Strophe . Status . RECONNECTING ) {
1469
+ const conn_status = _converse . connfeedback . get ( 'connection_status' ) ;
1470
+ if ( conn_status === Strophe . Status . CONNFAIL ) {
1471
+ if ( _converse . api . connection . isType ( 'websocket' ) && _converse . bosh_service_url ) {
1472
+ _converse . connection . _proto = new Strophe . Bosh ( _converse . connection ) ;
1473
+ _converse . connection . service = _converse . bosh_service_url ;
1474
+ } else if ( _converse . api . connection . isType ( 'bosh' ) && _converse . websocket_url ) {
1475
+ _converse . connection . _proto = new Strophe . Websocket ( _converse . connection ) ;
1476
+ _converse . connection . service = _converse . websocket_url ;
1477
+ }
1478
+ }
1479
+ if ( [ Strophe . Status . RECONNECTING , Strophe . Status . CONNFAIL ] . includes ( conn_status ) ) {
1469
1480
debouncedReconnect ( ) ;
1470
1481
} else {
1471
1482
reconnect ( ) ;
1472
1483
}
1484
+ } ,
1485
+
1486
+ /**
1487
+ * Utility method to determine the type of connection we have
1488
+ * @method isType
1489
+ * @memberOf _converse.api.connection
1490
+ * @returns {boolean }
1491
+ */
1492
+ isType ( type ) {
1493
+ if ( type . toLowerCase ( ) === 'websocket' ) {
1494
+ return _converse . connection . _proto instanceof Strophe . Websocket ;
1495
+ } else if ( type . toLowerCase ( ) === 'bosh' ) {
1496
+ return _converse . connection . _proto instanceof Strophe . Bosh ;
1497
+ }
1473
1498
}
1474
1499
} ,
1475
1500
0 commit comments