|
@@ -1,5 +1,5 @@
|
1
|
1
|
import * as constant from './constant';
|
2
|
|
-import { readyStateCallback, callback } from './callback';
|
|
2
|
+import { ReadyStateCallback, RequestCallback } from './callback';
|
3
|
3
|
import { Packet } from './packet';
|
4
|
4
|
import { Utils } from './utils';
|
5
|
5
|
|
|
@@ -7,7 +7,7 @@ import { Utils } from './utils';
|
7
|
7
|
* Client ws client, 单例模式, 负责维护连接
|
8
|
8
|
*/
|
9
|
9
|
export class Client {
|
10
|
|
- private requestCallback: callback;
|
|
10
|
+ private requestCallback: RequestCallback;
|
11
|
11
|
private requestHeader: string;
|
12
|
12
|
private responseHeader: string;
|
13
|
13
|
private maxPayload: number;
|
|
@@ -15,9 +15,9 @@ export class Client {
|
15
|
15
|
private reconnectTimes: number;
|
16
|
16
|
private reconnectLock: boolean;
|
17
|
17
|
private socket: WebSocket;
|
18
|
|
- private readyStateCallback: readyStateCallback;
|
|
18
|
+ private readyStateCallback: ReadyStateCallback;
|
19
|
19
|
|
20
|
|
- constructor(url: string, readyStateCallback: readyStateCallback) {
|
|
20
|
+ constructor(url: string, readyStateCallback: ReadyStateCallback) {
|
21
|
21
|
this.maxPayload = constant.MAX_PAYLOAD;
|
22
|
22
|
this.url = url;
|
23
|
23
|
this.readyStateCallback = readyStateCallback;
|
|
@@ -207,7 +207,6 @@ export class Client {
|
207
|
207
|
ws.binaryType = 'blob';
|
208
|
208
|
|
209
|
209
|
ws.onopen = function(ev) {
|
210
|
|
- console.info('websocket connected');
|
211
|
210
|
_this.reconnectTimes = 0;
|
212
|
211
|
if (
|
213
|
212
|
readyStateCallback.hasOwnProperty('onOpen') &&
|
|
@@ -218,7 +217,6 @@ export class Client {
|
218
|
217
|
};
|
219
|
218
|
|
220
|
219
|
ws.onclose = function(ev) {
|
221
|
|
- console.info('websocket disconnected');
|
222
|
220
|
_this.reconnect();
|
223
|
221
|
if (
|
224
|
222
|
readyStateCallback.hasOwnProperty('onClose') &&
|
|
@@ -229,7 +227,6 @@ export class Client {
|
229
|
227
|
};
|
230
|
228
|
|
231
|
229
|
ws.onerror = function(ev) {
|
232
|
|
- console.info('websocket error disconnected');
|
233
|
230
|
_this.reconnect();
|
234
|
231
|
if (
|
235
|
232
|
readyStateCallback.hasOwnProperty('onError') &&
|