1
1
import type { Fn , MaybeRefOrGetter } from '@vueuse/shared'
2
2
import type { Ref } from 'vue'
3
- import { isClient , isWorker , toRef , tryOnScopeDispose , useIntervalFn } from '@vueuse/shared'
3
+ import { isClient , isWorker , toRef , toValue , tryOnScopeDispose , useIntervalFn } from '@vueuse/shared'
4
4
import { ref , watch } from 'vue'
5
5
import { useEventListener } from '../useEventListener'
6
6
7
7
export type WebSocketStatus = 'OPEN' | 'CONNECTING' | 'CLOSED'
8
+ export type WebSocketHeartbeatMessage = string | ArrayBuffer | Blob
8
9
9
10
const DEFAULT_PING_MESSAGE = 'ping'
10
11
@@ -25,12 +26,12 @@ export interface UseWebSocketOptions {
25
26
*
26
27
* @default 'ping'
27
28
*/
28
- message ?: string | ArrayBuffer | Blob
29
+ message ?: MaybeRefOrGetter < WebSocketHeartbeatMessage >
29
30
30
31
/**
31
32
* Response message for the heartbeat, if undefined the message will be used
32
33
*/
33
- responseMessage ?: string | ArrayBuffer | Blob
34
+ responseMessage ?: MaybeRefOrGetter < WebSocketHeartbeatMessage >
34
35
35
36
/**
36
37
* Interval, in milliseconds
@@ -262,7 +263,7 @@ export function useWebSocket<Data = any>(
262
263
message = DEFAULT_PING_MESSAGE ,
263
264
responseMessage = message ,
264
265
} = resolveNestedOptions ( options . heartbeat )
265
- if ( e . data === responseMessage )
266
+ if ( e . data === toValue ( responseMessage ) )
266
267
return
267
268
}
268
269
@@ -280,7 +281,7 @@ export function useWebSocket<Data = any>(
280
281
281
282
const { pause, resume } = useIntervalFn (
282
283
( ) => {
283
- send ( message , false )
284
+ send ( toValue ( message ) , false )
284
285
if ( pongTimeoutWait != null )
285
286
return
286
287
pongTimeoutWait = setTimeout ( ( ) => {
0 commit comments