Browse Source

more type

Paul 5 years ago
parent
commit
1e5be84b75
2 changed files with 7 additions and 5 deletions
  1. 2
    2
      src/example/main.ts
  2. 5
    3
      src/index.ts

+ 2
- 2
src/example/main.ts View File

@@ -6,7 +6,7 @@ const client = new Client(
6 6
   new (class {
7 7
     onOpen(ev: Event) {
8 8
       client.ping(
9
-        undefined,
9
+        {},
10 10
         new (class {
11 11
           onStart(): void {
12 12
             console.log('start ping');
@@ -28,7 +28,7 @@ const client = new Client(
28 28
 
29 29
       client.syncSend(
30 30
         '/v1/healthy',
31
-        undefined,
31
+        {},
32 32
         new (class {
33 33
           onStart(): void {
34 34
             console.log('start request');

+ 5
- 3
src/index.ts View File

@@ -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;