From 73f1b3083c0e868e08b3d1ac5aa139b026b7f899 Mon Sep 17 00:00:00 2001 From: Atrue Date: Tue, 25 Jan 2022 16:39:25 +0300 Subject: [PATCH] add types for SocketIO --- index.d.ts | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 5be78cab..9c25e34f 100644 --- a/index.d.ts +++ b/index.d.ts @@ -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 {