Skip to content

SaltyAom/kingworld-websocket

Repository files navigation

@kingworldjs/websocket

A plugin for kingworld that add support for websocket.

Installation

bun add @kingworldjs/websocket

Example

import { KingWorld } from 'kingworld'
import { websocket } from '@kingworldjs/websocket'

const app = new KingWorld()
    .use(websocket())
    .ws('/ws', {
        message(ws, message) {
            ws.message('Hi')
        }
    })
    .listen(8080)

API

This plugin extends KingWorld class with ws method.

ws

Register Websocket to route

Parameters:

ws(
    path: string,
    options: Partial<WebSocketHandler<Context>> & {
        schema?: Schema
        beforeHandle?: WithArray<HookHandler>
        headers?:
            | HeadersInit
            | (Context) => HeadersInt
    }
): this

About

A plugin for KingWorld that add support for websocket

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published