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
- Last updated: Tue, 07 Nov 2023 09:09:38 GMT
- Dependencies: @types/koa, @types/koa-compose, @types/ws
Credits
These definitions were written by Maël Lavault, Jaco Greeff, Martin Ždila, Eunchong Yu, Christopher N. Katoyi-Kaba, and Zuo Jiazi.