wxyyxc1992 5 years ago
parent
commit
86ffc04518

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

97
                                             }
97
                                             }
98
                                             catch (err) {
98
                                             catch (err) {
99
                                                 console.error(err);
99
                                                 console.error(err);
100
+                                                reject(err);
100
                                             }
101
                                             }
101
                                             return [4, this.connect()];
102
                                             return [4, this.connect()];
102
                                         case 1:
103
                                         case 1:
166
         return __awaiter(this, void 0, void 0, function () {
167
         return __awaiter(this, void 0, void 0, function () {
167
             var tk, data;
168
             var tk, data;
168
             return __generator(this, function (_a) {
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
     WebSocketClient.prototype.onMessage = function (callback) {
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
     WebSocketClient.prototype.sendMessage = function (data) {
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
     WebSocketClient.prototype.markServiced = function (data) {
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
     WebSocketClient.prototype.getHistoryMessage = function (data) {
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
     return WebSocketClient;
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
     connect(): Promise<import("ts-linker-sdk/dist/types/types").WebSocketResp>;
26
     connect(): Promise<import("ts-linker-sdk/dist/types/types").WebSocketResp>;
27
     ping(): Promise<import("ts-linker-sdk/dist/types/types").WebSocketResp>;
27
     ping(): Promise<import("ts-linker-sdk/dist/types/types").WebSocketResp>;
28
     authentication(): Promise<import("ts-linker-sdk/dist/types/types").WebSocketResp>;
28
     authentication(): Promise<import("ts-linker-sdk/dist/types/types").WebSocketResp>;
29
-    onMessage(callback: ListenerCallback): void;
29
+    onMessage(callback: ListenerCallback): Promise<void>;
30
     sendMessage(data: object): Promise<import("ts-linker-sdk/dist/types/types").WebSocketResp>;
30
     sendMessage(data: object): Promise<import("ts-linker-sdk/dist/types/types").WebSocketResp>;
31
     markServiced(data: object): Promise<import("ts-linker-sdk/dist/types/types").WebSocketResp>;
31
     markServiced(data: object): Promise<import("ts-linker-sdk/dist/types/types").WebSocketResp>;
32
     getHistoryMessage(data: object): Promise<import("ts-linker-sdk/dist/types/types").WebSocketResp>;
32
     getHistoryMessage(data: object): Promise<import("ts-linker-sdk/dist/types/types").WebSocketResp>;

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

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