fishpi 0.0.57 → 0.0.59

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.
Files changed (2) hide show
  1. package/lib/chatroom.js +103 -95
  2. package/package.json +1 -1
package/lib/chatroom.js CHANGED
@@ -464,7 +464,7 @@ var ChatRoom = /** @class */ (function () {
464
464
  case 0:
465
465
  _a.trys.push([0, 2, , 3]);
466
466
  return [4 /*yield*/, (0, utils_1.request)({
467
- url: "chat-room/node/get",
467
+ url: "chat-room/node/get?apiKey=".concat(this._apiKey),
468
468
  method: 'get',
469
469
  })];
470
470
  case 1:
@@ -486,106 +486,114 @@ var ChatRoom = /** @class */ (function () {
486
486
  * @returns 返回 Open Event
487
487
  */
488
488
  ChatRoom.prototype.reconnect = function (_a) {
489
- var _b = _a === void 0 ? {} : _a, _c = _b.url, url = _c === void 0 ? "wss://".concat(utils_1.domain, "/chat-room-channel") : _c, _d = _b.timeout, timeout = _d === void 0 ? 10 : _d, _e = _b.error, error = _e === void 0 ? function (ev) { } : _e, _f = _b.close, close = _f === void 0 ? function (ev) { } : _f;
489
+ var _b = _a === void 0 ? {} : _a, _c = _b.url, url = _c === void 0 ? "" : _c, _d = _b.timeout, timeout = _d === void 0 ? 10 : _d, _e = _b.error, error = _e === void 0 ? function (ev) { } : _e, _f = _b.close, close = _f === void 0 ? function (ev) { } : _f;
490
490
  return __awaiter(this, void 0, void 0, function () {
491
491
  var _this = this;
492
492
  return __generator(this, function (_g) {
493
- return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
494
- var _a, _b, _c, _d;
495
- var _e;
496
- var _this = this;
497
- return __generator(this, function (_f) {
498
- switch (_f.label) {
499
- case 0:
500
- if (this._rws)
501
- return [2 /*return*/, resolve(this._rws.reconnect())];
502
- _a = this;
503
- _b = reconnecting_websocket_1.default.bind;
504
- _c = [void 0, "".concat(url, "?apiKey=").concat(this._apiKey), []];
505
- _e = {};
506
- if (!utils_1.isBrowse) return [3 /*break*/, 1];
507
- _d = window.WebSocket;
508
- return [3 /*break*/, 3];
509
- case 1: return [4 /*yield*/, Promise.resolve().then(function () { return __importStar(require('ws')); })];
510
- case 2:
511
- _d = (_f.sent()).WebSocket;
512
- _f.label = 3;
513
- case 3:
514
- _a._rws = new (_b.apply(reconnecting_websocket_1.default, _c.concat([(
515
- // eslint-disable-next-line @typescript-eslint/naming-convention
516
- _e.WebSocket = _d,
517
- _e.connectionTimeout = 1000 * timeout,
518
- _e)])))();
519
- this._rws.onopen = function (e) {
520
- if (_this._wsTimer) {
521
- clearInterval(_this._wsTimer);
522
- }
523
- _this._wsTimer = setInterval(function () {
524
- var _a;
525
- (_a = _this._rws) === null || _a === void 0 ? void 0 : _a.send('-hb-');
526
- }, 1000 * 60 * 3);
527
- resolve(e);
528
- };
529
- this._rws.onmessage = function (e) { return __awaiter(_this, void 0, void 0, function () {
530
- var msg, data, barragerContent, userAvatarURL, userAvatarURL20, userNickname, barragerColor, userName, userAvatarURL210, userAvatarURL48, userOId, oId, time, userName, userNickname, userAvatarURL, content, md, client, data_1, oId, count, got, whoGive, whoGot;
531
- return __generator(this, function (_a) {
532
- msg = JSON.parse(e.data);
533
- data = null;
534
- switch (msg.type) {
535
- case 'online': {
536
- this._onlines = msg.users;
537
- this._discusse = msg.discussing;
538
- data = this._onlines;
539
- break;
540
- }
541
- case 'discussChanged': {
542
- data = msg.newDiscuss;
543
- break;
544
- }
545
- case 'revoke': {
546
- data = msg.oId;
547
- break;
548
- }
549
- case 'barrager': {
550
- barragerContent = msg.barragerContent, userAvatarURL = msg.userAvatarURL, userAvatarURL20 = msg.userAvatarURL20, userNickname = msg.userNickname, barragerColor = msg.barragerColor, userName = msg.userName, userAvatarURL210 = msg.userAvatarURL210, userAvatarURL48 = msg.userAvatarURL48;
551
- data = { barragerContent: barragerContent, userAvatarURL: userAvatarURL, userAvatarURL20: userAvatarURL20, userNickname: userNickname, barragerColor: barragerColor, userName: userName, userAvatarURL210: userAvatarURL210, userAvatarURL48: userAvatarURL48 };
552
- break;
553
- }
554
- case 'msg': {
555
- userOId = msg.userOId, oId = msg.oId, time = msg.time, userName = msg.userName, userNickname = msg.userNickname, userAvatarURL = msg.userAvatarURL, content = msg.content, md = msg.md, client = msg.client;
556
- try {
557
- data_1 = JSON.parse(content);
558
- content = data_1;
559
- msg.type = data_1.msgType;
493
+ switch (_g.label) {
494
+ case 0:
495
+ if (!!url) return [3 /*break*/, 2];
496
+ return [4 /*yield*/, this.getNode().catch(function () { return "wss://".concat(utils_1.domain, "/chat-room-channel?apiKey=").concat(_this._apiKey); })];
497
+ case 1:
498
+ url = _g.sent();
499
+ _g.label = 2;
500
+ case 2: return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
501
+ var _a, _b, _c, _d;
502
+ var _e;
503
+ var _this = this;
504
+ return __generator(this, function (_f) {
505
+ switch (_f.label) {
506
+ case 0:
507
+ if (this._rws)
508
+ return [2 /*return*/, resolve(this._rws.reconnect())];
509
+ _a = this;
510
+ _b = reconnecting_websocket_1.default.bind;
511
+ _c = [void 0, "".concat(url), []];
512
+ _e = {};
513
+ if (!utils_1.isBrowse) return [3 /*break*/, 1];
514
+ _d = window.WebSocket;
515
+ return [3 /*break*/, 3];
516
+ case 1: return [4 /*yield*/, Promise.resolve().then(function () { return __importStar(require('ws')); })];
517
+ case 2:
518
+ _d = (_f.sent()).WebSocket;
519
+ _f.label = 3;
520
+ case 3:
521
+ _a._rws = new (_b.apply(reconnecting_websocket_1.default, _c.concat([(
522
+ // eslint-disable-next-line @typescript-eslint/naming-convention
523
+ _e.WebSocket = _d,
524
+ _e.connectionTimeout = 1000 * timeout,
525
+ _e)])))();
526
+ this._rws.onopen = function (e) {
527
+ if (_this._wsTimer) {
528
+ clearInterval(_this._wsTimer);
529
+ }
530
+ _this._wsTimer = setInterval(function () {
531
+ var _a;
532
+ (_a = _this._rws) === null || _a === void 0 ? void 0 : _a.send('-hb-');
533
+ }, 1000 * 60 * 3);
534
+ resolve(e);
535
+ };
536
+ this._rws.onmessage = function (e) { return __awaiter(_this, void 0, void 0, function () {
537
+ var msg, data, barragerContent, userAvatarURL, userAvatarURL20, userNickname, barragerColor, userName, userAvatarURL210, userAvatarURL48, userOId, oId, time, userName, userNickname, userAvatarURL, content, md, client, data_1, oId, count, got, whoGive, whoGot;
538
+ return __generator(this, function (_a) {
539
+ msg = JSON.parse(e.data);
540
+ data = null;
541
+ switch (msg.type) {
542
+ case 'online': {
543
+ this._onlines = msg.users;
544
+ this._discusse = msg.discussing;
545
+ data = this._onlines;
546
+ break;
547
+ }
548
+ case 'discussChanged': {
549
+ data = msg.newDiscuss;
550
+ break;
551
+ }
552
+ case 'revoke': {
553
+ data = msg.oId;
554
+ break;
555
+ }
556
+ case 'barrager': {
557
+ barragerContent = msg.barragerContent, userAvatarURL = msg.userAvatarURL, userAvatarURL20 = msg.userAvatarURL20, userNickname = msg.userNickname, barragerColor = msg.barragerColor, userName = msg.userName, userAvatarURL210 = msg.userAvatarURL210, userAvatarURL48 = msg.userAvatarURL48;
558
+ data = { barragerContent: barragerContent, userAvatarURL: userAvatarURL, userAvatarURL20: userAvatarURL20, userNickname: userNickname, barragerColor: barragerColor, userName: userName, userAvatarURL210: userAvatarURL210, userAvatarURL48: userAvatarURL48 };
559
+ break;
560
+ }
561
+ case 'msg': {
562
+ userOId = msg.userOId, oId = msg.oId, time = msg.time, userName = msg.userName, userNickname = msg.userNickname, userAvatarURL = msg.userAvatarURL, content = msg.content, md = msg.md, client = msg.client;
563
+ try {
564
+ data_1 = JSON.parse(content);
565
+ content = data_1;
566
+ msg.type = data_1.msgType;
567
+ }
568
+ catch (e) { }
569
+ data = { userOId: userOId, oId: oId, time: time, userName: userName, userNickname: userNickname, userAvatarURL: userAvatarURL, content: content, md: md, client: client, via: (0, utils_1.clientToVia)(client) };
570
+ break;
571
+ }
572
+ case 'redPacketStatus': {
573
+ oId = msg.oId, count = msg.count, got = msg.got, whoGive = msg.whoGive, whoGot = msg.whoGot;
574
+ data = { oId: oId, count: count, got: got, whoGive: whoGive, whoGot: whoGot };
575
+ break;
576
+ }
577
+ case 'customMessage': {
578
+ data = msg.message;
579
+ break;
560
580
  }
561
- catch (e) { }
562
- data = { userOId: userOId, oId: oId, time: time, userName: userName, userNickname: userNickname, userAvatarURL: userAvatarURL, content: content, md: md, client: client, via: (0, utils_1.clientToVia)(client) };
563
- break;
564
- }
565
- case 'redPacketStatus': {
566
- oId = msg.oId, count = msg.count, got = msg.got, whoGive = msg.whoGive, whoGot = msg.whoGot;
567
- data = { oId: oId, count: count, got: got, whoGive: whoGive, whoGot: whoGot };
568
- break;
569
- }
570
- case 'customMessage': {
571
- data = msg.message;
572
- break;
573
581
  }
574
- }
575
- this._wsCallbacks.forEach(function (call) { return call(Object.assign(__assign(__assign({}, e), { msg: { type: msg.type, data: data } }))); });
576
- return [2 /*return*/];
582
+ this._wsCallbacks.forEach(function (call) { return call(Object.assign(__assign(__assign({}, e), { msg: { type: msg.type, data: data } }))); });
583
+ return [2 /*return*/];
584
+ });
585
+ }); };
586
+ this._rws.onerror = error || (function (e) {
587
+ console.error(e);
577
588
  });
578
- }); };
579
- this._rws.onerror = error || (function (e) {
580
- console.error(e);
581
- });
582
- this._rws.onclose = close || (function (e) {
583
- console.log(e);
584
- });
585
- return [2 /*return*/];
586
- }
587
- });
588
- }); })];
589
+ this._rws.onclose = close || (function (e) {
590
+ console.log(e);
591
+ });
592
+ return [2 /*return*/];
593
+ }
594
+ });
595
+ }); })];
596
+ }
589
597
  });
590
598
  });
591
599
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fishpi",
3
- "version": "0.0.57",
3
+ "version": "0.0.59",
4
4
  "description": "A Package to use API of fishpi.",
5
5
  "main": "./lib/index.js",
6
6
  "files": [