karin-plugin-teamspeak 1.5.2 → 1.5.4
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/apps/ts3.d.ts +3 -0
- package/lib/apps/ts3.js +36 -25
- package/package.json +1 -1
package/lib/apps/ts3.d.ts
CHANGED
|
@@ -2,10 +2,13 @@ import { TeamSpeak } from "ts3-nodejs-library";
|
|
|
2
2
|
declare class ts3 {
|
|
3
3
|
teamspeak: undefined | TeamSpeak;
|
|
4
4
|
connectTimer: number;
|
|
5
|
+
private isReConnecting;
|
|
6
|
+
private reconnectAttempts;
|
|
5
7
|
init: () => Promise<void>;
|
|
6
8
|
getAllChannelList: () => Promise<string | undefined>;
|
|
7
9
|
quitTs: () => Promise<void>;
|
|
8
10
|
reconnectTs: () => Promise<void>;
|
|
11
|
+
private handelReconnect;
|
|
9
12
|
}
|
|
10
13
|
declare const teamspeak3: ts3;
|
|
11
14
|
export declare const getAllUserList: () => Promise<{
|
package/lib/apps/ts3.js
CHANGED
|
@@ -9,10 +9,13 @@ let disNotifyNameList = [];
|
|
|
9
9
|
class ts3 {
|
|
10
10
|
teamspeak;
|
|
11
11
|
connectTimer = 0;
|
|
12
|
+
isReConnecting = false;
|
|
13
|
+
reconnectAttempts = 0;
|
|
12
14
|
//初始化 如果已经有连接了就关闭连接重新连接
|
|
13
15
|
init = async () => {
|
|
14
16
|
const TS = config();
|
|
15
|
-
|
|
17
|
+
this.reconnectAttempts = 0;
|
|
18
|
+
this.isReConnecting = false;
|
|
16
19
|
disNotifyNameList = [TS.NICKNAME, ...TS.DIS_NOTIFY_NAME_LIST];
|
|
17
20
|
logger.info(loggerHex(" ===== ts3 ===== ") + "开始连接ts3服务器...");
|
|
18
21
|
if (this.teamspeak) {
|
|
@@ -34,31 +37,11 @@ class ts3 {
|
|
|
34
37
|
});
|
|
35
38
|
_teamspeak.on("close", (e) => {
|
|
36
39
|
logger.error(loggerHex(" ===== ts3 ===== ") + "ts3连接断开", e);
|
|
37
|
-
|
|
38
|
-
logger.info(loggerHex(" ===== ts3 ===== ") + "重连中...");
|
|
39
|
-
this.teamspeak
|
|
40
|
-
.reconnect(TS.RECONNECT_TIMER, 1000)
|
|
41
|
-
.catch((e) => {
|
|
42
|
-
logger.error(loggerHex(" ===== ts3 ===== ") + "连接TS3失败", e);
|
|
43
|
-
})
|
|
44
|
-
.then(() => {
|
|
45
|
-
logger.info(loggerHex(" ===== ts3 ===== ") + "重连成功");
|
|
46
|
-
});
|
|
47
|
-
}
|
|
40
|
+
this.handelReconnect();
|
|
48
41
|
});
|
|
49
42
|
_teamspeak.on("error", (err) => {
|
|
50
43
|
logger.error(loggerHex(" ===== ts3 ===== ") + "ts3连接出错", err);
|
|
51
|
-
|
|
52
|
-
logger.info(loggerHex(" ===== ts3 ===== ") + "重连中...");
|
|
53
|
-
this.teamspeak
|
|
54
|
-
.reconnect(TS.RECONNECT_TIMER, 1000)
|
|
55
|
-
.catch((e) => {
|
|
56
|
-
logger.error(loggerHex(" ===== ts3 ===== ") + "连接TS3失败", e);
|
|
57
|
-
})
|
|
58
|
-
.then(() => {
|
|
59
|
-
logger.info(loggerHex(" ===== ts3 ===== ") + "重连成功");
|
|
60
|
-
});
|
|
61
|
-
}
|
|
44
|
+
this.handelReconnect();
|
|
62
45
|
});
|
|
63
46
|
_teamspeak.on("clientconnect", (e) => {
|
|
64
47
|
if (!disNotifyNameList.includes(e.client.nickname)) {
|
|
@@ -152,6 +135,28 @@ class ts3 {
|
|
|
152
135
|
this.teamspeak.reconnect(config().RECONNECT_TIMER, 1000);
|
|
153
136
|
}
|
|
154
137
|
};
|
|
138
|
+
//重连逻辑
|
|
139
|
+
async handelReconnect() {
|
|
140
|
+
const TS = config();
|
|
141
|
+
if (!this.teamspeak || this.isReConnecting)
|
|
142
|
+
return;
|
|
143
|
+
this.isReConnecting = true;
|
|
144
|
+
logger.info(loggerHex(" ===== ts3 ===== ") +
|
|
145
|
+
"重连中... 尝试次数: " +
|
|
146
|
+
this.reconnectAttempts +
|
|
147
|
+
"次");
|
|
148
|
+
try {
|
|
149
|
+
await this.teamspeak.reconnect(TS.RECONNECT_TIMER, 1000);
|
|
150
|
+
logger.info(loggerHex(" ===== ts3 ===== ") + "重连成功");
|
|
151
|
+
this.reconnectAttempts = 0; // 重连成功后重置重连次数
|
|
152
|
+
}
|
|
153
|
+
catch (e) {
|
|
154
|
+
logger.error(loggerHex(" ===== ts3 ===== ") + "连接TS3失败", e);
|
|
155
|
+
}
|
|
156
|
+
finally {
|
|
157
|
+
this.isReConnecting = false;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
155
160
|
}
|
|
156
161
|
const teamspeak3 = new ts3();
|
|
157
162
|
setTimeout(() => {
|
|
@@ -196,6 +201,12 @@ router.get("/getAllUserList", async (req, res) => {
|
|
|
196
201
|
const result = await getAllUserList();
|
|
197
202
|
res.send(result);
|
|
198
203
|
});
|
|
199
|
-
|
|
200
|
-
app.use(
|
|
204
|
+
//将路由挂载到express实例中
|
|
205
|
+
app.use("/api/teamspeak", router);
|
|
206
|
+
//将静态资源挂载到express实例中 - 供外部单页应用网页部署时使用
|
|
207
|
+
app.use("/teamspeak", express.static(dirPath + "/resources/static"));
|
|
208
|
+
//供外部单页应用网页部署时使用 可用 ip:port/ts3 访问部署的网页
|
|
209
|
+
app.get("/teamspeak", (req, res) => {
|
|
210
|
+
res.sendFile(dirPath + "/resources/static/index.html");
|
|
211
|
+
});
|
|
201
212
|
export default teamspeak3;
|