WebSocket plugin is integrated to main Elysia package via elysia/ws
since Elysia 0.3.0.
Plugin for elysia that add support for websocket.
bun add @elysiajs/websocket
import { Elysia } from 'elysia'
import { websocket } from '@elysiajs/websocket'
const app = new Elysia()
.use(websocket())
.ws('/ws', {
message(ws, message) {
ws.message('Hi')
}
})
.listen(8080)
This plugin extends Elysia
class with ws
method.
Register Websocket to route
Parameters:
ws(
path: string,
options: Partial<WebSocketHandler<Context>> & {
schema?: Schema
beforeHandle?: WithArray<HookHandler>
headers?:
| HeadersInit
| (Context) => HeadersInt
}
): this