Skip to content

Commit

Permalink
chore: Add koa-socket-2 ts declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
yinxin630 committed Aug 28, 2019
1 parent 2c7a81a commit 6b1b578
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 2 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules/
dist/
static/
public/
*.d.ts
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"ip": "^1.1.5",
"jwt-simple": "^0.5.1",
"koa": "^2.5.0",
"koa-router": "^7.4.0",
"koa-send": "^4.1.3",
"koa-socket-2": "^1.1.0",
"koa-static": "^4.0.2",
Expand Down Expand Up @@ -93,6 +94,7 @@
"@types/react-dom": "^16.8.5",
"@types/react-redux": "^7.1.1",
"@types/redux": "^3.6.0",
"@types/socket.io": "^2.1.2",
"@typescript-eslint/eslint-plugin": "^2.0.0",
"@typescript-eslint/parser": "^2.0.0",
"babel-loader": "^8.0.6",
Expand Down
41 changes: 41 additions & 0 deletions types/koa-socket-2.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// 声明来源: https://github.com/ambelovsky/koa-socket-2/issues/16

declare module 'koa-socket-2' {
import { ServerOptions as HttpsServerOptions } from 'https';
import Application from 'koa';
import { RouterContext } from 'koa-router';
import { ServerOptions as SocketioServerOptions } from 'socket.io';

interface IOptions {
namespace?: string;
hidden?: boolean;
ioOptions?: SocketioServerOptions;
}

type IEventHandler = (ctx: RouterContext) => any;

class IO {
public opts: IOptions;
public connections: Map<string, any>;
// tslint:disable-next-line:variable-name
private _io: any;
private middleware: any[];
private composed: any;
private listeners: Map<string, any>;
private socket: any;

constructor(opts: undefined | string | IOptions);
public attach(app: Application, https?: boolean, opts?: HttpsServerOptions): void;
public attachNamespace(app: Application, id: string): void;
public use(fn: any): this;
public on(event: string, handler: IEventHandler): this;
public off(event: string, handler: IEventHandler): this;
public broadcast(event: string, data: any): void;
public to(room: string): object;
private onConnection(sock: any): void;
private onDisconnect(sock: any): void;
private updateConnections(): void;
}

export = IO;
}
40 changes: 38 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,13 @@
"@types/express-serve-static-core" "*"
"@types/mime" "*"

"@types/socket.io@^2.1.2":
version "2.1.2"
resolved "https://registry.npm.taobao.org/@types/socket.io/download/@types/socket.io-2.1.2.tgz#7165c2587cc3b86b44aa78e2a0060140551de211"
integrity sha1-cWXCWHzDuGtEqnjioAYBQFUd4hE=
dependencies:
"@types/node" "*"

"@types/stack-utils@^1.0.1":
version "1.0.1"
resolved "https://registry.npm.taobao.org/@types/stack-utils/download/@types/stack-utils-1.0.1.tgz#0a851d3bd96498fa25c33ab7278ed3bd65f06c3e"
Expand Down Expand Up @@ -4236,7 +4243,7 @@ http-errors@1.7.2:
statuses ">= 1.5.0 < 2"
toidentifier "1.0.0"

http-errors@^1.6.1, http-errors@^1.6.3, http-errors@~1.7.2:
http-errors@^1.3.1, http-errors@^1.6.1, http-errors@^1.6.3, http-errors@~1.7.2:
version "1.7.3"
resolved "https://registry.npm.taobao.org/http-errors/download/http-errors-1.7.3.tgz#6c619e4f9c60308c38519498c14fbb10aacebb06"
dependencies:
Expand Down Expand Up @@ -4714,6 +4721,11 @@ is-wsl@^1.1.0:
version "1.1.0"
resolved "https://registry.npm.taobao.org/is-wsl/download/is-wsl-1.1.0.tgz?cache=0&sync_timestamp=1561271040070&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fis-wsl%2Fdownload%2Fis-wsl-1.1.0.tgz#1f16e4aa22b04d1336b66188a66af3c600c3a66d"

isarray@0.0.1:
version "0.0.1"
resolved "https://registry.npm.taobao.org/isarray/download/isarray-0.0.1.tgz?cache=0&sync_timestamp=1562592096220&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fisarray%2Fdownload%2Fisarray-0.0.1.tgz#8a18acfca9a8f4177e09abfc6038939b05d1eedf"
integrity sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=

isarray@1.0.0, isarray@^1.0.0, isarray@~1.0.0:
version "1.0.0"
resolved "https://registry.npm.taobao.org/isarray/download/isarray-1.0.0.tgz?cache=0&sync_timestamp=1562592096220&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fisarray%2Fdownload%2Fisarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11"
Expand Down Expand Up @@ -5288,6 +5300,18 @@ koa-is-json@^1.0.0:
version "1.0.0"
resolved "https://registry.npm.taobao.org/koa-is-json/download/koa-is-json-1.0.0.tgz#273c07edcdcb8df6a2c1ab7d59ee76491451ec14"

koa-router@^7.4.0:
version "7.4.0"
resolved "https://registry.npm.taobao.org/koa-router/download/koa-router-7.4.0.tgz#aee1f7adc02d5cb31d7d67465c9eacc825e8c5e0"
integrity sha1-ruH3rcAtXLMdfWdGXJ6syCXoxeA=
dependencies:
debug "^3.1.0"
http-errors "^1.3.1"
koa-compose "^3.0.0"
methods "^1.0.1"
path-to-regexp "^1.1.1"
urijs "^1.19.0"

koa-send@^4.1.3:
version "4.1.3"
resolved "https://registry.npm.taobao.org/koa-send/download/koa-send-4.1.3.tgz#0822207bbf5253a414c8f1765ebc29fa41353cb6"
Expand Down Expand Up @@ -5628,7 +5652,7 @@ merge-stream@^2.0.0:
version "2.0.0"
resolved "https://registry.npm.taobao.org/merge-stream/download/merge-stream-2.0.0.tgz#52823629a14dd00c9770fb6ad47dc6310f2c1f60"

methods@~1.1.2:
methods@^1.0.1, methods@~1.1.2:
version "1.1.2"
resolved "https://registry.npm.taobao.org/methods/download/methods-1.1.2.tgz#5529a4d67654134edcc5266656835b0f851afcee"

Expand Down Expand Up @@ -6522,6 +6546,13 @@ path-to-regexp@0.1.7:
version "0.1.7"
resolved "https://registry.npm.taobao.org/path-to-regexp/download/path-to-regexp-0.1.7.tgz#df604178005f522f15eb4490e7247a1bfaa67f8c"

path-to-regexp@^1.1.1:
version "1.7.0"
resolved "https://registry.npm.taobao.org/path-to-regexp/download/path-to-regexp-1.7.0.tgz#59fde0f435badacba103a84e9d3bc64e96b9937d"
integrity sha1-Wf3g9DW62suhA6hOnTvGTpa5k30=
dependencies:
isarray "0.0.1"

path-type@^2.0.0:
version "2.0.0"
resolved "https://registry.npm.taobao.org/path-type/download/path-type-2.0.0.tgz#f012ccb8415b7096fc2daa1054c3d72389594c73"
Expand Down Expand Up @@ -8884,6 +8915,11 @@ uri-js@^4.2.2:
dependencies:
punycode "^2.1.0"

urijs@^1.19.0:
version "1.19.1"
resolved "https://registry.npm.taobao.org/urijs/download/urijs-1.19.1.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Furijs%2Fdownload%2Furijs-1.19.1.tgz#5b0ff530c0cbde8386f6342235ba5ca6e995d25a"
integrity sha1-Ww/1MMDL3oOG9jQiNbpcpumV0lo=

urix@^0.1.0:
version "0.1.0"
resolved "https://registry.npm.taobao.org/urix/download/urix-0.1.0.tgz#da937f7a62e21fec1fd18d49b35c2935067a6c72"
Expand Down

0 comments on commit 6b1b578

Please sign in to comment.