fishpi 0.0.57 → 0.0.58
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/chatroom.js +102 -94
- package/package.json +1 -1
package/lib/chatroom.js
CHANGED
|
@@ -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 ? "
|
|
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
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
493
|
+
switch (_g.label) {
|
|
494
|
+
case 0:
|
|
495
|
+
if (!!url) return [3 /*break*/, 2];
|
|
496
|
+
return [4 /*yield*/, this.getNode()];
|
|
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, "?apiKey=").concat(this._apiKey), []];
|
|
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
|
-
|
|
576
|
-
|
|
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
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
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
|
};
|