浏览代码

fix style

Paul 5 年前
父节点
当前提交
df9231f1f0
共有 3 个文件被更改,包括 23 次插入12 次删除
  1. 2
    2
      src/callback.ts
  2. 17
    3
      src/example/main.ts
  3. 4
    7
      src/index.ts

+ 2
- 2
src/callback.ts 查看文件

@@ -1,10 +1,10 @@
1
-export interface readyStateCallback {
1
+export interface ReadyStateCallback {
2 2
   onOpen(ev: Event);
3 3
   onError(ev: Event);
4 4
   onClose(ev: Event);
5 5
 }
6 6
 
7
-export interface callback {
7
+export interface RequestCallback {
8 8
   onStart();
9 9
   onSuccess(data: string);
10 10
   onError(code: number, message: string);

+ 17
- 3
src/example/main.ts 查看文件

@@ -1,5 +1,19 @@
1 1
 import { Client } from "../index";
2 2
 
3
-const client = new Client("ws://127.0.0.1:8081", null)
4
-console.log(client.setRequestProperty("name", "stri"))
5
-console.log(client.getRequestProperty("name"))
3
+const client = new Client("ws://127.0.0.1:8081", new class {
4
+  onOpen(ev:Event) {
5
+    console.log("open connection", ev.target)
6
+  }
7
+
8
+  onClose(ev:Event) {
9
+    console.log("connection error", ev)
10
+    console.log(ev)
11
+  }
12
+
13
+  onError(ev:Event){
14
+    console.log("close connection")
15
+  }
16
+})
17
+
18
+
19
+console.log(client)

+ 4
- 7
src/index.ts 查看文件

@@ -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') &&