Skip to content

Commit

Permalink
fix(useWebSocket): don't reconnect WebSocket if close issued betwee…
Browse files Browse the repository at this point in the history
…n retries (#2330)
  • Loading branch information
rotu committed Oct 25, 2022
1 parent c88491b commit d4c3263
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/core/useWebSocket/index.ts
Expand Up @@ -203,10 +203,12 @@ export function useWebSocket<Data = any>(
}

const _init = () => {
if (explicitlyClosed)
return

const ws = new WebSocket(url, protocols)
wsRef.value = ws
status.value = 'CONNECTING'
explicitlyClosed = false

ws.onopen = () => {
status.value = 'OPEN'
Expand Down Expand Up @@ -289,6 +291,7 @@ export function useWebSocket<Data = any>(

const open = () => {
close()
explicitlyClosed = false
retried = 0
_init()
}
Expand Down

0 comments on commit d4c3263

Please sign in to comment.