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

5.0.10 • Public • Published

Installation

npm install --save @types/koa-websocket

Summary

This package contains type definitions for koa-websocket (https://github.com/kudos/koa-websocket).

Details

Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/koa-websocket.

index.d.ts

import Koa = require("koa");
import compose = require("koa-compose");
import * as http from "http";
import * as https from "https";
import * as ws from "ws";

declare module "koa" {
    interface Context {
        websocket: ws;
        path: string;
    }
}

declare namespace KoaWebsocket {
    type Middleware<StateT = Koa.DefaultState, ContextT = Koa.DefaultContext> = compose.Middleware<
        MiddlewareContext<StateT> & ContextT
    >;

    interface MiddlewareContext<StateT> extends Koa.Context {
        // Limitation: Declaration merging cannot overwrap existing properties.
        // That's why this property is here, not in the merged declaration above.
        app: App;
        state: StateT;
    }

    class Server<StateT = Koa.DefaultState, ContextT = Koa.DefaultContext> {
        app: App;
        middleware: Array<Middleware<StateT, ContextT>>;
        server?: ws.Server | undefined;

        constructor(app: Koa<StateT, ContextT>);

        listen(options: ws.ServerOptions): ws.Server;
        onConnection(socket: ws, request: http.IncomingMessage): void;
        use(middleware: Middleware<StateT, ContextT>): this;
    }

    interface App<StateT = Koa.DefaultState, ContextT = Koa.DefaultContext> extends Koa<StateT, ContextT> {
        ws: Server<StateT, ContextT>;
    }
}

declare function KoaWebsocket<
    StateT = Koa.DefaultState,
    ContextT = Koa.DefaultContext,
>(
    app: Koa<StateT, ContextT>,
    wsOptions?: ws.ServerOptions,
    httpsOptions?: https.ServerOptions,
): KoaWebsocket.App<StateT, ContextT>;

export = KoaWebsocket;

Additional Details

Credits

These definitions were written by Maël Lavault, Jaco Greeff, Martin Ždila, Eunchong Yu, Christopher N. Katoyi-Kaba, and Zuo Jiazi.

/@types/koa-websocket/

    Package Sidebar

    Install

    npm i @types/koa-websocket

    Weekly Downloads

    2,208

    Version

    5.0.10

    License

    MIT

    Unpacked Size

    6.96 kB

    Total Files

    5

    Last publish

    Collaborators

    • types