Skip to content

Commit

Permalink
chore(useWebSocket): skip call to clearTimeout when heartbeat disabled (
Browse files Browse the repository at this point in the history
  • Loading branch information
rotu committed Oct 25, 2022
1 parent a3af5fa commit ec7e69b
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions packages/core/useWebSocket/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export function useWebSocket<Data = any>(

let bufferedData: (string | ArrayBuffer | Blob)[] = []

let pongTimeoutWait: ReturnType<typeof setTimeout>
let pongTimeoutWait: ReturnType<typeof setTimeout> | undefined

// Status code 1000 -> Normal Closure https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent/code
const close: WebSocket['close'] = (code = 1000, reason) => {
Expand Down Expand Up @@ -242,9 +242,8 @@ export function useWebSocket<Data = any>(
}

ws.onmessage = (e: MessageEvent) => {
resetHeartbeat()
// Heartbeat response will be skipped
if (options.heartbeat) {
resetHeartbeat()
const {
message = DEFAULT_PING_MESSAGE,
} = resolveNestedOptions(options.heartbeat)
Expand Down

0 comments on commit ec7e69b

Please sign in to comment.