Passed
Push — master ( cd1d60...fb47b8 )
by Michael
02:11 queued 10s
created

WebSocketClient.open   A

Complexity

Conditions 1

Size

Total Lines 1
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 1
rs 10
c 0
b 0
f 0
cc 1
1
// Generated by dts-bundle-generator v9.5.1
2
3
declare namespace wsc {
4
	interface DataObject {
5
		[key: string]: any;
6
	}
7
	type WSEvent = "open" | "message" | "close" | "error" | "timeout";
8
	/** Minimal socket-like interface. */
9
	interface Socket {
10
		readyState: number;
11
		send(...any: any[]): void;
12
		close(): void;
13
		addEventListener: WebSocket["addEventListener"];
14
		removeEventListener: WebSocket["removeEventListener"];
15
	}
16
	type AsyncErrCode = Promise<number | null | {}>;
17
	type EventHandler = (e: any) => void;
18
	type DataPipe = (message: any) => any;
19
	type DataType = "json" | "string";
20
	interface Config {
21
		data_type: DataType;
22
		log(event: string, time?: number | null, message?: any): void;
23
		log(event: string, message?: any): void;
24
		timer: boolean;
25
		url: string;
26
		timeout: number;
27
		reconnect: number;
28
		reconnection_attempts: number;
29
		max_idle_time: number;
30
		lazy: boolean;
31
		socket: Socket | null;
32
		adapter: (host: string, protocols?: string[]) => Socket;
33
		encode: (key: string, message: any, config: Config) => any;
34
		decode: (rawMessage: any) => {
35
			[id_or_data_key: string]: string;
36
		};
37
		protocols: string[];
38
		pipes: DataPipe[];
39
		server: {
40
			id_key: string;
41
			data_key: string;
42
		};
43
		ping: {
44
			interval: number;
45
			content: any;
46
		};
47
	}
48
	type UserConfig = Partial<Config>;
49
	interface SendOptions {
50
		top: any;
51
		data_type: DataType;
52
	}
53
	interface Message {
54
		msg: any;
55
		ff(x: any): any;
56
		data_type: DataType;
57
		sent_time: number | null;
58
		timeout: NodeJS.Timeout;
59
	}
60
}
61
declare class WebSocketClient {
62
	private ws;
63
	private intentionally_closed;
64
	private reconnect_timeout;
65
	private queue;
66
	private onReadyQueue;
67
	private onCloseQueue;
68
	private handlers;
69
	private config;
70
	private ping_timer;
71
	private idle_timer;
72
	private get opened();
73
	private init_flush;
74
	private call;
75
	private log;
76
	private resetPing;
77
	private resetIdle;
78
	private initSocket;
79
	private opening;
80
	private connect;
81
	get socket(): wsc.Socket | null;
82
	ready(): Promise<void>;
83
	on(event_name: wsc.WSEvent, handler: (data: any) => any, predicate?: (data: any) => boolean, raw?: boolean): wsc.EventHandler;
84
	off(event_name: wsc.WSEvent, handler: (data: any) => any, raw?: boolean): void;
85
	close(): wsc.AsyncErrCode;
86
	open(): Promise<number | null> | undefined;
87
	/**  .send(your_data) wraps request to server with {id: `hash`, data: `actually your data`},
88
	  returns a Promise that will be rejected after a timeout or
89
	  resolved if server returns the same signature: {id: `same_hash`, data: `response data`}.
90
	*/
91
	send<RequestDataType = any, ResponseDataType = any>(message_data: RequestDataType, opts?: wsc.SendOptions): Promise<ResponseDataType>;
92
	constructor(user_config?: wsc.UserConfig);
93
}
94
95
export {
96
	WebSocketClient as default,
97
};
98
99
export {};
100