Skip to content

Commit aea27f8

Browse files
alipay404antfu
alipay404
andauthored
fix(useWebsocket): reset pongTimeout on close (#3324)
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
1 parent 72cc6e4 commit aea27f8

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

packages/core/useWebSocket/index.ts

+10-9
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,6 @@ export function useWebSocket<Data = any>(
171171

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

174-
// Status code 1000 -> Normal Closure https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent/code
175-
const close: WebSocket['close'] = (code = 1000, reason) => {
176-
if (!wsRef.value)
177-
return
178-
explicitlyClosed = true
179-
heartbeatPause?.()
180-
wsRef.value.close(code, reason)
181-
}
182-
183174
const _sendBuffer = () => {
184175
if (bufferedData.length && wsRef.value && status.value === 'OPEN') {
185176
for (const buffer of bufferedData)
@@ -193,6 +184,16 @@ export function useWebSocket<Data = any>(
193184
pongTimeoutWait = undefined
194185
}
195186

187+
// Status code 1000 -> Normal Closure https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent/code
188+
const close: WebSocket['close'] = (code = 1000, reason) => {
189+
if (!wsRef.value)
190+
return
191+
explicitlyClosed = true
192+
resetHeartbeat()
193+
heartbeatPause?.()
194+
wsRef.value.close(code, reason)
195+
}
196+
196197
const send = (data: string | ArrayBuffer | Blob, useBuffer = true) => {
197198
if (!wsRef.value || status.value !== 'OPEN') {
198199
if (useBuffer)

0 commit comments

Comments
 (0)