-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Client reconnects when state's available on the server #7395
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
598851d
Client reconnects when state's available on the server
pranavkm bd5768a
Remove RemoteUriHelper
pranavkm 6bff984
More cleanup
pranavkm fcff3f1
Add css to template
pranavkm f08a064
Clean up unused variable
pranavkm 292e093
Changes per PR
pranavkm fb25d86
Remove css
pranavkm f1d1ef5
More changes per PR
pranavkm babfe89
Undo renderer changes
pranavkm 6da5aa6
changes per PR
pranavkm 708dfed
Fix ref file
pranavkm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
module.exports = { | ||
globals: { | ||
"ts-jest": { | ||
"tsConfig": "./tests/tsconfig.json", | ||
"babeConfig": true, | ||
"diagnostics": true | ||
} | ||
}, | ||
preset: 'ts-jest', | ||
testEnvironment: 'jsdom' | ||
}; | ||
pranavkm marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/Components/Browser.JS/src/Platform/Circuits/AutoReconnectCircuitHandler.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { CircuitHandler } from './CircuitHandler'; | ||
import { UserSpecifiedDisplay } from './UserSpecifiedDisplay'; | ||
import { DefaultReconnectDisplay } from './DefaultReconnectDisplay'; | ||
import { ReconnectDisplay } from './ReconnectDisplay'; | ||
export class AutoReconnectCircuitHandler implements CircuitHandler { | ||
static readonly MaxRetries = 5; | ||
static readonly RetryInterval = 3000; | ||
static readonly DialogId = 'components-reconnect-modal'; | ||
reconnectDisplay: ReconnectDisplay; | ||
|
||
constructor() { | ||
this.reconnectDisplay = new DefaultReconnectDisplay(document); | ||
document.addEventListener('DOMContentLoaded', () => { | ||
const modal = document.getElementById(AutoReconnectCircuitHandler.DialogId); | ||
if (modal) { | ||
this.reconnectDisplay = new UserSpecifiedDisplay(modal); | ||
} | ||
}); | ||
} | ||
onConnectionUp() : void{ | ||
this.reconnectDisplay.hide(); | ||
} | ||
|
||
delay() : Promise<void>{ | ||
return new Promise((resolve) => setTimeout(resolve, AutoReconnectCircuitHandler.RetryInterval)); | ||
} | ||
|
||
async onConnectionDown() : Promise<void> { | ||
this.reconnectDisplay.show(); | ||
|
||
for (let i = 0; i < AutoReconnectCircuitHandler.MaxRetries; i++) { | ||
await this.delay(); | ||
try { | ||
const result = await window['Blazor'].reconnect(); | ||
if (!result) { | ||
// If the server responded and refused to reconnect, stop auto-retrying. | ||
break; | ||
} | ||
return; | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
} | ||
|
||
this.reconnectDisplay.failed(); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/Components/Browser.JS/src/Platform/Circuits/CircuitHandler.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export interface CircuitHandler { | ||
/** Invoked when a server connection is established or re-established after a connection failure. | ||
*/ | ||
onConnectionUp?() : void; | ||
|
||
/** Invoked when a server connection is dropped. | ||
* @param {Error} error Optionally argument containing the error that caused the connection to close (if any). | ||
*/ | ||
onConnectionDown?(error?: Error): void; | ||
} |
50 changes: 50 additions & 0 deletions
50
src/Components/Browser.JS/src/Platform/Circuits/DefaultReconnectDisplay.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { ReconnectDisplay } from "./ReconnectDisplay"; | ||
import { AutoReconnectCircuitHandler } from "./AutoReconnectCircuitHandler"; | ||
export class DefaultReconnectDisplay implements ReconnectDisplay { | ||
modal: HTMLDivElement; | ||
message: HTMLHeadingElement; | ||
button: HTMLButtonElement; | ||
addedToDom: boolean = false; | ||
constructor(private document: Document) { | ||
this.modal = this.document.createElement('div'); | ||
this.modal.id = AutoReconnectCircuitHandler.DialogId; | ||
|
||
const modalStyles = [ | ||
"position: fixed", | ||
"top: 0", | ||
"right: 0", | ||
"bottom: 0", | ||
"left: 0", | ||
"z-index: 1000", | ||
"display: none", | ||
"overflow: hidden", | ||
"background-color: #fff", | ||
"opacity: 0.8", | ||
"text-align: center", | ||
"font-weight: bold" | ||
]; | ||
|
||
this.modal.style.cssText = modalStyles.join(';'); | ||
this.modal.innerHTML = '<h5 style="margin-top: 20px"></h5><button style="margin:5px auto 5px">Retry?</button>'; | ||
this.message = this.modal.querySelector('h5')!; | ||
this.button = this.modal.querySelector('button')!; | ||
|
||
this.button.addEventListener('click', () => window['Blazor'].reconnect()); | ||
pranavkm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
show(): void { | ||
if (!this.addedToDom) { | ||
this.addedToDom = true; | ||
this.document.body.appendChild(this.modal); | ||
} | ||
this.modal.style.display = 'block'; | ||
this.button.style.display = 'none'; | ||
this.message.textContent = 'Attempting to reconnect to the server...'; | ||
} | ||
hide(): void { | ||
this.modal.style.display = 'none'; | ||
} | ||
failed(): void { | ||
this.button.style.display = 'block'; | ||
this.message.textContent = 'Failed to reconnect to the server.'; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/Components/Browser.JS/src/Platform/Circuits/ReconnectDisplay.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export interface ReconnectDisplay { | ||
show(): void; | ||
hide(): void; | ||
failed(): void; | ||
} |
23 changes: 23 additions & 0 deletions
23
src/Components/Browser.JS/src/Platform/Circuits/UserSpecifiedDisplay.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { ReconnectDisplay } from "./ReconnectDisplay"; | ||
export class UserSpecifiedDisplay implements ReconnectDisplay { | ||
static readonly ShowClassName = 'components-reconnect-show'; | ||
static readonly HideClassName = 'components-reconnect-hide'; | ||
static readonly FailedClassName = 'components-reconnect-failed'; | ||
constructor(private dialog: HTMLElement) { | ||
} | ||
show(): void { | ||
this.removeClasses(); | ||
this.dialog.classList.add(UserSpecifiedDisplay.ShowClassName); | ||
} | ||
hide(): void { | ||
this.removeClasses(); | ||
this.dialog.classList.add(UserSpecifiedDisplay.HideClassName); | ||
} | ||
failed(): void { | ||
this.removeClasses(); | ||
this.dialog.classList.add(UserSpecifiedDisplay.FailedClassName); | ||
} | ||
private removeClasses() { | ||
this.dialog.classList.remove(UserSpecifiedDisplay.ShowClassName, UserSpecifiedDisplay.HideClassName, UserSpecifiedDisplay.FailedClassName); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,3 @@ | ||
{ | ||
"compilerOptions": { | ||
"noImplicitAny": false, | ||
"noEmitOnError": true, | ||
"removeComments": false, | ||
"sourceMap": true, | ||
"target": "es5", | ||
"lib": ["es2015", "dom"], | ||
"strict": true | ||
}, | ||
"exclude": [ | ||
"node_modules", | ||
"wwwroot" | ||
] | ||
"extends": "../tsconfig.base.json" | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.