@@ -14,53 +14,15 @@ var abp = abp || {};
1414 abp . signalr . increaseReconnectTime = abp . signalr . increaseReconnectTime || function ( time ) {
1515 return time * 2 ;
1616 } ;
17- abp . signalr . withUrlOptions = abp . signalr . withUrlOptions || { } ;
17+ abp . signalr . withUrlOptions = abp . signalr . withUrlOptions || { } ;
1818
1919 // Configure the connection for abp.signalr.hubs.common
2020 function configureConnection ( connection ) {
2121 // Set the common hub
2222 abp . signalr . hubs . common = connection ;
2323
24- let tries = 1 ;
2524 let reconnectTime = abp . signalr . reconnectTime ;
2625
27- // Reconnect loop
28- function tryReconnect ( ) {
29- if ( tries <= abp . signalr . maxTries ) {
30- connection . start ( )
31- . then ( function ( ) {
32- reconnectTime = abp . signalr . reconnectTime ;
33- tries = 1 ;
34- console . log ( 'Reconnected to SignalR server!' ) ;
35- abp . event . trigger ( 'abp.signalr.reconnected' ) ;
36- } ) . catch ( function ( ) {
37- tries += 1 ;
38- reconnectTime = abp . signalr . increaseReconnectTime ( reconnectTime ) ;
39- setTimeout ( function ( ) {
40- tryReconnect ( )
41- } ,
42- reconnectTime
43- ) ;
44- } ) ;
45- }
46- }
47-
48- // Reconnect if hub disconnects
49- connection . onclose ( function ( e ) {
50- if ( e ) {
51- abp . log . debug ( 'Connection closed with error: ' + e ) ;
52- } else {
53- abp . log . debug ( 'Disconnected' ) ;
54- }
55-
56- if ( ! abp . signalr . autoReconnect ) {
57- return ;
58- }
59-
60- abp . event . trigger ( 'abp.signalr.disconnected' ) ;
61- tryReconnect ( ) ;
62- } ) ;
63-
6426 // Register to get notifications
6527 connection . on ( 'getNotification' , function ( notification ) {
6628 abp . event . trigger ( 'abp.notifications.received' , notification ) ;
@@ -104,6 +66,18 @@ var abp = abp || {};
10466 abp . log . debug ( 'Starting connection using ' + signalR . HttpTransportType [ transport ] + ' transport' ) ;
10567 abp . signalr . withUrlOptions . transport = transport ;
10668 var connection = new signalR . HubConnectionBuilder ( )
69+ . withAutomaticReconnect ( {
70+ nextRetryDelayInMilliseconds : retryContext => {
71+ abp . log . debug ( 'Retry to connect to SignalR' ) ;
72+ if ( retryContext . previousRetryCount > maxTries ) {
73+ abp . log . debug ( 'Max retries reached' ) ;
74+ return null ;
75+ }
76+ reconnectTime *= 2 ;
77+ abp . log . debug ( 'Waiting ' + reconnectTime + 'ms before retrying' ) ;
78+ return reconnectTime ;
79+ }
80+ } )
10781 . withUrl ( url , abp . signalr . withUrlOptions )
10882 . build ( ) ;
10983
0 commit comments