Skip to content

Commit

Permalink
add types for SocketIO
Browse files Browse the repository at this point in the history
  • Loading branch information
Atrue committed Jan 25, 2022
1 parent 36f4234 commit 73f1b30
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,44 @@ declare module 'mock-socket' {
in(any: any): ToReturnObject;
simulate(event: string): void;

public of(url: string): Server;
static of(url: string): Server;
}

interface SocketIOClient extends EventTarget {
binaryType: BinaryType;

readonly CONNECTING: 0;
readonly OPEN: 1;
readonly CLOSING: 2;
readonly CLOSED: 3;

readonly url: string;
readonly readyState: number;
readonly protocol: string;
readonly target: this;

close(): this;
disconnect(): this;
emit(event: string, data: any): this;
send(data: any): this;
on(type: string, callback: (socket: SocketIOClient) => void): this;
off(type: string, callback: (socket: SocketIOClient) => void): void;
hasListeners(type: string): boolean;
join(room: string): void;
leave(room: string): void;
to(room: string): ToReturnObject;
in(room: string): ToReturnObject;

readonly broadcast: {
emit(event: string, data: any): SocketIOClient;
to(room: string): ToReturnObject;
in(room: string): ToReturnObject;
};
}

const SocketIO: {
(url: string, protocol: string | string[]): SocketIOClient;
connect(url: string, protocol: string | string[]): SocketIOClient;
}

interface CloseOptions {
Expand Down

0 comments on commit 73f1b30

Please sign in to comment.