@kingworldjs/websocket
TypeScript icon, indicating that this package has built-in type declarations

0.0.0-experimental.7 • Public • Published

@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

Readme

Keywords

Package Sidebar

Install

npm i @kingworldjs/websocket

Weekly Downloads

1

Version

0.0.0-experimental.7

License

MIT

Unpacked Size

53.1 kB

Total Files

25

Last publish

Collaborators

  • aomkirby123