1- import * as SignalR from "@aspnet /signalr" ;
1+ import * as SignalR from "@microsoft /signalr" ;
22import { AppEvents } from './app.common' ;
33
44class SignalRApp {
@@ -18,6 +18,7 @@ class SignalRApp {
1818 this . connection = new SignalR . HubConnectionBuilder ( )
1919 . withUrl ( options . url , options )
2020 . configureLogging ( SignalR . LogLevel . Information )
21+ . withAutomaticReconnect ( [ 0 , 3000 , 5000 , 10000 , 15000 , 30000 ] )
2122 . build ( ) ;
2223
2324 //Receive Data
@@ -29,6 +30,24 @@ class SignalRApp {
2930 self . processResponse . call ( self . connection , data ) ;
3031 self . HandleResponse ( data ) ;
3132 }
33+
34+ self . connection . onreconnecting ( ( error ) => {
35+ // disableUi(true);
36+ // const li = document.createElement("li");
37+ // li.textContent = `Connection lost due to error "${error}". Reconnecting.`;
38+ // document.getElementById("messagesList").appendChild(li);
39+ AppEvents . emit ( 'Logger' , `Connection lost due to error "${ error } ". Reconnecting.` ) ;
40+ console . log ( 'On Reconnecting...' ) ;
41+ } ) ;
42+
43+ self . connection . onreconnected ( ( connectionId ) => {
44+ // disableUi(false);
45+ // const li = document.createElement("li");
46+ // li.textContent = `Connection reestablished. Connected.`;
47+ // document.getElementById("messagesList").appendChild(li);
48+ AppEvents . emit ( 'Logger' , `Connection reestablished. Connected` ) ;
49+ console . log ( 'On Reconnected...' ) ;
50+ } ) ;
3251
3352 AppEvents . emit ( 'Init' , options ) ;
3453 AppEvents . emit ( 'Logger' , "Init" ) ;
0 commit comments