mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Add type definitions for koa-websocket (#16221)
This commit is contained in:
parent
0a29ae08a9
commit
0cefb71e50
36
types/koa-websocket/index.d.ts
vendored
Normal file
36
types/koa-websocket/index.d.ts
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
// Type definitions for koa-websocket 2.1
|
||||
// Project: https://github.com/kudos/koa-websocket
|
||||
// Definitions by: My Self <https://github.com/me>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
import * as Koa from 'koa';
|
||||
import * as ws from 'ws';
|
||||
import * as http from 'http';
|
||||
import * as https from 'https';
|
||||
|
||||
type KoaWebsocketConnectionHandler = (socket: ws) => void;
|
||||
type KoaWebsocketMiddleware = (this: KoaWebsocketMiddlewareContext, context: Koa.Context, next: () => Promise<any>) => any;
|
||||
interface KoaWebsocketMiddlewareContext extends Koa.Context {
|
||||
websocket: ws;
|
||||
path: string;
|
||||
}
|
||||
|
||||
declare class KoaWebsocketServer {
|
||||
app: Koa;
|
||||
middleware: Koa.Middleware[];
|
||||
|
||||
constructor(app: Koa);
|
||||
listen(server: http.Server | https.Server): ws.Server;
|
||||
onConnection(handler: KoaWebsocketConnectionHandler): void;
|
||||
use(middleware: KoaWebsocketMiddleware): this;
|
||||
}
|
||||
|
||||
interface KoaWebsocketApp extends Koa {
|
||||
ws: KoaWebsocketServer;
|
||||
}
|
||||
|
||||
type KoaWebsockets = (app: Koa) => KoaWebsocketApp;
|
||||
|
||||
declare const websockets: KoaWebsockets;
|
||||
export = websockets;
|
||||
14
types/koa-websocket/koa-websocket-tests.ts
Normal file
14
types/koa-websocket/koa-websocket-tests.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import * as Koa from 'koa';
|
||||
import * as websocket from 'koa-websocket';
|
||||
|
||||
const app = websocket(new Koa());
|
||||
|
||||
app.ws.use(async function(context, next) {
|
||||
this.websocket.on('message', (message) => {
|
||||
console.log(message);
|
||||
});
|
||||
this.websocket.send('Hello world');
|
||||
await next();
|
||||
});
|
||||
|
||||
app.listen(3000);
|
||||
22
types/koa-websocket/tsconfig.json
Normal file
22
types/koa-websocket/tsconfig.json
Normal file
@ -0,0 +1,22 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"koa-websocket-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/koa-websocket/tslint.json
Normal file
1
types/koa-websocket/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user