mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 03:52:50 +08:00
feat: report live voice status and harden target handling
This commit is contained in:
1 parent
e0d5916a86
commit
0a4fff6f6f
19 files changed
+1003
-101
No files matched your search
@@ -0,0 +1,38 @@
|
||||
import { existsSync } from "node:fs";
|
||||
import http from "node:http";
|
||||
import https from "node:https";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
const scriptDirectory = path.dirname(fileURLToPath(import.meta.url));
|
||||
const appRoot = path.resolve(scriptDirectory, "..");
|
||||
const defaultCertDirectory = path.join(appRoot, "certs");
|
||||
|
||||
export function healthcheckUsesHttps(certDirectory = defaultCertDirectory) {
|
||||
return existsSync(path.join(certDirectory, "cert.pem"));
|
||||
}
|
||||
|
||||
export function runDockerHealthcheck({ mode = process.env.WEBSPEAK_MODE, certDirectory = defaultCertDirectory } = {}) {
|
||||
if (mode?.trim().toLowerCase() === "relay") {
|
||||
process.exitCode = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
const secure = healthcheckUsesHttps(certDirectory);
|
||||
const client = secure ? https : http;
|
||||
const request = client.get({
|
||||
hostname: "127.0.0.1",
|
||||
port: 3040,
|
||||
path: "/health",
|
||||
...(secure ? { rejectUnauthorized: false } : {}),
|
||||
}, (response) => {
|
||||
response.resume();
|
||||
process.exitCode = response.statusCode >= 200 && response.statusCode < 300 ? 0 : 1;
|
||||
});
|
||||
request.setTimeout(4_000, () => request.destroy(new Error("Healthcheck timed out")));
|
||||
request.on("error", () => { process.exitCode = 1; });
|
||||
}
|
||||
|
||||
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
||||
runDockerHealthcheck();
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
import test from "node:test";
|
||||
import { healthcheckUsesHttps } from "./docker-healthcheck.mjs";
|
||||
|
||||
test("Docker healthcheck selects HTTP or HTTPS from the same certificate marker as the server", (context) => {
|
||||
const directory = mkdtempSync(path.join(tmpdir(), "webspeak-healthcheck-"));
|
||||
context.after(() => rmSync(directory, { recursive: true, force: true }));
|
||||
|
||||
assert.equal(healthcheckUsesHttps(directory), false);
|
||||
mkdirSync(directory, { recursive: true });
|
||||
writeFileSync(path.join(directory, "cert.pem"), "test certificate marker");
|
||||
assert.equal(healthcheckUsesHttps(directory), true);
|
||||
});
|
||||
Reference in new issue
Block a user