fishpi 0.0.51 → 0.0.52

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/chat.d.ts CHANGED
@@ -4,6 +4,7 @@ declare class Chat {
4
4
  private _apiKey;
5
5
  private _rwss;
6
6
  private _wsCallbacks;
7
+ private timer;
7
8
  constructor(token?: string);
8
9
  /**
9
10
  * 重新设置请求 Token
@@ -59,15 +60,18 @@ declare class Chat {
59
60
  */
60
61
  addListener(wsCallback: ({ msg }: {
61
62
  msg: NoticeMsg | ChatRevoke | ChatData;
62
- }) => void, user?: string): Promise<void>;
63
+ }) => void, user?: string, onclose?: (e: any) => void): Promise<void>;
64
+ /**
65
+ * 重新连接用户私聊频道
66
+ * @param user 私聊用户名
67
+ */
68
+ reconnect(user?: string, onclose?: (e: any) => void): void;
63
69
  /**
64
70
  * 连接用户私聊频道
65
71
  * @param user 私聊用户名
66
72
  * @returns Websocket 连接对象
67
73
  */
68
- connect(user: string, { onclose }?: {
69
- onclose?: (e: any) => void;
70
- }): Promise<ReconnectingWebSocket>;
74
+ private connect;
71
75
  /**
72
76
  *
73
77
  * @param user 私聊用户名
package/lib/chat.js CHANGED
@@ -70,6 +70,7 @@ var Chat = /** @class */ (function () {
70
70
  this._apiKey = '';
71
71
  this._rwss = {};
72
72
  this._wsCallbacks = {};
73
+ this.timer = null;
73
74
  if (!token) {
74
75
  return;
75
76
  }
@@ -220,7 +221,7 @@ var Chat = /** @class */ (function () {
220
221
  * @param wsCallback 消息监听函数
221
222
  * @param user 指定为用户消息监听函数,空为新信息监听
222
223
  */
223
- Chat.prototype.addListener = function (wsCallback, user) {
224
+ Chat.prototype.addListener = function (wsCallback, user, onclose) {
224
225
  if (user === void 0) { user = ''; }
225
226
  return __awaiter(this, void 0, void 0, function () {
226
227
  return __generator(this, function (_a) {
@@ -231,11 +232,22 @@ var Chat = /** @class */ (function () {
231
232
  }
232
233
  this._wsCallbacks[user] = this._wsCallbacks[user] || [];
233
234
  this._wsCallbacks[user].push(wsCallback);
234
- this.connect(user);
235
+ this.connect(user, { onclose: onclose });
235
236
  return [2 /*return*/];
236
237
  });
237
238
  });
238
239
  };
240
+ /**
241
+ * 重新连接用户私聊频道
242
+ * @param user 私聊用户名
243
+ */
244
+ Chat.prototype.reconnect = function (user, onclose) {
245
+ if (user === void 0) { user = ''; }
246
+ if (this._rwss[user])
247
+ this._rwss[user].reconnect();
248
+ else
249
+ this.connect(user, { onclose: onclose });
250
+ };
239
251
  /**
240
252
  * 连接用户私聊频道
241
253
  * @param user 私聊用户名
@@ -274,6 +286,13 @@ var Chat = /** @class */ (function () {
274
286
  _f.connectionTimeout = 10000,
275
287
  _f)])))();
276
288
  this._rwss[user].onopen = function (e) {
289
+ if (user === '') {
290
+ if (_this.timer)
291
+ clearInterval(_this.timer);
292
+ _this.timer = setInterval(function () {
293
+ _this._rwss[user].send('-hd-');
294
+ }, 30000);
295
+ }
277
296
  resolve(_this._rwss[user]);
278
297
  };
279
298
  this._rwss[user].onmessage = function (e) { return __awaiter(_this, void 0, void 0, function () {
@@ -290,6 +309,11 @@ var Chat = /** @class */ (function () {
290
309
  };
291
310
  this._rwss[user].onclose = onclose !== null && onclose !== void 0 ? onclose : (function (e) {
292
311
  console.log("[Chat] ".concat(user, " \u8FDE\u63A5\u5DF2\u5173\u95ED"), e);
312
+ if (user === '') {
313
+ if (_this.timer)
314
+ clearInterval(_this.timer);
315
+ _this.timer = null;
316
+ }
293
317
  });
294
318
  return [2 /*return*/];
295
319
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fishpi",
3
- "version": "0.0.51",
3
+ "version": "0.0.52",
4
4
  "description": "A Package to use API of fishpi.",
5
5
  "main": "./lib/index.js",
6
6
  "files": [