|
@@ -28,6 +28,8 @@ import {WebClientService} from '../services/webclient';
|
|
|
*/
|
|
*/
|
|
|
export class StatusController {
|
|
export class StatusController {
|
|
|
|
|
|
|
|
|
|
+ private logTag: string = '[StatusController]';
|
|
|
|
|
+
|
|
|
// State variable
|
|
// State variable
|
|
|
private state: threema.GlobalConnectionState = 'error';
|
|
private state: threema.GlobalConnectionState = 'error';
|
|
|
|
|
|
|
@@ -110,7 +112,7 @@ export class StatusController {
|
|
|
}
|
|
}
|
|
|
break;
|
|
break;
|
|
|
default:
|
|
default:
|
|
|
- this.$log.error('Invalid state change: From', oldValue, 'to', newValue);
|
|
|
|
|
|
|
+ this.$log.error(this.logTag, 'Invalid state change: From', oldValue, 'to', newValue);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -137,12 +139,19 @@ export class StatusController {
|
|
|
* Go back to the welcome screen and try to reconnect using the same keys as right now.
|
|
* Go back to the welcome screen and try to reconnect using the same keys as right now.
|
|
|
*/
|
|
*/
|
|
|
private reconnect(): void {
|
|
private reconnect(): void {
|
|
|
- this.$log.debug('Connection lost. Attempting to reconnect...');
|
|
|
|
|
|
|
+ this.$log.warn(this.logTag, 'Connection lost. Attempting to reconnect...');
|
|
|
|
|
|
|
|
// Get original keys
|
|
// Get original keys
|
|
|
let originalKeyStore = this.webClientService.salty.keyStore;
|
|
let originalKeyStore = this.webClientService.salty.keyStore;
|
|
|
let originalPeerPermanentKeyBytes = this.webClientService.salty.peerPermanentKeyBytes;
|
|
let originalPeerPermanentKeyBytes = this.webClientService.salty.peerPermanentKeyBytes;
|
|
|
|
|
|
|
|
|
|
+ // Timeout durations
|
|
|
|
|
+ const TIMEOUT1 = 20 * 1000; // Duration per step for first reconnect
|
|
|
|
|
+ const TIMEOUT2 = 20 * 1000; // Duration per step for second reconnect
|
|
|
|
|
+
|
|
|
|
|
+ // Reconnect state
|
|
|
|
|
+ let reconnectTry: 1 | 2 = 1;
|
|
|
|
|
+
|
|
|
// Handler for failed reconnection attempts
|
|
// Handler for failed reconnection attempts
|
|
|
let reconnectionFailed = () => {
|
|
let reconnectionFailed = () => {
|
|
|
// Collapse status bar
|
|
// Collapse status bar
|
|
@@ -160,6 +169,20 @@ export class StatusController {
|
|
|
});
|
|
});
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+ // Handlers for reconnecting timeout
|
|
|
|
|
+ const reconnect2Timeout = () => {
|
|
|
|
|
+ // Give up
|
|
|
|
|
+ this.$log.error(this.logTag, 'Reconnect timeout 2. Going back to initial loading screen...');
|
|
|
|
|
+ reconnectionFailed();
|
|
|
|
|
+ };
|
|
|
|
|
+ const reconnect1Timeout = () => {
|
|
|
|
|
+ // Could not connect so far.
|
|
|
|
|
+ this.$log.error(this.logTag, 'Reconnect timeout 1. Retrying...');
|
|
|
|
|
+ reconnectTry = 2;
|
|
|
|
|
+ this.reconnectTimeout = this.$timeout(reconnect2Timeout, TIMEOUT2);
|
|
|
|
|
+ doSoftReconnect();
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
// Function to soft-reconnect. Does not reset the loaded data.
|
|
// Function to soft-reconnect. Does not reset the loaded data.
|
|
|
let doSoftReconnect = () => {
|
|
let doSoftReconnect = () => {
|
|
|
const deleteStoredData = false;
|
|
const deleteStoredData = false;
|
|
@@ -176,25 +199,29 @@ export class StatusController {
|
|
|
this.collapseStatusBar();
|
|
this.collapseStatusBar();
|
|
|
},
|
|
},
|
|
|
(error) => {
|
|
(error) => {
|
|
|
- this.$log.error('Error state:', error);
|
|
|
|
|
|
|
+ this.$log.error(this.logTag, 'Error state:', error);
|
|
|
this.$timeout.cancel(this.reconnectTimeout);
|
|
this.$timeout.cancel(this.reconnectTimeout);
|
|
|
reconnectionFailed();
|
|
reconnectionFailed();
|
|
|
},
|
|
},
|
|
|
|
|
+ (progress: threema.ConnectionBuildupStateChange) => {
|
|
|
|
|
+ if (progress.state === 'peer_handshake' || progress.state === 'loading') {
|
|
|
|
|
+ this.$log.debug(this.logTag, 'Connection buildup advanced, resetting timeout');
|
|
|
|
|
+ // Restart timeout
|
|
|
|
|
+ this.$timeout.cancel(this.reconnectTimeout);
|
|
|
|
|
+ if (reconnectTry === 1) {
|
|
|
|
|
+ this.reconnectTimeout = this.$timeout(reconnect1Timeout, TIMEOUT1);
|
|
|
|
|
+ } else if (reconnectTry === 2) {
|
|
|
|
|
+ this.reconnectTimeout = this.$timeout(reconnect2Timeout, TIMEOUT2);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ throw new Error('Invalid reconnectTry value: ' + reconnectTry);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
);
|
|
);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
// Start timeout
|
|
// Start timeout
|
|
|
- this.reconnectTimeout = this.$timeout(() => {
|
|
|
|
|
- // Could not connect so far.
|
|
|
|
|
- // Retry once, but increase reconnect timeout to 40 seconds
|
|
|
|
|
- this.$log.error('Reconnect timeout 1. Retrying for 40 seconds...');
|
|
|
|
|
- this.reconnectTimeout = this.$timeout(() => {
|
|
|
|
|
- // Give up
|
|
|
|
|
- this.$log.error('Reconnect timeout 2. Going back to initial loading screen...');
|
|
|
|
|
- reconnectionFailed();
|
|
|
|
|
- }, 40000);
|
|
|
|
|
- doSoftReconnect();
|
|
|
|
|
- }, 20000);
|
|
|
|
|
|
|
+ this.reconnectTimeout = this.$timeout(reconnect1Timeout, TIMEOUT1);
|
|
|
|
|
|
|
|
// Start reconnecting process
|
|
// Start reconnecting process
|
|
|
doSoftReconnect();
|
|
doSoftReconnect();
|