fishpi 0.0.3 → 0.0.7
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/LICENSE +21 -21
- package/README.md +56 -52
- package/lib/src/article.d.ts +60 -0
- package/lib/src/article.js +254 -0
- package/lib/src/breezemoon.d.ts +20 -0
- package/lib/src/breezemoon.js +114 -0
- package/lib/src/chat.d.ts +66 -0
- package/lib/src/chat.js +315 -0
- package/lib/src/chatroom.d.ts +21 -23
- package/lib/src/chatroom.js +377 -262
- package/lib/src/comment.d.ts +31 -0
- package/lib/src/comment.js +207 -0
- package/lib/src/emoji.d.ts +197 -0
- package/lib/src/emoji.js +308 -0
- package/lib/src/index.d.ts +23 -26
- package/lib/src/index.js +179 -218
- package/lib/src/notice.d.ts +1 -3
- package/lib/src/notice.js +116 -59
- package/lib/src/typing.d.ts +1901 -0
- package/lib/src/typing.js +411 -0
- package/lib/src/user.d.ts +35 -0
- package/lib/src/user.js +243 -0
- package/lib/src/utils.d.ts +4 -3
- package/lib/src/utils.js +84 -39
- package/package.json +48 -48
- package/lib/test/index.d.ts +0 -1
- package/lib/test/index.js +0 -27
package/lib/src/chatroom.js
CHANGED
|
@@ -27,15 +27,45 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
27
27
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
28
|
});
|
|
29
29
|
};
|
|
30
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
31
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
32
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
33
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
34
|
+
function step(op) {
|
|
35
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
36
|
+
while (_) try {
|
|
37
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
38
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
39
|
+
switch (op[0]) {
|
|
40
|
+
case 0: case 1: t = op; break;
|
|
41
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
42
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
43
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
44
|
+
default:
|
|
45
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
46
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
47
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
48
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
49
|
+
if (t[2]) _.ops.pop();
|
|
50
|
+
_.trys.pop(); continue;
|
|
51
|
+
}
|
|
52
|
+
op = body.call(thisArg, _);
|
|
53
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
54
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
55
|
+
}
|
|
56
|
+
};
|
|
30
57
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
31
58
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
32
59
|
};
|
|
33
60
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
61
|
+
var reconnecting_websocket_1 = __importDefault(require("reconnecting-websocket"));
|
|
62
|
+
var utils_1 = require("./utils");
|
|
63
|
+
var typing_1 = require("./typing");
|
|
64
|
+
var ChatRoom = /** @class */ (function () {
|
|
65
|
+
function ChatRoom(token) {
|
|
66
|
+
if (token === void 0) { token = ''; }
|
|
38
67
|
this._apiKey = '';
|
|
68
|
+
this._discusse = '';
|
|
39
69
|
this._onlines = [];
|
|
40
70
|
this._rws = null;
|
|
41
71
|
this._wsTimer = null;
|
|
@@ -45,308 +75,393 @@ class ChatRoom {
|
|
|
45
75
|
}
|
|
46
76
|
this._apiKey = token;
|
|
47
77
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
78
|
+
Object.defineProperty(ChatRoom.prototype, "onlines", {
|
|
79
|
+
/**
|
|
80
|
+
* 当前在线人数列表,需要先调用 addListener 添加聊天室消息监听
|
|
81
|
+
*/
|
|
82
|
+
get: function () {
|
|
83
|
+
return this._onlines;
|
|
84
|
+
},
|
|
85
|
+
enumerable: false,
|
|
86
|
+
configurable: true
|
|
87
|
+
});
|
|
88
|
+
Object.defineProperty(ChatRoom.prototype, "discusse", {
|
|
89
|
+
/**
|
|
90
|
+
* 当前聊天室话题,需要先调用 addListener 添加聊天室消息监听
|
|
91
|
+
*/
|
|
92
|
+
get: function () {
|
|
93
|
+
return this._discusse;
|
|
94
|
+
},
|
|
95
|
+
/**
|
|
96
|
+
* 設置当前聊天室话题
|
|
97
|
+
*/
|
|
98
|
+
set: function (val) {
|
|
99
|
+
this.send("[setdiscuss]".concat(val, "[/setdiscuss]"));
|
|
100
|
+
},
|
|
101
|
+
enumerable: false,
|
|
102
|
+
configurable: true
|
|
103
|
+
});
|
|
54
104
|
/**
|
|
55
105
|
* 重新设置请求 Token
|
|
56
106
|
* @param apiKey 接口 API Key
|
|
57
107
|
*/
|
|
58
|
-
setToken(apiKey) {
|
|
108
|
+
ChatRoom.prototype.setToken = function (apiKey) {
|
|
59
109
|
this._apiKey = apiKey;
|
|
60
|
-
}
|
|
110
|
+
};
|
|
61
111
|
/**
|
|
62
112
|
* 查询聊天室历史消息
|
|
63
113
|
* @param page 消息页码
|
|
64
114
|
*/
|
|
65
|
-
more(page
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
115
|
+
ChatRoom.prototype.more = function (page, type) {
|
|
116
|
+
if (page === void 0) { page = 1; }
|
|
117
|
+
if (type === void 0) { type = typing_1.ChatContentType.HTML; }
|
|
118
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
119
|
+
var rsp_1, redpacket_1, e_1;
|
|
120
|
+
return __generator(this, function (_a) {
|
|
121
|
+
switch (_a.label) {
|
|
122
|
+
case 0:
|
|
123
|
+
_a.trys.push([0, 2, , 3]);
|
|
124
|
+
return [4 /*yield*/, (0, utils_1.request)({
|
|
125
|
+
url: "chat-room/more?page=".concat(page, "&type=").concat(type, "&apiKey=").concat(this._apiKey)
|
|
126
|
+
})];
|
|
127
|
+
case 1:
|
|
128
|
+
rsp_1 = _a.sent();
|
|
129
|
+
if (rsp_1.status === 401) {
|
|
130
|
+
return [2 /*return*/, { code: -1, msg: '登录已失效,请重新登录!' }];
|
|
131
|
+
}
|
|
132
|
+
rsp_1 = rsp_1.data;
|
|
133
|
+
if (rsp_1.code != 0) {
|
|
134
|
+
throw new Error(rsp_1.msg);
|
|
135
|
+
}
|
|
136
|
+
if (!rsp_1.data)
|
|
137
|
+
return [2 /*return*/, rsp_1];
|
|
138
|
+
rsp_1.data.forEach(function (d, i, data) {
|
|
139
|
+
try {
|
|
140
|
+
data[i].sysMetal = (0, utils_1.toMetal)(data[i].sysMetal);
|
|
141
|
+
redpacket_1 = JSON.parse(d.content);
|
|
142
|
+
if (redpacket_1.msgType !== 'redPacket')
|
|
143
|
+
return rsp_1;
|
|
144
|
+
redpacket_1.recivers = JSON.parse(redpacket_1.recivers);
|
|
145
|
+
data[i].content = redpacket_1;
|
|
146
|
+
}
|
|
147
|
+
catch (e) { }
|
|
148
|
+
});
|
|
149
|
+
return [2 /*return*/, rsp_1];
|
|
150
|
+
case 2:
|
|
151
|
+
e_1 = _a.sent();
|
|
152
|
+
throw e_1;
|
|
153
|
+
case 3: return [2 /*return*/];
|
|
73
154
|
}
|
|
74
|
-
|
|
75
|
-
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
};
|
|
158
|
+
ChatRoom.prototype.get = function (data) {
|
|
159
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
160
|
+
var rsp_2, redpacket_2, e_2;
|
|
161
|
+
return __generator(this, function (_a) {
|
|
162
|
+
switch (_a.label) {
|
|
163
|
+
case 0:
|
|
164
|
+
_a.trys.push([0, 2, , 3]);
|
|
165
|
+
return [4 /*yield*/, (0, utils_1.request)({
|
|
166
|
+
url: "chat-room/getMessage?oId=".concat(data.oId, "&mode=").concat(data.mode, "&size=").concat(data.size, "&type=").concat(data.type, "&apiKey=").concat(this._apiKey)
|
|
167
|
+
})];
|
|
168
|
+
case 1:
|
|
169
|
+
rsp_2 = _a.sent();
|
|
170
|
+
if (rsp_2.status === 401) {
|
|
171
|
+
return [2 /*return*/, { code: -1, msg: '登录已失效,请重新登录!' }];
|
|
172
|
+
}
|
|
173
|
+
rsp_2 = rsp_2.data;
|
|
174
|
+
if (rsp_2.code != 0) {
|
|
175
|
+
throw new Error(rsp_2.msg);
|
|
176
|
+
}
|
|
177
|
+
if (!rsp_2.data)
|
|
178
|
+
return [2 /*return*/, rsp_2];
|
|
179
|
+
rsp_2.data.forEach(function (d, i, data) {
|
|
180
|
+
try {
|
|
181
|
+
data[i].sysMetal = (0, utils_1.toMetal)(data[i].sysMetal);
|
|
182
|
+
redpacket_2 = JSON.parse(d.content);
|
|
183
|
+
if (redpacket_2.msgType !== 'redPacket')
|
|
184
|
+
return rsp_2;
|
|
185
|
+
redpacket_2.recivers = JSON.parse(redpacket_2.recivers);
|
|
186
|
+
data[i].content = redpacket_2;
|
|
187
|
+
}
|
|
188
|
+
catch (e) { }
|
|
189
|
+
});
|
|
190
|
+
return [2 /*return*/, rsp_2];
|
|
191
|
+
case 2:
|
|
192
|
+
e_2 = _a.sent();
|
|
193
|
+
throw e_2;
|
|
194
|
+
case 3: return [2 /*return*/];
|
|
76
195
|
}
|
|
77
|
-
|
|
78
|
-
if (!rsp.data)
|
|
79
|
-
return rsp;
|
|
80
|
-
let redpacket;
|
|
81
|
-
rsp.data.forEach((d, i, data) => {
|
|
82
|
-
try {
|
|
83
|
-
data[i].sysMetal = (0, utils_1.toMetal)(data[i].sysMetal);
|
|
84
|
-
redpacket = JSON.parse(d.content);
|
|
85
|
-
if (redpacket.msgType !== 'msgType')
|
|
86
|
-
return rsp;
|
|
87
|
-
redpacket.recivers = JSON.parse(redpacket.recivers);
|
|
88
|
-
data[i].content = redpacket;
|
|
89
|
-
}
|
|
90
|
-
catch (e) { }
|
|
91
|
-
});
|
|
92
|
-
return rsp;
|
|
93
|
-
}
|
|
94
|
-
catch (e) {
|
|
95
|
-
throw e;
|
|
96
|
-
}
|
|
196
|
+
});
|
|
97
197
|
});
|
|
98
|
-
}
|
|
198
|
+
};
|
|
99
199
|
/**
|
|
100
200
|
* 撤回消息,普通成员 24 小时内可撤回一条自己的消息,纪律委员/OP/管理员角色可以撤回任意人消息
|
|
101
201
|
* @param oId 消息 Id
|
|
102
202
|
*/
|
|
103
|
-
revoke(oId) {
|
|
104
|
-
return __awaiter(this, void 0, void 0, function
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
203
|
+
ChatRoom.prototype.revoke = function (oId) {
|
|
204
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
205
|
+
var rsp, e_3;
|
|
206
|
+
return __generator(this, function (_a) {
|
|
207
|
+
switch (_a.label) {
|
|
208
|
+
case 0:
|
|
209
|
+
_a.trys.push([0, 2, , 3]);
|
|
210
|
+
return [4 /*yield*/, (0, utils_1.request)({
|
|
211
|
+
url: "chat-room/revoke/".concat(oId),
|
|
212
|
+
method: 'delete',
|
|
213
|
+
data: {
|
|
214
|
+
apiKey: this._apiKey
|
|
215
|
+
},
|
|
216
|
+
})];
|
|
217
|
+
case 1:
|
|
218
|
+
rsp = _a.sent();
|
|
219
|
+
if (rsp.status === 401) {
|
|
220
|
+
return [2 /*return*/, { code: -1, msg: '登录已失效,请重新登录!' }];
|
|
221
|
+
}
|
|
222
|
+
return [2 /*return*/, rsp.data];
|
|
223
|
+
case 2:
|
|
224
|
+
e_3 = _a.sent();
|
|
225
|
+
throw e_3;
|
|
226
|
+
case 3: return [2 /*return*/];
|
|
116
227
|
}
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
catch (e) {
|
|
120
|
-
throw e;
|
|
121
|
-
}
|
|
228
|
+
});
|
|
122
229
|
});
|
|
123
|
-
}
|
|
230
|
+
};
|
|
124
231
|
/**
|
|
125
232
|
* 发送一条消息
|
|
126
233
|
* @param msg 消息内容,支持 Markdown
|
|
127
234
|
*/
|
|
128
|
-
send(msg) {
|
|
129
|
-
return __awaiter(this, void 0, void 0, function
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
235
|
+
ChatRoom.prototype.send = function (msg) {
|
|
236
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
237
|
+
var rsp, e_4;
|
|
238
|
+
return __generator(this, function (_a) {
|
|
239
|
+
switch (_a.label) {
|
|
240
|
+
case 0:
|
|
241
|
+
_a.trys.push([0, 2, , 3]);
|
|
242
|
+
return [4 /*yield*/, (0, utils_1.request)({
|
|
243
|
+
url: "chat-room/send",
|
|
244
|
+
method: 'post',
|
|
245
|
+
data: {
|
|
246
|
+
content: msg,
|
|
247
|
+
apiKey: this._apiKey
|
|
248
|
+
},
|
|
249
|
+
})];
|
|
250
|
+
case 1:
|
|
251
|
+
rsp = _a.sent();
|
|
252
|
+
if (rsp.status === 401) {
|
|
253
|
+
return [2 /*return*/, { code: -1, msg: '登录已失效,请重新登录!' }];
|
|
254
|
+
}
|
|
255
|
+
return [2 /*return*/, rsp.data];
|
|
256
|
+
case 2:
|
|
257
|
+
e_4 = _a.sent();
|
|
258
|
+
throw e_4;
|
|
259
|
+
case 3: return [2 /*return*/];
|
|
142
260
|
}
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
catch (e) {
|
|
146
|
-
throw e;
|
|
147
|
-
}
|
|
261
|
+
});
|
|
148
262
|
});
|
|
149
|
-
}
|
|
263
|
+
};
|
|
150
264
|
/**
|
|
151
265
|
* 获取消息原文(比如 Markdown)
|
|
152
266
|
* @param oId 消息 Id
|
|
153
267
|
*/
|
|
154
|
-
raw(oId) {
|
|
155
|
-
return __awaiter(this, void 0, void 0, function
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
268
|
+
ChatRoom.prototype.raw = function (oId) {
|
|
269
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
270
|
+
var rsp, e_5;
|
|
271
|
+
return __generator(this, function (_a) {
|
|
272
|
+
switch (_a.label) {
|
|
273
|
+
case 0:
|
|
274
|
+
_a.trys.push([0, 2, , 3]);
|
|
275
|
+
return [4 /*yield*/, (0, utils_1.request)({
|
|
276
|
+
url: "cr/raw/".concat(oId),
|
|
277
|
+
})];
|
|
278
|
+
case 1:
|
|
279
|
+
rsp = _a.sent();
|
|
280
|
+
return [2 /*return*/, rsp.data.replace(/<!--.*?-->/g, '')];
|
|
281
|
+
case 2:
|
|
282
|
+
e_5 = _a.sent();
|
|
283
|
+
throw e_5;
|
|
284
|
+
case 3: return [2 /*return*/];
|
|
285
|
+
}
|
|
286
|
+
});
|
|
166
287
|
});
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
url: `api/cloud/sync`,
|
|
209
|
-
method: 'post',
|
|
210
|
-
data: {
|
|
211
|
-
gameId: 'emojis',
|
|
212
|
-
data: JSON.stringify(data),
|
|
213
|
-
apiKey
|
|
214
|
-
},
|
|
288
|
+
};
|
|
289
|
+
Object.defineProperty(ChatRoom.prototype, "redpacket", {
|
|
290
|
+
/**
|
|
291
|
+
* 红包接口对象
|
|
292
|
+
*/
|
|
293
|
+
get: function () {
|
|
294
|
+
var apiKey = this._apiKey;
|
|
295
|
+
var that = this;
|
|
296
|
+
return {
|
|
297
|
+
/**
|
|
298
|
+
* 打开一个红包
|
|
299
|
+
* @param oId 红包消息 Id
|
|
300
|
+
* @param gesture 猜拳类型
|
|
301
|
+
*/
|
|
302
|
+
open: function (oId, gesture) {
|
|
303
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
304
|
+
var rsp, e_6;
|
|
305
|
+
return __generator(this, function (_a) {
|
|
306
|
+
switch (_a.label) {
|
|
307
|
+
case 0:
|
|
308
|
+
_a.trys.push([0, 2, , 3]);
|
|
309
|
+
return [4 /*yield*/, (0, utils_1.request)({
|
|
310
|
+
url: "chat-room/red-packet/open",
|
|
311
|
+
method: 'post',
|
|
312
|
+
data: {
|
|
313
|
+
oId: oId,
|
|
314
|
+
gesture: gesture,
|
|
315
|
+
apiKey: apiKey
|
|
316
|
+
},
|
|
317
|
+
})];
|
|
318
|
+
case 1:
|
|
319
|
+
rsp = _a.sent();
|
|
320
|
+
if (rsp.status === 401) {
|
|
321
|
+
return [2 /*return*/, { code: -1, msg: '登录已失效,请重新登录!' }];
|
|
322
|
+
}
|
|
323
|
+
return [2 /*return*/, rsp.data];
|
|
324
|
+
case 2:
|
|
325
|
+
e_6 = _a.sent();
|
|
326
|
+
throw e_6;
|
|
327
|
+
case 3: return [2 /*return*/];
|
|
328
|
+
}
|
|
215
329
|
});
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
* 红包接口对象
|
|
230
|
-
*/
|
|
231
|
-
get redpacket() {
|
|
232
|
-
let apiKey = this._apiKey;
|
|
233
|
-
let that = this;
|
|
234
|
-
return {
|
|
235
|
-
/**
|
|
236
|
-
* 打开一个红包
|
|
237
|
-
* @param oId 红包消息 Id
|
|
238
|
-
*/
|
|
239
|
-
open(oId) {
|
|
240
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
241
|
-
let rsp;
|
|
242
|
-
try {
|
|
243
|
-
rsp = yield (0, utils_1.request)({
|
|
244
|
-
url: `chat-room/red-packet/open`,
|
|
245
|
-
method: 'post',
|
|
246
|
-
data: {
|
|
247
|
-
oId,
|
|
248
|
-
apiKey
|
|
249
|
-
},
|
|
330
|
+
});
|
|
331
|
+
},
|
|
332
|
+
/**
|
|
333
|
+
* 发送一个红包
|
|
334
|
+
* @param redpacket 红包对象
|
|
335
|
+
*/
|
|
336
|
+
send: function (redpacket) {
|
|
337
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
338
|
+
return __generator(this, function (_a) {
|
|
339
|
+
switch (_a.label) {
|
|
340
|
+
case 0: return [4 /*yield*/, that.send("[redpacket]".concat(JSON.stringify(redpacket), "[/redpacket]"))];
|
|
341
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
342
|
+
}
|
|
250
343
|
});
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
}
|
|
259
|
-
});
|
|
260
|
-
},
|
|
261
|
-
/**
|
|
262
|
-
* 发送一个红包
|
|
263
|
-
* @param redpacket 红包对象
|
|
264
|
-
*/
|
|
265
|
-
send(redpacket) {
|
|
266
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
267
|
-
return yield that.send(`[redpacket]${JSON.stringify(redpacket)}[/redpacket]`);
|
|
268
|
-
});
|
|
269
|
-
}
|
|
270
|
-
};
|
|
271
|
-
}
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
},
|
|
348
|
+
enumerable: false,
|
|
349
|
+
configurable: true
|
|
350
|
+
});
|
|
272
351
|
/**
|
|
273
352
|
* 移除聊天室消息监听函数
|
|
274
353
|
* @param wsCallback 消息监听函数
|
|
275
354
|
*/
|
|
276
|
-
removeListener(wsCallback) {
|
|
355
|
+
ChatRoom.prototype.removeListener = function (wsCallback) {
|
|
277
356
|
if (this._wsCallbacks.indexOf(wsCallback) < 0)
|
|
278
357
|
return;
|
|
279
358
|
this._wsCallbacks.splice(this._wsCallbacks.indexOf(wsCallback), 1);
|
|
280
|
-
}
|
|
359
|
+
};
|
|
281
360
|
/**
|
|
282
361
|
* 添加聊天室消息监听函数
|
|
283
362
|
* @param wsCallback 消息监听函数
|
|
284
363
|
*/
|
|
285
|
-
addListener(wsCallback) {
|
|
286
|
-
return __awaiter(this, void 0, void 0, function
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
});
|
|
298
|
-
this._rws.onopen = (e) => {
|
|
299
|
-
if (this._wsTimer) {
|
|
300
|
-
clearInterval(this._wsTimer);
|
|
301
|
-
}
|
|
302
|
-
this._wsTimer = setInterval(() => {
|
|
303
|
-
var _a;
|
|
304
|
-
(_a = this._rws) === null || _a === void 0 ? void 0 : _a.send('-hb-');
|
|
305
|
-
}, 1000 * 60 * 3);
|
|
306
|
-
};
|
|
307
|
-
this._rws.onmessage = (e) => __awaiter(this, void 0, void 0, function* () {
|
|
308
|
-
let msg = JSON.parse(e.data);
|
|
309
|
-
let data = null;
|
|
310
|
-
switch (msg.type) {
|
|
311
|
-
case 'online': {
|
|
312
|
-
data = this._onlines = msg.users;
|
|
313
|
-
break;
|
|
314
|
-
}
|
|
315
|
-
case 'revoke': {
|
|
316
|
-
data = msg.oId;
|
|
317
|
-
break;
|
|
318
|
-
}
|
|
319
|
-
case 'msg': {
|
|
320
|
-
let { oId, time, userName, userNickname, userAvatarURL, content, md } = msg;
|
|
321
|
-
try {
|
|
322
|
-
let { msg, recivers, money, count, type, got, who, msgType } = JSON.parse(content);
|
|
323
|
-
if (msgType === 'redPacket') {
|
|
324
|
-
data = {
|
|
325
|
-
oId, time, userName, userNickname, userAvatarURL,
|
|
326
|
-
redpacket: { msg, recivers, money, count, type, got, who }
|
|
327
|
-
};
|
|
328
|
-
msg.type = 'redPacket';
|
|
329
|
-
break;
|
|
330
|
-
}
|
|
364
|
+
ChatRoom.prototype.addListener = function (wsCallback) {
|
|
365
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
366
|
+
var _a, _b, _c, _d;
|
|
367
|
+
var _e;
|
|
368
|
+
var _this = this;
|
|
369
|
+
return __generator(this, function (_f) {
|
|
370
|
+
switch (_f.label) {
|
|
371
|
+
case 0:
|
|
372
|
+
if (this._rws !== null) {
|
|
373
|
+
if (this._wsCallbacks.indexOf(wsCallback) < 0)
|
|
374
|
+
this._wsCallbacks.push(wsCallback);
|
|
375
|
+
return [2 /*return*/];
|
|
331
376
|
}
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
break;
|
|
340
|
-
}
|
|
377
|
+
this._wsCallbacks.push(wsCallback);
|
|
378
|
+
_a = this;
|
|
379
|
+
_b = reconnecting_websocket_1.default.bind;
|
|
380
|
+
_c = [void 0, "wss://".concat(utils_1.domain, "chat-room-channel?apiKey=").concat(this._apiKey), []];
|
|
381
|
+
_e = {};
|
|
382
|
+
if (!utils_1.isBrowse) return [3 /*break*/, 1];
|
|
383
|
+
_d = window.WebSocket;
|
|
384
|
+
return [3 /*break*/, 3];
|
|
385
|
+
case 1: return [4 /*yield*/, Promise.resolve().then(function () { return __importStar(require('ws')); })];
|
|
386
|
+
case 2:
|
|
387
|
+
_d = (_f.sent()).WebSocket;
|
|
388
|
+
_f.label = 3;
|
|
389
|
+
case 3:
|
|
390
|
+
_a._rws = new (_b.apply(reconnecting_websocket_1.default, _c.concat([(
|
|
391
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
392
|
+
_e.WebSocket = _d,
|
|
393
|
+
_e.connectionTimeout = 10000,
|
|
394
|
+
_e)])))();
|
|
395
|
+
this._rws.onopen = function (e) {
|
|
396
|
+
if (_this._wsTimer) {
|
|
397
|
+
clearInterval(_this._wsTimer);
|
|
398
|
+
}
|
|
399
|
+
_this._wsTimer = setInterval(function () {
|
|
400
|
+
var _a;
|
|
401
|
+
(_a = _this._rws) === null || _a === void 0 ? void 0 : _a.send('-hb-');
|
|
402
|
+
}, 1000 * 60 * 3);
|
|
403
|
+
};
|
|
404
|
+
this._rws.onmessage = function (e) { return __awaiter(_this, void 0, void 0, function () {
|
|
405
|
+
var msg, data, oId, time, userName, userNickname, userAvatarURL, content, md, _a, msg_1, recivers, money, count, type, got, who, msgType, oId, count, got, whoGive, whoGot;
|
|
406
|
+
return __generator(this, function (_b) {
|
|
407
|
+
msg = JSON.parse(e.data);
|
|
408
|
+
data = null;
|
|
409
|
+
switch (msg.type) {
|
|
410
|
+
case 'online': {
|
|
411
|
+
this._onlines = msg.users;
|
|
412
|
+
this._discusse = msg.discussing;
|
|
413
|
+
data = this._onlines;
|
|
414
|
+
break;
|
|
415
|
+
}
|
|
416
|
+
case 'discussChanged': {
|
|
417
|
+
data = msg.newDiscuss;
|
|
418
|
+
break;
|
|
419
|
+
}
|
|
420
|
+
case 'revoke': {
|
|
421
|
+
data = msg.oId;
|
|
422
|
+
break;
|
|
423
|
+
}
|
|
424
|
+
case 'msg': {
|
|
425
|
+
oId = msg.oId, time = msg.time, userName = msg.userName, userNickname = msg.userNickname, userAvatarURL = msg.userAvatarURL, content = msg.content, md = msg.md;
|
|
426
|
+
try {
|
|
427
|
+
_a = JSON.parse(content), msg_1 = _a.msg, recivers = _a.recivers, money = _a.money, count = _a.count, type = _a.type, got = _a.got, who = _a.who, msgType = _a.msgType;
|
|
428
|
+
if (msgType === 'redPacket') {
|
|
429
|
+
data = {
|
|
430
|
+
oId: oId,
|
|
431
|
+
time: time,
|
|
432
|
+
userName: userName,
|
|
433
|
+
userNickname: userNickname,
|
|
434
|
+
userAvatarURL: userAvatarURL,
|
|
435
|
+
redpacket: { msg: msg_1, recivers: recivers, money: money, count: count, type: type, got: got, who: who }
|
|
436
|
+
};
|
|
437
|
+
msg_1.type = 'redPacket';
|
|
438
|
+
break;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
catch (e) { }
|
|
442
|
+
data = { oId: oId, time: time, userName: userName, userNickname: userNickname, userAvatarURL: userAvatarURL, content: content, md: md };
|
|
443
|
+
break;
|
|
444
|
+
}
|
|
445
|
+
case 'redPacketStatus': {
|
|
446
|
+
oId = msg.oId, count = msg.count, got = msg.got, whoGive = msg.whoGive, whoGot = msg.whoGot;
|
|
447
|
+
data = { oId: oId, count: count, got: got, whoGive: whoGive, whoGot: whoGot };
|
|
448
|
+
break;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
this._wsCallbacks.forEach(function (call) { return call(Object.assign({ msg: { type: msg.type, data: data } }, e)); });
|
|
452
|
+
return [2 /*return*/];
|
|
453
|
+
});
|
|
454
|
+
}); };
|
|
455
|
+
this._rws.onerror = function (e) {
|
|
456
|
+
console.error(e);
|
|
457
|
+
};
|
|
458
|
+
this._rws.onclose = function (e) {
|
|
459
|
+
};
|
|
460
|
+
return [2 /*return*/];
|
|
341
461
|
}
|
|
342
|
-
this._wsCallbacks.forEach(call => call(Object.assign({ msg: { type: msg.type, data } }, e)));
|
|
343
462
|
});
|
|
344
|
-
this._rws.onerror = (e) => {
|
|
345
|
-
console.error(e);
|
|
346
|
-
};
|
|
347
|
-
this._rws.onclose = (e) => {
|
|
348
|
-
};
|
|
349
463
|
});
|
|
350
|
-
}
|
|
351
|
-
|
|
464
|
+
};
|
|
465
|
+
return ChatRoom;
|
|
466
|
+
}());
|
|
352
467
|
exports.default = ChatRoom;
|