Skip to content

Commit

Permalink
chore: update
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Aug 25, 2023
1 parent 85f7e07 commit 64ea898
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions packages/core/useWebSocket/index.ts
Expand Up @@ -171,16 +171,6 @@ export function useWebSocket<Data = any>(

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) => {
if (!wsRef.value)
return
explicitlyClosed = true
resetHeartbeat()
heartbeatPause?.()
wsRef.value.close(code, reason)
}

const _sendBuffer = () => {
if (bufferedData.length && wsRef.value && status.value === 'OPEN') {
for (const buffer of bufferedData)
Expand All @@ -194,6 +184,16 @@ export function useWebSocket<Data = any>(
pongTimeoutWait = undefined
}

// Status code 1000 -> Normal Closure https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent/code
const close: WebSocket['close'] = (code = 1000, reason) => {
if (!wsRef.value)
return
explicitlyClosed = true
resetHeartbeat()
heartbeatPause?.()
wsRef.value.close(code, reason)
}

const send = (data: string | ArrayBuffer | Blob, useBuffer = true) => {
if (!wsRef.value || status.value !== 'OPEN') {
if (useBuffer)
Expand Down

0 comments on commit 64ea898

Please sign in to comment.