GitHub - muzychenka/vue3-websocket: Simple package for implementing WebSocket into your Vue 3 application (original) (raw)

Vue 3 WebSocket

Important

Since v2.0.0 it's not a plugin anymore, but a composable

Simple package for implementing WebSocket into your Vue 3 application using Composition API

Install dependency via pnpm/npm

or

You'll also need zod to be installed

or

For connection you should provide WS/WSS address as a string line or an object data

Direct manipulation of socket connection

Providing typed interfaces for incoming messages

There is a reactive readyState field available. You can track it using watchers

Connection options interfaces

interface IConnection extends IConnectionOptions { secured?: boolean host: string path?: string debug?: boolean }

interface IConnectionOptions { debug?: boolean reconnect?: boolean reconnectDelay?: number protocols?: string[] }

If debug is set to true, there will be debug messages in the console about some WS events

Available events: