File tree 3 files changed +16
-1
lines changed
3 files changed +16
-1
lines changed Original file line number Diff line number Diff line change 83
83
- Accepts ` integer `
84
84
- Default: ` 1000 `
85
85
86
+ #### ` maxReconnectInterval `
87
+ - The maximum number of milliseconds to delay a reconnection attempt.
88
+ - Accepts ` integer `
89
+ - Default: ` 30000 `
90
+
86
91
####` reconnectDecay `
87
92
- The rate of increase of the reconnect delay. Allows reconnect attempts to back off when problems persist.
88
93
- Accepts ` integer ` or ` float `
Original file line number Diff line number Diff line change 79
79
* reconnectInterval
80
80
* - The number of milliseconds to delay before attempting to reconnect. Accepts integer. Default: 1000.
81
81
*
82
+ * maxReconnectInterval
83
+ * - The maximum number of milliseconds to delay a reconnection attempt. Accepts integer. Default: 30000.
84
+ *
82
85
* reconnectDecay
83
86
* - The rate of increase of the reconnect delay. Allows reconnect attempts to back off when problems persist. Accepts integer or float. Default: 1.5.
84
87
*
104
107
debug : false ,
105
108
/** The number of milliseconds to delay before attempting to reconnect. */
106
109
reconnectInterval : 1000 ,
110
+ /** The maximum number of milliseconds to delay a reconnection attempt. */
111
+ maxReconnectInterval : 30000 ,
107
112
/** The rate of increase of the reconnect delay. Allows reconnect attempts to back off when problems persist. */
108
113
reconnectDecay : 1.5 ,
109
114
/** The maximum time in milliseconds to wait for a connection to succeed before closing and retrying. */
232
237
}
233
238
eventTarget . dispatchEvent ( generateEvent ( 'close' ) ) ;
234
239
}
240
+
241
+ var timeout = self . reconnectInterval * Math . pow ( self . reconnectDecay , self . reconnectAttempts ) ;
235
242
setTimeout ( function ( ) {
236
243
self . reconnectAttempts ++ ;
237
244
connect ( true ) ;
238
- } , self . reconnectInterval * Math . pow ( self . reconnectDecay , self . reconnectAttempts ) ) ;
245
+ } , timeout > self . maxReconnectInterval ? self . maxReconnectInterval : timeout ) ;
239
246
}
240
247
} ;
241
248
ws . onmessage = function ( event ) {
Original file line number Diff line number Diff line change @@ -23,6 +23,9 @@ declare class ReconnectingWebSocket
23
23
/** The number of milliseconds to delay before attempting to reconnect. */
24
24
public reconnectInterval : number ;
25
25
26
+ /** The maximum number of milliseconds to delay a reconnection attempt. */
27
+ public maxReconnectInterval : number ;
28
+
26
29
/** The rate of increase of the reconnect delay. Allows reconnect attempts to back off when problems persist. */
27
30
public reconnectDecay : number ;
28
31
You can’t perform that action at this time.
0 commit comments