Paul 6 vuotta sitten
vanhempi
commit
1e5be84b75
2 muutettua tiedostoa jossa 7 lisäystä ja 5 poistoa
  1. 2
    2
      src/example/main.ts
  2. 5
    3
      src/index.ts

+ 2
- 2
src/example/main.ts Näytä tiedosto

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

+ 5
- 3
src/index.ts Näytä tiedosto

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