Skip to content

Commit

Permalink
fix(useWebSocket): don't hide pong setTimeout reference (#2206)
Browse files Browse the repository at this point in the history
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
  • Loading branch information
kellerza and antfu committed Nov 9, 2022
1 parent 934a893 commit 65f4341
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/core/useWebSocket/index.ts
Expand Up @@ -190,6 +190,7 @@ export function useWebSocket<Data = any>(

const resetHeartbeat = () => {
clearTimeout(pongTimeoutWait)
pongTimeoutWait = undefined
}

const send = (data: string | ArrayBuffer | Blob, useBuffer = true) => {
Expand Down Expand Up @@ -269,6 +270,8 @@ export function useWebSocket<Data = any>(
const { pause, resume } = useIntervalFn(
() => {
send(message, false)
if (pongTimeoutWait != null)
return
pongTimeoutWait = setTimeout(() => {
// auto-reconnect will be trigger with ws.onclose()
close()
Expand Down

0 comments on commit 65f4341

Please sign in to comment.