fishpi 0.0.61 → 0.0.63
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.d.ts +4 -1
- package/lib/chatroom.js +103 -98
- package/package.json +1 -1
package/lib/chatroom.d.ts
CHANGED
|
@@ -99,6 +99,7 @@ declare class ChatRoom {
|
|
|
99
99
|
getNode(): Promise<IChatRoomNodeInfo>;
|
|
100
100
|
/**
|
|
101
101
|
* 重连聊天室
|
|
102
|
+
* @param url 节点地址
|
|
102
103
|
* @param timeout 超时时间
|
|
103
104
|
* @param error 错误回调
|
|
104
105
|
* @param close 关闭回调
|
|
@@ -124,13 +125,15 @@ declare class ChatRoom {
|
|
|
124
125
|
/**
|
|
125
126
|
* 添加聊天室消息监听函数
|
|
126
127
|
* @param wsCallback 消息监听函数
|
|
128
|
+
* @param url 节点地址
|
|
127
129
|
* @param timeout 超时时间
|
|
128
130
|
* @param error 错误回调
|
|
129
131
|
* @param close 关闭回调
|
|
130
132
|
*/
|
|
131
133
|
addListener(wsCallback: (event: {
|
|
132
134
|
msg: Message;
|
|
133
|
-
}) => void, { timeout, error, close }?: {
|
|
135
|
+
}) => void, { url, timeout, error, close }?: {
|
|
136
|
+
url?: string;
|
|
134
137
|
timeout?: number;
|
|
135
138
|
error?: (ev: any) => void;
|
|
136
139
|
close?: (ev: any) => void;
|
package/lib/chatroom.js
CHANGED
|
@@ -490,6 +490,7 @@ var ChatRoom = /** @class */ (function () {
|
|
|
490
490
|
};
|
|
491
491
|
/**
|
|
492
492
|
* 重连聊天室
|
|
493
|
+
* @param url 节点地址
|
|
493
494
|
* @param timeout 超时时间
|
|
494
495
|
* @param error 错误回调
|
|
495
496
|
* @param close 关闭回调
|
|
@@ -507,106 +508,109 @@ var ChatRoom = /** @class */ (function () {
|
|
|
507
508
|
case 1:
|
|
508
509
|
url = _g.sent();
|
|
509
510
|
_g.label = 2;
|
|
510
|
-
case 2:
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
_a = this;
|
|
524
|
-
_b = reconnecting_websocket_1.default.bind;
|
|
525
|
-
_c = [void 0, "".concat(url), []];
|
|
526
|
-
_e = {};
|
|
527
|
-
if (!utils_1.isBrowse) return [3 /*break*/, 1];
|
|
528
|
-
_d = window.WebSocket;
|
|
529
|
-
return [3 /*break*/, 3];
|
|
530
|
-
case 1: return [4 /*yield*/, Promise.resolve().then(function () { return __importStar(require('ws')); })];
|
|
531
|
-
case 2:
|
|
532
|
-
_d = (_f.sent()).WebSocket;
|
|
533
|
-
_f.label = 3;
|
|
534
|
-
case 3:
|
|
535
|
-
_a._rws = new (_b.apply(reconnecting_websocket_1.default, _c.concat([(
|
|
536
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
537
|
-
_e.WebSocket = _d,
|
|
538
|
-
_e.connectionTimeout = 1000 * timeout,
|
|
539
|
-
_e)])))();
|
|
540
|
-
this._rws.onopen = function (e) {
|
|
541
|
-
if (_this._wsTimer) {
|
|
542
|
-
clearInterval(_this._wsTimer);
|
|
511
|
+
case 2:
|
|
512
|
+
if (!url.includes('apiKey='))
|
|
513
|
+
url += "".concat(url.includes('?') ? '&' : '?', "apiKey=").concat(this._apiKey);
|
|
514
|
+
return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
515
|
+
var _a, _b, _c, _d;
|
|
516
|
+
var _e;
|
|
517
|
+
var _this = this;
|
|
518
|
+
return __generator(this, function (_f) {
|
|
519
|
+
switch (_f.label) {
|
|
520
|
+
case 0:
|
|
521
|
+
if (this._rws && url !== this._rws.url) {
|
|
522
|
+
this._rws.close();
|
|
523
|
+
this._rws = null;
|
|
543
524
|
}
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
return
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
525
|
+
if (this._rws)
|
|
526
|
+
return [2 /*return*/, resolve(this._rws.reconnect())];
|
|
527
|
+
_a = this;
|
|
528
|
+
_b = reconnecting_websocket_1.default.bind;
|
|
529
|
+
_c = [void 0, "".concat(url), []];
|
|
530
|
+
_e = {};
|
|
531
|
+
if (!utils_1.isBrowse) return [3 /*break*/, 1];
|
|
532
|
+
_d = window.WebSocket;
|
|
533
|
+
return [3 /*break*/, 3];
|
|
534
|
+
case 1: return [4 /*yield*/, Promise.resolve().then(function () { return __importStar(require('ws')); })];
|
|
535
|
+
case 2:
|
|
536
|
+
_d = (_f.sent()).WebSocket;
|
|
537
|
+
_f.label = 3;
|
|
538
|
+
case 3:
|
|
539
|
+
_a._rws = new (_b.apply(reconnecting_websocket_1.default, _c.concat([(
|
|
540
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
541
|
+
_e.WebSocket = _d,
|
|
542
|
+
_e.connectionTimeout = 1000 * timeout,
|
|
543
|
+
_e)])))();
|
|
544
|
+
this._rws.onopen = function (e) {
|
|
545
|
+
if (_this._wsTimer) {
|
|
546
|
+
clearInterval(_this._wsTimer);
|
|
547
|
+
}
|
|
548
|
+
_this._wsTimer = setInterval(function () {
|
|
549
|
+
var _a;
|
|
550
|
+
(_a = _this._rws) === null || _a === void 0 ? void 0 : _a.send('-hb-');
|
|
551
|
+
}, 1000 * 60 * 3);
|
|
552
|
+
resolve(e);
|
|
553
|
+
};
|
|
554
|
+
this._rws.onmessage = function (e) { return __awaiter(_this, void 0, void 0, function () {
|
|
555
|
+
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;
|
|
556
|
+
return __generator(this, function (_a) {
|
|
557
|
+
msg = JSON.parse(e.data);
|
|
558
|
+
data = null;
|
|
559
|
+
switch (msg.type) {
|
|
560
|
+
case 'online': {
|
|
561
|
+
this._onlines = msg.users;
|
|
562
|
+
this._discusse = msg.discussing;
|
|
563
|
+
data = this._onlines;
|
|
564
|
+
break;
|
|
565
|
+
}
|
|
566
|
+
case 'discussChanged': {
|
|
567
|
+
data = msg.newDiscuss;
|
|
568
|
+
break;
|
|
569
|
+
}
|
|
570
|
+
case 'revoke': {
|
|
571
|
+
data = msg.oId;
|
|
572
|
+
break;
|
|
573
|
+
}
|
|
574
|
+
case 'barrager': {
|
|
575
|
+
barragerContent = msg.barragerContent, userAvatarURL = msg.userAvatarURL, userAvatarURL20 = msg.userAvatarURL20, userNickname = msg.userNickname, barragerColor = msg.barragerColor, userName = msg.userName, userAvatarURL210 = msg.userAvatarURL210, userAvatarURL48 = msg.userAvatarURL48;
|
|
576
|
+
data = { barragerContent: barragerContent, userAvatarURL: userAvatarURL, userAvatarURL20: userAvatarURL20, userNickname: userNickname, barragerColor: barragerColor, userName: userName, userAvatarURL210: userAvatarURL210, userAvatarURL48: userAvatarURL48 };
|
|
577
|
+
break;
|
|
578
|
+
}
|
|
579
|
+
case 'msg': {
|
|
580
|
+
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;
|
|
581
|
+
try {
|
|
582
|
+
data_1 = JSON.parse(content);
|
|
583
|
+
content = data_1;
|
|
584
|
+
msg.type = data_1.msgType;
|
|
585
|
+
}
|
|
586
|
+
catch (e) { }
|
|
587
|
+
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) };
|
|
588
|
+
break;
|
|
589
|
+
}
|
|
590
|
+
case 'redPacketStatus': {
|
|
591
|
+
oId = msg.oId, count = msg.count, got = msg.got, whoGive = msg.whoGive, whoGot = msg.whoGot;
|
|
592
|
+
data = { oId: oId, count: count, got: got, whoGive: whoGive, whoGot: whoGot };
|
|
593
|
+
break;
|
|
594
|
+
}
|
|
595
|
+
case 'customMessage': {
|
|
596
|
+
data = msg.message;
|
|
597
|
+
break;
|
|
581
598
|
}
|
|
582
|
-
catch (e) { }
|
|
583
|
-
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) };
|
|
584
|
-
break;
|
|
585
|
-
}
|
|
586
|
-
case 'redPacketStatus': {
|
|
587
|
-
oId = msg.oId, count = msg.count, got = msg.got, whoGive = msg.whoGive, whoGot = msg.whoGot;
|
|
588
|
-
data = { oId: oId, count: count, got: got, whoGive: whoGive, whoGot: whoGot };
|
|
589
|
-
break;
|
|
590
|
-
}
|
|
591
|
-
case 'customMessage': {
|
|
592
|
-
data = msg.message;
|
|
593
|
-
break;
|
|
594
599
|
}
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
600
|
+
this._wsCallbacks.forEach(function (call) { return call(Object.assign(__assign(__assign({}, e), { msg: { type: msg.type, data: data } }))); });
|
|
601
|
+
return [2 /*return*/];
|
|
602
|
+
});
|
|
603
|
+
}); };
|
|
604
|
+
this._rws.onerror = error || (function (e) {
|
|
605
|
+
console.error(e);
|
|
606
|
+
});
|
|
607
|
+
this._rws.onclose = close || (function (e) {
|
|
608
|
+
console.log(e);
|
|
598
609
|
});
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
this._rws.onclose = close || (function (e) {
|
|
604
|
-
console.log(e);
|
|
605
|
-
});
|
|
606
|
-
return [2 /*return*/];
|
|
607
|
-
}
|
|
608
|
-
});
|
|
609
|
-
}); })];
|
|
610
|
+
return [2 /*return*/];
|
|
611
|
+
}
|
|
612
|
+
});
|
|
613
|
+
}); })];
|
|
610
614
|
}
|
|
611
615
|
});
|
|
612
616
|
});
|
|
@@ -629,12 +633,13 @@ var ChatRoom = /** @class */ (function () {
|
|
|
629
633
|
/**
|
|
630
634
|
* 添加聊天室消息监听函数
|
|
631
635
|
* @param wsCallback 消息监听函数
|
|
636
|
+
* @param url 节点地址
|
|
632
637
|
* @param timeout 超时时间
|
|
633
638
|
* @param error 错误回调
|
|
634
639
|
* @param close 关闭回调
|
|
635
640
|
*/
|
|
636
641
|
ChatRoom.prototype.addListener = function (wsCallback, _a) {
|
|
637
|
-
var _b = _a === void 0 ? {} : _a, _c = _b.timeout, timeout = _c === void 0 ? 10 : _c, _d = _b.error, error = _d === void 0 ? function (ev) { } : _d, _e = _b.close, close = _e === void 0 ? function (ev) { } : _e;
|
|
642
|
+
var _b = _a === void 0 ? {} : _a, url = _b.url, _c = _b.timeout, timeout = _c === void 0 ? 10 : _c, _d = _b.error, error = _d === void 0 ? function (ev) { } : _d, _e = _b.close, close = _e === void 0 ? function (ev) { } : _e;
|
|
638
643
|
return __awaiter(this, void 0, void 0, function () {
|
|
639
644
|
return __generator(this, function (_f) {
|
|
640
645
|
switch (_f.label) {
|
|
@@ -645,7 +650,7 @@ var ChatRoom = /** @class */ (function () {
|
|
|
645
650
|
return [2 /*return*/];
|
|
646
651
|
}
|
|
647
652
|
this._wsCallbacks.push(wsCallback);
|
|
648
|
-
return [4 /*yield*/, this.reconnect({ timeout: timeout, error: error, close: close })];
|
|
653
|
+
return [4 /*yield*/, this.reconnect({ url: url, timeout: timeout, error: error, close: close })];
|
|
649
654
|
case 1:
|
|
650
655
|
_f.sent();
|
|
651
656
|
return [2 /*return*/];
|