fix: enable soft reconnect (#119)
CD / Test (push) Successful in 19s
CD / Build and push (amd64) (push) Successful in 33s
CD / Create tag (push) Successful in 6s
CD / Build and push (arm64) (push) Successful in 1m33s
CD / Create manifest (push) Successful in 8s

Try to reconnect softly to the ts3 server instead of crashing hard in case of closed connection or errors. Also tracks if a re-connection attempt is currently in progress.

Reviewed-on: #119
Reviewed-by: branch-buddy <branch-buddy@t00n.de>
Co-authored-by: Timo Behrendt <t.behrendt@t00n.de>
Co-committed-by: Timo Behrendt <t.behrendt@t00n.de>
This commit was merged in pull request #119.
This commit is contained in:
2026-05-07 19:10:17 +02:00
committed by t.behrendt
parent 0670e54cf1
commit 0e4ab1bfc6
+23 -4
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);
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 {