You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
488 B
JavaScript
25 lines
488 B
JavaScript
import { useWebSocket, useBrowserLocation } from '@vueuse/core'
|
|
|
|
const location = useBrowserLocation()
|
|
let origin = 'ws://localhost:3000'
|
|
|
|
if (location && location.value.origin) {
|
|
origin = location.value.origin.replace(/^http/, 'ws')
|
|
}
|
|
|
|
const { status, data, send, open, close } = useWebSocket(origin, {
|
|
autoReconnect: true,
|
|
immediate: false,
|
|
autoClose: false,
|
|
})
|
|
|
|
export default function connectWebsocket() {
|
|
return {
|
|
status,
|
|
data,
|
|
send,
|
|
open,
|
|
close,
|
|
}
|
|
}
|