|
@@ -20,15 +20,17 @@ class Client {
|
20
|
20
|
|
21
|
21
|
constructor(url: string, readyStateCallback: ReadyStateCallback) {
|
22
|
22
|
this.listeners = new Map<number, (data: string) => void>();
|
|
23
|
+ this.requestHeader = '';
|
|
24
|
+ this.requestHeader = '';
|
23
|
25
|
this.maxPayload = MAX_PAYLOAD;
|
24
|
26
|
this.url = url;
|
|
27
|
+ this.reconnectTimes = 0;
|
25
|
28
|
this.readyStateCallback = readyStateCallback;
|
26
|
|
-
|
27
|
29
|
this.socket = this.connect();
|
28
|
30
|
}
|
29
|
31
|
|
30
|
32
|
// 向服务端发送ping包保持长连接
|
31
|
|
- ping(param = {}, requestCallback: RequestCallback) {
|
|
33
|
+ ping(param: any, requestCallback: RequestCallback) {
|
32
|
34
|
if (this.socket.readyState !== this.socket.OPEN) {
|
33
|
35
|
throw new Error('asyncSend: connection refuse');
|
34
|
36
|
}
|
|
@@ -52,7 +54,7 @@ class Client {
|
52
|
54
|
this.send(p.pack(0, 0, this.requestHeader, JSON.stringify(param)));
|
53
|
55
|
}
|
54
|
56
|
|
55
|
|
- send(data) {
|
|
57
|
+ send(data: ArrayBuffer) {
|
56
|
58
|
if (this.socket.readyState !== this.socket.OPEN) {
|
57
|
59
|
console.error('WebSocket is already in CLOSING or CLOSED state.');
|
58
|
60
|
return;
|