Skip to content

Commit

Permalink
docs(useWebSocket): heartbeat message type (#2243)
Browse files Browse the repository at this point in the history
  • Loading branch information
shuperry committed Sep 25, 2022
1 parent c8c38a5 commit 4b72d97
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 1 deletion.
101 changes: 101 additions & 0 deletions packages/core/useWebSocket/index.md
Expand Up @@ -76,6 +76,107 @@ const { status, data, close } = useWebSocket('ws://websocketurl', {
})
```

<!--FOOTER_STARTS-->
## Type Declarations

```typescript
export declare type WebSocketStatus = "OPEN" | "CONNECTING" | "CLOSED"
export interface WebSocketOptions {
onConnected?: (ws: WebSocket) => void
onDisconnected?: (ws: WebSocket, event: CloseEvent) => void
onError?: (ws: WebSocket, event: Event) => void
onMessage?: (ws: WebSocket, event: MessageEvent) => void
/**
* Send heartbeat for every x mileseconds passed
*
* @default false
*/
heartbeat?:
| boolean
| {
/**
* Message for the heartbeat
*
* @default 'ping'
*/
message?: string | ArrayBuffer | Blob
/**
* Interval, in mileseconds
*
* @default 1000
*/
interval?: number
}
/**
* Enabled auto reconnect
*
* @default false
*/
autoReconnect?:
| boolean
| {
/**
* Maximum retry times.
*
* @default -1
*/
retries?: number
/**
* Delay for reconnect, in mileseconds
*
* @default 1000
*/
delay?: number
/**
* On maximum retry times reached.
*/
onFailed?: Fn
}
}
export interface WebSocketResult<T> {
/**
* Reference to the latest data received via the websocket,
* can be watched to respond to incoming messages
*/
data: Ref<T | null>
/**
* The current websocket status, can be only one of:
* 'OPEN', 'CONNECTING', 'CLOSED'
*/
status: Ref<WebSocketStatus>
/**
* Closes the websocket connection gracefully.
*/
close: WebSocket["close"]
/**
* Reopen the websocket connection.
* If there the current one is active, will close it before opening a new one.
*/
open: Fn
/**
* Sends data through the websocket connection.
*
* @param data
* @param useBuffer when the socket is not yet open, store the data into the buffer and sent them one connected. Default to true.
*/
send: (data: string | ArrayBuffer | Blob, useBuffer?: boolean) => boolean
/**
* Reference to the WebSocket instance.
*/
ws: Ref<WebSocket | undefined>
}
/**
* Reactive WebSocket client.
*
* @see {@link https://vueuse.org/useWebSocket}
* @param url
*/
export declare function useWebSocket<Data = any>(
url: string,
options?: WebSocketOptions
): WebSocketResult<Data>
```

### Sub-protocols

List of one or more subprotocols to use, in this case soap and wamp.
Expand Down
2 changes: 1 addition & 1 deletion packages/core/useWebSocket/index.ts
Expand Up @@ -25,7 +25,7 @@ export interface UseWebSocketOptions {
*
* @default 'ping'
*/
message?: string
message?: string | ArrayBuffer | Blob

/**
* Interval, in milliseconds
Expand Down

0 comments on commit 4b72d97

Please sign in to comment.