fix: enable soft reconnect
CI / Test (pull_request) Successful in 19s

This commit is contained in:
2026-05-07 19:03:50 +02:00
parent 0670e54cf1
commit 0bbe22a383
+24 -5
View File
@@ -1,13 +1,13 @@
import type { Gotify } from "gotify";
import type { Logger } from "pino";
import type { TeamSpeak, TextMessageTargetMode } from "ts3-nodejs-library";
import type { GotifyConfig, Mode } from "./types";
import {
ClientConnect,
ClientDisconnect,
ClientMoved,
TextMessage,
} from "ts3-nodejs-library/lib/types/Events";
import type { GotifyConfig, Mode } from "./types";
function resolveMessageTarget(target: TextMessageTargetMode): string {
if (target === 1) {
@@ -45,6 +45,8 @@ export function ts3gotifyFactory(
gotifyConfig: GotifyConfig,
logger: Logger
) {
let reconnectInProgress = false;
function sendNotification(message: string) {
gotifyClient
.send({
@@ -87,15 +89,32 @@ export function ts3gotifyFactory(
}
}
ts3Client.on("close", async () => {
async function reconnectWithBackoff() {
if (reconnectInProgress) {
return;
}
reconnectInProgress = true;
logger.info("disconnected, trying to reconnect...");
await ts3Client.reconnect(5, 1000);
logger.info("reconnected!");
try {
await ts3Client.reconnect(10, 2000);
logger.info("reconnected!");
} catch (error) {
const message = error instanceof Error ? error.message : String(error);
logger.error(`Error reconnecting to TS3 server: ${message}`);
} finally {
reconnectInProgress = false;
}
}
ts3Client.on("close", async () => {
await reconnectWithBackoff();
});
ts3Client.on("error", (error: Error) => {
logger.error(`Error connecting to TS3 server: ${error.message}`);
process.exit(1);
reconnectWithBackoff();
});
return {