Retry websocket connect if error returned is 502

* Retry websocket connect if error returned is 502

* Introduce connect button on 'Disconnected' left-pane dialog

* NetworkStatus: If user clicks connect, show connecting for 5s
This commit is contained in:
Scott Nonnenberg 2020-03-20 11:01:55 -07:00
parent c44176f7f3
commit 6bd5587d50
5 changed files with 89 additions and 15 deletions

View file

@ -1446,6 +1446,7 @@
new textsecure.SyncRequest(textsecure.messaging, messageReceiver);
let disconnectTimer = null;
let reconnectTimer = null;
function onOffline() {
window.log.info('offline');
@ -1499,7 +1500,12 @@
let connectCount = 0;
async function connect(firstRun) {
window.log.info('connect', firstRun);
window.log.info('connect', { firstRun, connectCount });
if (reconnectTimer) {
clearTimeout(reconnectTimer);
reconnectTimer = null;
}
// Bootstrap our online/offline detection, only the first time we connect
if (connectCount === 0 && navigator.onLine) {
@ -1799,6 +1805,11 @@
}
}
Whisper.events.on('manualConnect', manualConnect);
function manualConnect() {
connect();
}
function onConfiguration(ev) {
ev.confirm();
@ -2435,11 +2446,15 @@
return;
}
if (error && error.name === 'HTTPError' && error.code === -1) {
if (
error &&
error.name === 'HTTPError' &&
(error.code === -1 || error.code === 502)
) {
// Failed to connect to server
if (navigator.onLine) {
window.log.info('retrying in 1 minute');
setTimeout(connect, 60000);
reconnectTimer = setTimeout(connect, 60000);
Whisper.events.trigger('reconnectTimer');
}