From 75805a781fc3f7bb7f77cd9fea9c16796120aa26 Mon Sep 17 00:00:00 2001 From: Konrad Bartecki Date: Fri, 23 Apr 2021 22:36:58 +0200 Subject: [PATCH 1/7] Support for mobile browsers to automatically reload the page when circuit was lost --- .../Web.JS/src/Platform/Circuits/DefaultReconnectionHandler.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Components/Web.JS/src/Platform/Circuits/DefaultReconnectionHandler.ts b/src/Components/Web.JS/src/Platform/Circuits/DefaultReconnectionHandler.ts index 28415375ba74..56b413ddd29b 100644 --- a/src/Components/Web.JS/src/Platform/Circuits/DefaultReconnectionHandler.ts +++ b/src/Components/Web.JS/src/Platform/Circuits/DefaultReconnectionHandler.ts @@ -75,7 +75,7 @@ class ReconnectionProcess { const result = await this.reconnectCallback(); if (!result) { // If the server responded and refused to reconnect, stop auto-retrying. - this.reconnectDisplay.rejected(); + location.reload(); return; } return; From e44c8280ce3e11f72ebb7647cab6d4f97e5db19d Mon Sep 17 00:00:00 2001 From: Konrad Bartecki Date: Fri, 23 Apr 2021 22:38:21 +0200 Subject: [PATCH 2/7] Reconnection handler will now immediately try to reconnect and apply delay afterwards. Support for mobile browsers to enable page reload when circuit was lost --- .../Platform/Circuits/DefaultReconnectionHandler.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Components/Web.JS/src/Platform/Circuits/DefaultReconnectionHandler.ts b/src/Components/Web.JS/src/Platform/Circuits/DefaultReconnectionHandler.ts index 56b413ddd29b..622d1d791778 100644 --- a/src/Components/Web.JS/src/Platform/Circuits/DefaultReconnectionHandler.ts +++ b/src/Components/Web.JS/src/Platform/Circuits/DefaultReconnectionHandler.ts @@ -57,12 +57,6 @@ class ReconnectionProcess { async attemptPeriodicReconnection(options: ReconnectionOptions) { for (let i = 0; i < options.maxRetries; i++) { this.reconnectDisplay.update(i + 1); - - const delayDuration = i == 0 && options.retryIntervalMilliseconds > ReconnectionProcess.MaximumFirstRetryInterval - ? ReconnectionProcess.MaximumFirstRetryInterval - : options.retryIntervalMilliseconds; - await this.delay(delayDuration); - if (this.isDisposed) { break; } @@ -83,6 +77,11 @@ class ReconnectionProcess { // We got an exception so will try again momentarily this.logger.log(LogLevel.Error, err); } + const delayDuration = i == 0 && options.retryIntervalMilliseconds > ReconnectionProcess.MaximumFirstRetryInterval + ? ReconnectionProcess.MaximumFirstRetryInterval + : options.retryIntervalMilliseconds; + this.logger.log(LogLevel.Debug, `Reconnecting in ${delayDuration}`); + await this.delay(delayDuration); } this.reconnectDisplay.failed(); From 69c47809623cd0f9a388c294c6bc38547065d779 Mon Sep 17 00:00:00 2001 From: Konrad Bartecki Date: Fri, 23 Apr 2021 23:33:21 +0200 Subject: [PATCH 3/7] Add new onConnectionRejected event with default implementation that reloads the page --- src/Components/Web.JS/src/Boot.Server.ts | 1 + .../Web.JS/src/Platform/Circuits/CircuitStartOptions.ts | 5 ++++- .../src/Platform/Circuits/DefaultReconnectionHandler.ts | 8 +++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Components/Web.JS/src/Boot.Server.ts b/src/Components/Web.JS/src/Boot.Server.ts index 968a65dd45c6..a7b8454eea33 100644 --- a/src/Components/Web.JS/src/Boot.Server.ts +++ b/src/Components/Web.JS/src/Boot.Server.ts @@ -49,6 +49,7 @@ async function boot(userOptions?: Partial): Promise { const reconnection = existingConnection || await initializeConnection(options, logger, circuit); if (!(await circuit.reconnect(reconnection))) { logger.log(LogLevel.Information, 'Reconnection attempt to the circuit was rejected by the server. This may indicate that the associated state is no longer available on the server.'); + options.reconnectionHandler!.onConnectionRejected(options.reconnectionOptions); return false; } diff --git a/src/Components/Web.JS/src/Platform/Circuits/CircuitStartOptions.ts b/src/Components/Web.JS/src/Platform/Circuits/CircuitStartOptions.ts index 08bbea4c5fc5..d0f3b5fe1d47 100644 --- a/src/Components/Web.JS/src/Platform/Circuits/CircuitStartOptions.ts +++ b/src/Components/Web.JS/src/Platform/Circuits/CircuitStartOptions.ts @@ -22,11 +22,13 @@ export interface ReconnectionOptions { maxRetries: number; retryIntervalMilliseconds: number; dialogId: string; + reloadOnCircuitRejected: boolean; } export interface ReconnectionHandler { onConnectionDown(options: ReconnectionOptions, error?: Error): void; onConnectionUp(): void; + onConnectionRejected(options: ReconnectionOptions): void; } const defaultOptions: CircuitStartOptions = { @@ -34,7 +36,8 @@ const defaultOptions: CircuitStartOptions = { logLevel: LogLevel.Warning, reconnectionOptions: { maxRetries: 8, - retryIntervalMilliseconds: 20000, + retryIntervalMilliseconds: 3000, dialogId: 'components-reconnect-modal', + reloadOnCircuitRejected: true, }, }; diff --git a/src/Components/Web.JS/src/Platform/Circuits/DefaultReconnectionHandler.ts b/src/Components/Web.JS/src/Platform/Circuits/DefaultReconnectionHandler.ts index 622d1d791778..1165c656ba08 100644 --- a/src/Components/Web.JS/src/Platform/Circuits/DefaultReconnectionHandler.ts +++ b/src/Components/Web.JS/src/Platform/Circuits/DefaultReconnectionHandler.ts @@ -35,6 +35,12 @@ export class DefaultReconnectionHandler implements ReconnectionHandler { this._currentReconnectionProcess = null; } } + + onConnectionRejected(options: ReconnectionOptions) { + if (options.reloadOnCircuitRejected) { + location.reload(); + } + } }; class ReconnectionProcess { @@ -69,7 +75,7 @@ class ReconnectionProcess { const result = await this.reconnectCallback(); if (!result) { // If the server responded and refused to reconnect, stop auto-retrying. - location.reload(); + this.reconnectDisplay.rejected(); return; } return; From bd1015fb8436de1b6a7536dab52614e9016457d6 Mon Sep 17 00:00:00 2001 From: Konrad Bartecki Date: Fri, 23 Apr 2021 23:35:54 +0200 Subject: [PATCH 4/7] Removed custom retry delay with a different timeout on the first attempt --- .../src/Platform/Circuits/DefaultReconnectionHandler.ts | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/Components/Web.JS/src/Platform/Circuits/DefaultReconnectionHandler.ts b/src/Components/Web.JS/src/Platform/Circuits/DefaultReconnectionHandler.ts index 1165c656ba08..42df25ee4174 100644 --- a/src/Components/Web.JS/src/Platform/Circuits/DefaultReconnectionHandler.ts +++ b/src/Components/Web.JS/src/Platform/Circuits/DefaultReconnectionHandler.ts @@ -44,8 +44,6 @@ export class DefaultReconnectionHandler implements ReconnectionHandler { }; class ReconnectionProcess { - static readonly MaximumFirstRetryInterval = 3000; - readonly reconnectDisplay: ReconnectDisplay; isDisposed = false; @@ -83,11 +81,7 @@ class ReconnectionProcess { // We got an exception so will try again momentarily this.logger.log(LogLevel.Error, err); } - const delayDuration = i == 0 && options.retryIntervalMilliseconds > ReconnectionProcess.MaximumFirstRetryInterval - ? ReconnectionProcess.MaximumFirstRetryInterval - : options.retryIntervalMilliseconds; - this.logger.log(LogLevel.Debug, `Reconnecting in ${delayDuration}`); - await this.delay(delayDuration); + await this.delay(options.retryIntervalMilliseconds); } this.reconnectDisplay.failed(); From f2f6cdbbc15156fb93f71ceeb8b1fc6740715b3f Mon Sep 17 00:00:00 2001 From: Konrad Bartecki Date: Sat, 24 Apr 2021 00:01:02 +0200 Subject: [PATCH 5/7] Fix broken tests --- .../Web.JS/tests/DefaultReconnectionHandler.test.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Components/Web.JS/tests/DefaultReconnectionHandler.test.ts b/src/Components/Web.JS/tests/DefaultReconnectionHandler.test.ts index 4d34c08c79fc..fa0e1624d956 100644 --- a/src/Components/Web.JS/tests/DefaultReconnectionHandler.test.ts +++ b/src/Components/Web.JS/tests/DefaultReconnectionHandler.test.ts @@ -31,7 +31,8 @@ describe('DefaultReconnectionHandler', () => { handler.onConnectionDown({ maxRetries: 1000, retryIntervalMilliseconds: 100, - dialogId: 'ignored' + dialogId: 'ignored', + reloadOnCircuitRejected: true }); handler.onConnectionUp(); @@ -48,7 +49,8 @@ describe('DefaultReconnectionHandler', () => { handler.onConnectionDown({ maxRetries: 1000, retryIntervalMilliseconds: 100, - dialogId: 'ignored' + dialogId: 'ignored', + reloadOnCircuitRejected: true }); expect(testDisplay.show).toHaveBeenCalled(); expect(testDisplay.failed).not.toHaveBeenCalled(); @@ -67,7 +69,8 @@ describe('DefaultReconnectionHandler', () => { handler.onConnectionDown({ maxRetries: 2, retryIntervalMilliseconds: 5, - dialogId: 'ignored' + dialogId: 'ignored', + reloadOnCircuitRejected: true }); await delay(500); @@ -85,7 +88,8 @@ describe('DefaultReconnectionHandler', () => { handler.onConnectionDown({ maxRetries: maxRetries, retryIntervalMilliseconds: 5, - dialogId: 'ignored' + dialogId: 'ignored', + reloadOnCircuitRejected: true }); await delay(500); From 70647ea474859a8096d653290689ae155b9ca4ee Mon Sep 17 00:00:00 2001 From: Konrad Bartecki Date: Tue, 18 Jan 2022 12:25:42 +0100 Subject: [PATCH 6/7] Remove whitespace Co-authored-by: Steve Sanderson --- .../Web.JS/src/Platform/Circuits/DefaultReconnectionHandler.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Components/Web.JS/src/Platform/Circuits/DefaultReconnectionHandler.ts b/src/Components/Web.JS/src/Platform/Circuits/DefaultReconnectionHandler.ts index 42df25ee4174..aa8eae4fb957 100644 --- a/src/Components/Web.JS/src/Platform/Circuits/DefaultReconnectionHandler.ts +++ b/src/Components/Web.JS/src/Platform/Circuits/DefaultReconnectionHandler.ts @@ -73,7 +73,7 @@ class ReconnectionProcess { const result = await this.reconnectCallback(); if (!result) { // If the server responded and refused to reconnect, stop auto-retrying. - this.reconnectDisplay.rejected(); + this.reconnectDisplay.rejected(); return; } return; From 29cfd30341e12224be916882312c01059a298b8e Mon Sep 17 00:00:00 2001 From: Konrad Bartecki Date: Mon, 24 Jan 2022 08:20:00 +0100 Subject: [PATCH 7/7] Revert back 3s reconnection interval to 20s --- .../Web.JS/src/Platform/Circuits/CircuitStartOptions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Components/Web.JS/src/Platform/Circuits/CircuitStartOptions.ts b/src/Components/Web.JS/src/Platform/Circuits/CircuitStartOptions.ts index d0f3b5fe1d47..c4c16fda2e55 100644 --- a/src/Components/Web.JS/src/Platform/Circuits/CircuitStartOptions.ts +++ b/src/Components/Web.JS/src/Platform/Circuits/CircuitStartOptions.ts @@ -36,7 +36,7 @@ const defaultOptions: CircuitStartOptions = { logLevel: LogLevel.Warning, reconnectionOptions: { maxRetries: 8, - retryIntervalMilliseconds: 3000, + retryIntervalMilliseconds: 20000, dialogId: 'components-reconnect-modal', reloadOnCircuitRejected: true, },