@@ -181,6 +181,7 @@ export function useWebSocket<Data = any>(
181
181
182
182
let bufferedData : ( string | ArrayBuffer | Blob ) [ ] = [ ]
183
183
184
+ let retryTimeout : ReturnType < typeof setTimeout > | undefined
184
185
let pongTimeoutWait : ReturnType < typeof setTimeout > | undefined
185
186
186
187
const _sendBuffer = ( ) => {
@@ -191,13 +192,21 @@ export function useWebSocket<Data = any>(
191
192
}
192
193
}
193
194
195
+ const resetRetry = ( ) => {
196
+ if ( retryTimeout != null ) {
197
+ clearTimeout ( retryTimeout )
198
+ retryTimeout = undefined
199
+ }
200
+ }
201
+
194
202
const resetHeartbeat = ( ) => {
195
203
clearTimeout ( pongTimeoutWait )
196
204
pongTimeoutWait = undefined
197
205
}
198
206
199
207
// Status code 1000 -> Normal Closure https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent/code
200
208
const close : WebSocket [ 'close' ] = ( code = 1000 , reason ) => {
209
+ resetRetry ( )
201
210
if ( ( ! isClient && ! isWorker ) || ! wsRef . value )
202
211
return
203
212
explicitlyClosed = true
@@ -247,10 +256,10 @@ export function useWebSocket<Data = any>(
247
256
248
257
if ( typeof retries === 'number' && ( retries < 0 || retried < retries ) ) {
249
258
retried += 1
250
- setTimeout ( _init , delay )
259
+ retryTimeout = setTimeout ( _init , delay )
251
260
}
252
261
else if ( typeof retries === 'function' && retries ( ) ) {
253
- setTimeout ( _init , delay )
262
+ retryTimeout = setTimeout ( _init , delay )
254
263
}
255
264
else {
256
265
onFailed ?.( )
@@ -313,6 +322,7 @@ export function useWebSocket<Data = any>(
313
322
const open = ( ) => {
314
323
if ( ! isClient && ! isWorker )
315
324
return
325
+
316
326
close ( )
317
327
explicitlyClosed = false
318
328
retried = 0
0 commit comments