-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Blazor Server - Auto reconnect on mobile browsers #32122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
75805a7
e44c828
69c4780
bd1015f
f2f6cdb
70647ea
29cfd30
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems like a pretty good idea to me. I'm not 100% sold on reloading automatically by default (we need to at least reason about why that wasn't already our default) but the ability to configure a handler for this scenario seems valuable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For back-compatibility, this new property needs to be added as optional |
||
} | ||
|
||
const defaultOptions: CircuitStartOptions = { | ||
|
@@ -36,5 +38,6 @@ const defaultOptions: CircuitStartOptions = { | |
maxRetries: 8, | ||
retryIntervalMilliseconds: 20000, | ||
dialogId: 'components-reconnect-modal', | ||
reloadOnCircuitRejected: true, | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,11 +35,15 @@ export class DefaultReconnectionHandler implements ReconnectionHandler { | |
this._currentReconnectionProcess = null; | ||
} | ||
} | ||
|
||
onConnectionRejected(options: ReconnectionOptions) { | ||
if (options.reloadOnCircuitRejected) { | ||
location.reload(); | ||
} | ||
} | ||
}; | ||
|
||
class ReconnectionProcess { | ||
static readonly MaximumFirstRetryInterval = 3000; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does anyone remember why we implemented this originally? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Most likely because after connection goes down it would try to attempt the reconnection only after 20s, which is quite a long time. |
||
|
||
readonly reconnectDisplay: ReconnectDisplay; | ||
isDisposed = false; | ||
|
||
|
@@ -57,12 +61,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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since |
||
|
||
if (this.isDisposed) { | ||
break; | ||
} | ||
|
@@ -83,6 +81,7 @@ class ReconnectionProcess { | |
// We got an exception so will try again momentarily | ||
this.logger.log(LogLevel.Error, err); | ||
} | ||
await this.delay(options.retryIntervalMilliseconds); | ||
} | ||
|
||
this.reconnectDisplay.failed(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect we should be checking whether
reconnectionHandler
oronConnectionRejected
are unset, and skipping the call if so. Or is there some way we know for sure that both of them are set?Example (untested):