forked from HenningM/express-ws
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
46 lines (37 loc) · 1.27 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import * as express from "express";
import * as core from "express-serve-static-core";
import * as http from "http";
import * as https from "https";
import * as ws from "ws";
declare module "express" {
function Router(options?: RouterOptions): expressWs.Router;
}
interface RouterLike {
get: express.IRouterMatcher<this>;
[key: string]: any;
[key: number]: any;
}
export function expressWs(
app: express.Application,
server?: http.Server | https.Server,
options?: expressWs.Options,
): expressWs.Instance;
export function addWsMethod(target: RouterLike): void;
declare namespace expressWs {
type Application = express.Application & WithWebsocketMethod;
type Router = express.Router & WithWebsocketMethod;
interface Options {
leaveRouterUntouched?: boolean | undefined;
wsOptions?: ws.ServerOptions | undefined;
}
interface Instance {
app: Application;
applyTo(target: RouterLike): void;
getWss(): ws.Server;
}
type WebsocketRequestHandler = (ws: ws, req: express.Request, next: express.NextFunction) => void;
type WebsocketMethod<T> = (route: core.PathParams, ...middlewares: WebsocketRequestHandler[]) => T;
interface WithWebsocketMethod {
ws: WebsocketMethod<this>;
}
}