Angular: 9,
SignalR: "@microsoft/signalr": "^6.0.0"
//The following code creates and starts a connection
hubConnection: signalR.HubConnection;
this.hubConnection = new signalR.HubConnectionBuilder()
.withUrl(
`<url>`)
.withAutomaticReconnect()
.build();
this.hubConnection
.start()
.then(() => {
console.log('Connection Started...');
this.receiveMessageEvent();
})
.catch((err) => {
console.log('Error while starting connection: ' + err);
});
receiveMessageEvent() {
this.hubConnection.on(
'receiveMessage',
(message: any) => {
console.log(message);
}
);
}
getting issue while internet get offline,
Error: Connection disconnected with error 'Error: WebSocket closed with status code: 1006 (no reason given).'.
Issue: when the internet gets a connection after some minutes of disconnection we need to refresh the screen to connect the hub.
looking for: It should automatically re-connect when the internet gets connected.
How to re-connect hub connection when internet get online?