@@ -14,53 +14,15 @@ var abp = abp || {};
14
14
abp . signalr . increaseReconnectTime = abp . signalr . increaseReconnectTime || function ( time ) {
15
15
return time * 2 ;
16
16
} ;
17
- abp . signalr . withUrlOptions = abp . signalr . withUrlOptions || { } ;
17
+ abp . signalr . withUrlOptions = abp . signalr . withUrlOptions || { } ;
18
18
19
19
// Configure the connection for abp.signalr.hubs.common
20
20
function configureConnection ( connection ) {
21
21
// Set the common hub
22
22
abp . signalr . hubs . common = connection ;
23
23
24
- let tries = 1 ;
25
24
let reconnectTime = abp . signalr . reconnectTime ;
26
25
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
-
64
26
// Register to get notifications
65
27
connection . on ( 'getNotification' , function ( notification ) {
66
28
abp . event . trigger ( 'abp.notifications.received' , notification ) ;
@@ -104,6 +66,18 @@ var abp = abp || {};
104
66
abp . log . debug ( 'Starting connection using ' + signalR . HttpTransportType [ transport ] + ' transport' ) ;
105
67
abp . signalr . withUrlOptions . transport = transport ;
106
68
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
+ } )
107
81
. withUrl ( url , abp . signalr . withUrlOptions )
108
82
. build ( ) ;
109
83
0 commit comments