wxyyxc1992 5 years ago
parent
commit
86ffc04518

+ 30
- 7
packages/cts-api/dist/cjs/WebSocketClient.js View File

@@ -97,6 +97,7 @@ var WebSocketClient = (function () {
97 97
                                             }
98 98
                                             catch (err) {
99 99
                                                 console.error(err);
100
+                                                reject(err);
100 101
                                             }
101 102
                                             return [4, this.connect()];
102 103
                                         case 1:
@@ -166,23 +167,45 @@ var WebSocketClient = (function () {
166 167
         return __awaiter(this, void 0, void 0, function () {
167 168
             var tk, data;
168 169
             return __generator(this, function (_a) {
169
-                tk = this.token;
170
-                data = this.request('/v1/session/bind/uid/by/token', { token: tk });
171
-                return [2, data || true];
170
+                switch (_a.label) {
171
+                    case 0:
172
+                        tk = this.token;
173
+                        return [4, this.request('/v1/session/bind/uid/by/token', { token: tk })];
174
+                    case 1:
175
+                        data = _a.sent();
176
+                        return [2, data || true];
177
+                }
172 178
             });
173 179
         });
174 180
     };
175 181
     WebSocketClient.prototype.onMessage = function (callback) {
176
-        this.on('/v1/message/listener', callback);
182
+        return __awaiter(this, void 0, void 0, function () {
183
+            return __generator(this, function (_a) {
184
+                this.on('/v1/message/listener', callback);
185
+                return [2];
186
+            });
187
+        });
177 188
     };
178 189
     WebSocketClient.prototype.sendMessage = function (data) {
179
-        return this.request('/v1/send/message', data);
190
+        return __awaiter(this, void 0, void 0, function () {
191
+            return __generator(this, function (_a) {
192
+                return [2, this.request('/v1/send/message', data)];
193
+            });
194
+        });
180 195
     };
181 196
     WebSocketClient.prototype.markServiced = function (data) {
182
-        return this.request('/v1/mark/message/serviced', data);
197
+        return __awaiter(this, void 0, void 0, function () {
198
+            return __generator(this, function (_a) {
199
+                return [2, this.request('/v1/mark/message/serviced', data)];
200
+            });
201
+        });
183 202
     };
184 203
     WebSocketClient.prototype.getHistoryMessage = function (data) {
185
-        return this.request('/v1/history/message', data);
204
+        return __awaiter(this, void 0, void 0, function () {
205
+            return __generator(this, function (_a) {
206
+                return [2, this.request('/v1/history/message', data)];
207
+            });
208
+        });
186 209
     };
187 210
     return WebSocketClient;
188 211
 }());

+ 1
- 1
packages/cts-api/dist/index.js
File diff suppressed because it is too large
View File


+ 1
- 1
packages/cts-api/dist/types/WebSocketClient.d.ts View File

@@ -26,7 +26,7 @@ export declare class WebSocketClient {
26 26
     connect(): Promise<import("ts-linker-sdk/dist/types/types").WebSocketResp>;
27 27
     ping(): Promise<import("ts-linker-sdk/dist/types/types").WebSocketResp>;
28 28
     authentication(): Promise<import("ts-linker-sdk/dist/types/types").WebSocketResp>;
29
-    onMessage(callback: ListenerCallback): void;
29
+    onMessage(callback: ListenerCallback): Promise<void>;
30 30
     sendMessage(data: object): Promise<import("ts-linker-sdk/dist/types/types").WebSocketResp>;
31 31
     markServiced(data: object): Promise<import("ts-linker-sdk/dist/types/types").WebSocketResp>;
32 32
     getHistoryMessage(data: object): Promise<import("ts-linker-sdk/dist/types/types").WebSocketResp>;

+ 6
- 5
packages/cts-api/src/WebSocketClient.ts View File

@@ -63,6 +63,7 @@ export class WebSocketClient {
63 63
             }, PING_INTERVAL) as any;
64 64
           } catch (err) {
65 65
             console.error(err);
66
+            reject(err);
66 67
           }
67 68
 
68 69
           const data = await this.connect();
@@ -120,19 +121,19 @@ export class WebSocketClient {
120 121
 
121 122
   async authentication() {
122 123
     const tk = this.token;
123
-    const data = this.request('/v1/session/bind/uid/by/token', { token: tk });
124
+    const data = await this.request('/v1/session/bind/uid/by/token', { token: tk });
124 125
     return data || true;
125 126
   }
126 127
 
127
-  onMessage(callback: ListenerCallback) {
128
+  async onMessage(callback: ListenerCallback) {
128 129
     this.on('/v1/message/listener', callback);
129 130
   }
130 131
 
131
-  sendMessage(data: object) {
132
+  async sendMessage(data: object) {
132 133
     return this.request('/v1/send/message', data);
133 134
   }
134 135
 
135
-  markServiced(data: object) {
136
+  async markServiced(data: object) {
136 137
     return this.request('/v1/mark/message/serviced', data);
137 138
   }
138 139
 
@@ -140,7 +141,7 @@ export class WebSocketClient {
140 141
    *
141 142
    * @param {*} data contact_id chat_type start_time limit
142 143
    */
143
-  getHistoryMessage(data: object) {
144
+  async getHistoryMessage(data: object) {
144 145
     return this.request('/v1/history/message', data);
145 146
   }
146 147
 }