/
socketClient.d.ts
137 lines (137 loc) · 3.06 KB
/
socketClient.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
export default SocketClient;
declare class SocketClient {
/**
* Create a WebSocket instance
* @param url {string} WebSocket url
*/
constructor(url: string);
/**
* WebSocket instance
* @type {WebSocket|null}
*/
ws: WebSocket | null;
events: {
open: Set<any>;
message: Set<any>;
error: Set<any>;
close: Set<any>;
};
debug: boolean;
lastReConnTime: number;
interval: number;
url: string;
useReConn: boolean;
/**
* Check the connection status of the WebSocket instance
* @private
*/
private checkConn;
/**
* Get the Origin WebSocket instance
* @return {WebSocket|null}
*/
getOriginInstance(): WebSocket | null;
/**
* Set whether to print the log
* @param debug {boolean}
*/
setDebug(debug: boolean): void;
/**
* Disable disconnecting retry links
* @param disable {boolean}
*/
disableReConnect(disable?: boolean): void;
/**
* set reConnect setInterval (default:1000 ms)
* @param interval {number} ms
*/
setReConnectInterval(interval: number): void;
/**
* data a text string, ArrayBuffer or Blob
* @param data {string|any}
*/
send(data: string | any): void;
/**
* Actively disconnect
*/
close(): void;
/**
* Actively disconnect
*/
disconnect(): void;
/**
* Check if the link is closed
* @return {boolean}
*/
isClose(): boolean;
/**
* Check if the link is connecting
* @return {boolean}
*/
isConnecting(): boolean;
/**
* Check if the link is open
* @return {boolean}
*/
isOpen(): boolean;
/**
* Check if the link is closing
* @return {boolean}
*/
isClosing(): boolean;
/**
* Listen to the link success event, with superimposed features
* @param func {Function}
*/
onOpen(func: Function): void;
/**
* Listen to the link success event, with superimposed features
* @param event {string}
* @private
*/
private _emitOpen;
/**
*
* @param event
* @private
*/
private _emitMessage;
/**
* Listen to message acquisition events, with superimposed features
* @param func {Function}
*/
onMessage(func: Function): void;
/**
* Monitor abnormal events, with superimposed features
* @param func {Function}
*/
onError(func: Function): void;
_emitError(event: any): void;
/**
* Listen for link closing events, with superimposed features
* @param func {Function}
*/
onClose(func: Function): void;
/**
*
* @param event
* @private
*/
private _emitClose;
/**
* Clear all listener link close events
*/
offCloseEvent(): void;
/**
* Clear all exception event listeners
*/
offErrorEvent(): void;
/**
* Clear all listener messages to get events
*/
offMessageEvent(): void;
/**
* Clear all listener link success events
*/
offOpenEvent(): void;
}