mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 12:02: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,20 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { isSafeOpenTargetForPrefill } from "./open-target-policy.js";
|
||||
|
||||
test("open-mode target prefill follows the same allow/deny result as the join policy", async () => {
|
||||
assert.equal(await isSafeOpenTargetForPrefill({ host: "198.51.100.24", port: 9987 }, {
|
||||
resolveTarget: async (target) => target,
|
||||
}), true);
|
||||
assert.equal(await isSafeOpenTargetForPrefill({ host: "teamspeak", port: 9987 }, {
|
||||
resolveTarget: async () => { throw new Error("private or unresolved target"); },
|
||||
}), false);
|
||||
});
|
||||
|
||||
test("open-mode target prefill fails closed when DNS validation stalls", async () => {
|
||||
const result = await isSafeOpenTargetForPrefill({ host: "internal.example", port: 9987 }, {
|
||||
timeoutMs: 10,
|
||||
resolveTarget: async () => new Promise(() => undefined),
|
||||
});
|
||||
assert.equal(result, false);
|
||||
});
|
||||
@@ -27,6 +27,26 @@ export async function resolveSafeOpenTarget(target: TeamSpeakTarget): Promise<Te
|
||||
return { host: addresses[0]!.address, port: target.port };
|
||||
}
|
||||
|
||||
/** A bounded, non-authoritative check used only to avoid pre-filling a target that open mode will reject. */
|
||||
export async function isSafeOpenTargetForPrefill(
|
||||
target: TeamSpeakTarget,
|
||||
options: { timeoutMs?: number; resolveTarget?: (target: TeamSpeakTarget) => Promise<TeamSpeakTarget> } = {},
|
||||
): Promise<boolean> {
|
||||
const timeoutMs = options.timeoutMs ?? 1_000;
|
||||
const resolveTarget = options.resolveTarget ?? resolveSafeOpenTarget;
|
||||
let timer: ReturnType<typeof setTimeout> | undefined;
|
||||
try {
|
||||
return await Promise.race([
|
||||
Promise.resolve().then(() => resolveTarget(target)).then(() => true, () => false),
|
||||
new Promise<boolean>((resolve) => {
|
||||
timer = setTimeout(() => resolve(false), timeoutMs);
|
||||
}),
|
||||
]);
|
||||
} finally {
|
||||
if (timer !== undefined) clearTimeout(timer);
|
||||
}
|
||||
}
|
||||
|
||||
export function isRestrictedAddress(address: string): boolean {
|
||||
const version = isIP(address);
|
||||
if (version === 4) return isRestrictedIpv4(address);
|
||||
|
||||
+16
-3
@@ -9,7 +9,7 @@ import { parseTeamSpeakTarget, teamSpeakTargetKey } from "../domain/teamspeak-ta
|
||||
import { createAdminRouter } from "../admin/admin-router.js";
|
||||
import type { AdminService } from "../admin/admin-service.js";
|
||||
import { AdminSessionStore } from "../admin/admin-session.js";
|
||||
import { resolveSafeOpenTarget } from "../security/open-target-policy.js";
|
||||
import { isSafeOpenTargetForPrefill, resolveSafeOpenTarget } from "../security/open-target-policy.js";
|
||||
import { identityFromString } from "@echosixhiya/teamspeak-client";
|
||||
import { JoinRateLimiter } from "./join-rate-limit.js";
|
||||
import type { ConfiguredAccelerationRelay } from "./acceleration-relay.js";
|
||||
@@ -65,7 +65,7 @@ export function createWebServer(options: WebServerOptions): WebServer {
|
||||
app.get("/health", healthHandler);
|
||||
app.get("/api/health", healthHandler);
|
||||
|
||||
app.get("/api/public-config", (request, response) => {
|
||||
app.get("/api/public-config", async (request, response) => {
|
||||
response.setHeader("Cache-Control", "no-store");
|
||||
const acceleration = resolveAccelerationOptions(options.voiceBridgeOptions.acceleration);
|
||||
let visitorNumber = readVisitorNumberCookie(request.header("cookie"));
|
||||
@@ -90,8 +90,21 @@ export function createWebServer(options: WebServerOptions): WebServer {
|
||||
} else if (visitorNumber !== null) {
|
||||
visitorTotal = visitorNumber;
|
||||
}
|
||||
const publicConfig = options.adminService.getPublicConfig();
|
||||
let target = typeof publicConfig.target === "string" ? publicConfig.target : "";
|
||||
let targetPrefillBlocked = false;
|
||||
if (publicConfig.accessMode === "open" && target.trim()) {
|
||||
try {
|
||||
targetPrefillBlocked = !await isSafeOpenTargetForPrefill(parseTeamSpeakTarget(target));
|
||||
} catch {
|
||||
targetPrefillBlocked = true;
|
||||
}
|
||||
if (targetPrefillBlocked) target = "";
|
||||
}
|
||||
response.json({
|
||||
...options.adminService.getPublicConfig(),
|
||||
...publicConfig,
|
||||
target,
|
||||
targetPrefillBlocked,
|
||||
...(visitorNumber === null ? {} : { visitorNumber }),
|
||||
...(visitorTotal === null ? {} : { visitorTotal }),
|
||||
accelerationAvailable: acceleration.length > 0,
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
type ClientOptions,
|
||||
type Identity,
|
||||
} from "@echosixhiya/teamspeak-client";
|
||||
import { WebSpeakTeamSpeakResolver } from "./teamspeak-resolver.js";
|
||||
import type { Logger } from "../logger.js";
|
||||
import { normalizeTeamSpeakError } from "../errors.js";
|
||||
import { formatTeamSpeakTarget, teamSpeakTargetKey, type TeamSpeakTarget } from "../domain/teamspeak-target.js";
|
||||
@@ -85,6 +86,7 @@ export class TeamSpeakAdapter {
|
||||
) {
|
||||
this.identity = options.identity ?? generateIdentity(8);
|
||||
const clientOptions: ClientOptions = {
|
||||
resolver: new WebSpeakTeamSpeakResolver(),
|
||||
serverPassword: options.serverPassword,
|
||||
defaultChannel: options.defaultChannel,
|
||||
defaultChannelPassword: options.channelPassword,
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import type { AddrResolver, ResolvedAddr } from "@echosixhiya/teamspeak-client";
|
||||
import { WebSpeakTeamSpeakResolver } from "./teamspeak-resolver.js";
|
||||
|
||||
function fixedResolver(result: ResolvedAddr[], onResolve?: (signal?: AbortSignal) => void): AddrResolver {
|
||||
return {
|
||||
resolve: async (_address, signal) => {
|
||||
onResolve?.(signal);
|
||||
return result;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
test("private short hostnames use local DNS directly without cloud nickname discovery", async () => {
|
||||
let baseCalls = 0;
|
||||
const resolver = new WebSpeakTeamSpeakResolver({
|
||||
localLookup: async (hostname) => {
|
||||
assert.equal(hostname, "teamspeak");
|
||||
return [{ address: "172.18.0.6", family: 4 }];
|
||||
},
|
||||
baseResolver: {
|
||||
resolve: async () => {
|
||||
baseCalls++;
|
||||
return [];
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const result = await resolver.resolve("teamspeak:9988");
|
||||
assert.equal(result[0]?.addr, "172.18.0.6:9988");
|
||||
assert.equal(result[0]?.source, "Direct");
|
||||
assert.equal(baseCalls, 0);
|
||||
});
|
||||
|
||||
test("undotted nickname discovery is bounded and falls back to the direct host", async () => {
|
||||
let baseSignal: AbortSignal | undefined;
|
||||
const resolver = new WebSpeakTeamSpeakResolver({
|
||||
localLookup: async () => [],
|
||||
baseResolver: {
|
||||
resolve: async (_address, signal) => {
|
||||
baseSignal = signal;
|
||||
return new Promise<ResolvedAddr[]>(() => undefined);
|
||||
},
|
||||
},
|
||||
localAliasLookupTimeoutMs: 20,
|
||||
nicknameLookupTimeoutMs: 25,
|
||||
});
|
||||
|
||||
const result = await resolver.resolve("teamspeak:9987");
|
||||
assert.equal(result[0]?.addr, "teamspeak:9987");
|
||||
assert.equal(result[0]?.source, "Direct");
|
||||
assert.equal(baseSignal?.aborted, true);
|
||||
});
|
||||
|
||||
test("dotted hostnames preserve the SDK resolver path", async () => {
|
||||
const expected: ResolvedAddr[] = [{ addr: "voice.example.com:9987", source: "Direct", expiry: new Date(0) }];
|
||||
let lookupCalls = 0;
|
||||
let baseCalls = 0;
|
||||
const resolver = new WebSpeakTeamSpeakResolver({
|
||||
localLookup: async () => {
|
||||
lookupCalls++;
|
||||
return [];
|
||||
},
|
||||
baseResolver: fixedResolver(expected, () => { baseCalls++; }),
|
||||
});
|
||||
|
||||
assert.deepEqual(await resolver.resolve("voice.example.com:9987"), expected);
|
||||
assert.equal(lookupCalls, 0);
|
||||
assert.equal(baseCalls, 1);
|
||||
});
|
||||
|
||||
test("DNS resolution failures continue through bounded nickname discovery", async () => {
|
||||
const expected: ResolvedAddr[] = [{ addr: "public.example.com:9987", source: "Nickname", expiry: new Date(0) }];
|
||||
const resolver = new WebSpeakTeamSpeakResolver({
|
||||
localLookup: async () => { throw new Error("ENOTFOUND"); },
|
||||
baseResolver: fixedResolver(expected),
|
||||
nicknameLookupTimeoutMs: 100,
|
||||
});
|
||||
|
||||
assert.deepEqual(await resolver.resolve("public-alias"), expected);
|
||||
});
|
||||
@@ -0,0 +1,153 @@
|
||||
import { lookup } from "node:dns/promises";
|
||||
import { isIP } from "node:net";
|
||||
import { Resolver as TeamSpeakResolver } from "@echosixhiya/teamspeak-client/discovery";
|
||||
import type { AddrResolver, ResolvedAddr } from "@echosixhiya/teamspeak-client";
|
||||
import { formatTeamSpeakTarget, parseTeamSpeakTarget } from "../domain/teamspeak-target.js";
|
||||
|
||||
const LOCAL_ALIAS_LOOKUP_TIMEOUT_MS = 1_000;
|
||||
const NICKNAME_LOOKUP_TIMEOUT_MS = 3_000;
|
||||
|
||||
type LocalAddress = { address: string; family: number };
|
||||
type LocalLookup = (hostname: string) => Promise<LocalAddress[]>;
|
||||
|
||||
interface WebSpeakTeamSpeakResolverOptions {
|
||||
baseResolver?: AddrResolver;
|
||||
localLookup?: LocalLookup;
|
||||
localAliasLookupTimeoutMs?: number;
|
||||
nicknameLookupTimeoutMs?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Keep TeamSpeak nickname discovery for normal names, while allowing an
|
||||
* internal short hostname (for example a Docker Compose service name) to use
|
||||
* the local resolver directly. Bound cloud nickname discovery so a network
|
||||
* black hole cannot prevent the SDK's direct-host fallback indefinitely.
|
||||
*/
|
||||
export class WebSpeakTeamSpeakResolver implements AddrResolver {
|
||||
private readonly baseResolver: AddrResolver;
|
||||
private readonly localLookup: LocalLookup;
|
||||
private readonly localAliasLookupTimeoutMs: number;
|
||||
private readonly nicknameLookupTimeoutMs: number;
|
||||
|
||||
constructor(options: WebSpeakTeamSpeakResolverOptions = {}) {
|
||||
this.baseResolver = options.baseResolver ?? new TeamSpeakResolver();
|
||||
this.localLookup = options.localLookup ?? ((hostname) => lookup(hostname, { all: true, verbatim: true }));
|
||||
this.localAliasLookupTimeoutMs = options.localAliasLookupTimeoutMs ?? LOCAL_ALIAS_LOOKUP_TIMEOUT_MS;
|
||||
this.nicknameLookupTimeoutMs = options.nicknameLookupTimeoutMs ?? NICKNAME_LOOKUP_TIMEOUT_MS;
|
||||
}
|
||||
|
||||
async resolve(address: string, signal?: AbortSignal): Promise<ResolvedAddr[]> {
|
||||
if (signal?.aborted) throw signal.reason ?? new Error("TeamSpeak address resolution was aborted");
|
||||
|
||||
let target;
|
||||
try {
|
||||
target = parseTeamSpeakTarget(address);
|
||||
} catch {
|
||||
return this.resolveBase(address, signal);
|
||||
}
|
||||
|
||||
const { host, port } = target;
|
||||
if (isIP(host) || host === "localhost" || host.includes(".")) {
|
||||
return this.resolveBase(address, signal);
|
||||
}
|
||||
|
||||
const localAddresses = await raceWithTimeout(
|
||||
Promise.resolve().then(() => this.localLookup(host)),
|
||||
this.localAliasLookupTimeoutMs,
|
||||
signal,
|
||||
)
|
||||
.catch((error: unknown) => {
|
||||
if (signal?.aborted) throw signal.reason ?? error;
|
||||
return null;
|
||||
});
|
||||
const localAddress = localAddresses?.find(({ address: candidate }) => isPrivateNetworkAddress(candidate));
|
||||
if (localAddress) {
|
||||
return [directAddress(localAddress.address, port)];
|
||||
}
|
||||
|
||||
const baseResults = await this.resolveBaseWithTimeout(address, signal);
|
||||
return baseResults?.length ? baseResults : [directAddress(host, port)];
|
||||
}
|
||||
|
||||
private resolveBase(address: string, signal?: AbortSignal): Promise<ResolvedAddr[]> {
|
||||
return this.baseResolver.resolve(address, signal);
|
||||
}
|
||||
|
||||
private async resolveBaseWithTimeout(address: string, signal?: AbortSignal): Promise<ResolvedAddr[] | null> {
|
||||
const timeoutController = new AbortController();
|
||||
const combinedSignal = signal ? AbortSignal.any([signal, timeoutController.signal]) : timeoutController.signal;
|
||||
try {
|
||||
return await raceWithTimeout(
|
||||
Promise.resolve().then(() => this.baseResolver.resolve(address, combinedSignal)),
|
||||
this.nicknameLookupTimeoutMs,
|
||||
signal,
|
||||
);
|
||||
} catch (error: unknown) {
|
||||
if (signal?.aborted) throw signal.reason ?? error;
|
||||
return null;
|
||||
} finally {
|
||||
timeoutController.abort(new Error("TeamSpeak nickname lookup timed out"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function directAddress(host: string, port: number): ResolvedAddr {
|
||||
return {
|
||||
addr: formatTeamSpeakTarget({ host, port }),
|
||||
source: "Direct",
|
||||
expiry: new Date(0),
|
||||
};
|
||||
}
|
||||
|
||||
function isPrivateNetworkAddress(address: string): boolean {
|
||||
const version = isIP(address);
|
||||
if (version === 4) {
|
||||
const [a, b] = address.split(".").map(Number) as [number, number, number, number];
|
||||
return a === 10
|
||||
|| a === 127
|
||||
|| (a === 169 && b === 254)
|
||||
|| (a === 172 && b >= 16 && b <= 31)
|
||||
|| (a === 192 && b === 168);
|
||||
}
|
||||
if (version !== 6) return false;
|
||||
|
||||
const normalized = address.toLowerCase();
|
||||
if (normalized.startsWith("::ffff:")) return isPrivateNetworkAddress(normalized.slice("::ffff:".length));
|
||||
if (normalized === "::" || normalized === "::1") return true;
|
||||
const firstGroup = Number.parseInt(normalized.split(":", 1)[0] || "0", 16);
|
||||
return (firstGroup & 0xfe00) === 0xfc00 || (firstGroup & 0xffc0) === 0xfe80;
|
||||
}
|
||||
|
||||
function raceWithTimeout<T>(work: Promise<T>, timeoutMs: number, signal?: AbortSignal): Promise<T | null> {
|
||||
if (signal?.aborted) return Promise.reject(signal.reason ?? new Error("TeamSpeak address resolution was aborted"));
|
||||
|
||||
return new Promise<T | null>((resolve, reject) => {
|
||||
let settled = false;
|
||||
const finish = (callback: (value: T | null) => void, value: T | null): void => {
|
||||
if (settled) return;
|
||||
settled = true;
|
||||
clearTimeout(timer);
|
||||
signal?.removeEventListener("abort", onAbort);
|
||||
callback(value);
|
||||
};
|
||||
const onAbort = (): void => {
|
||||
if (settled) return;
|
||||
settled = true;
|
||||
clearTimeout(timer);
|
||||
signal?.removeEventListener("abort", onAbort);
|
||||
reject(signal?.reason ?? new Error("TeamSpeak address resolution was aborted"));
|
||||
};
|
||||
const timer = setTimeout(() => finish(resolve, null), timeoutMs);
|
||||
signal?.addEventListener("abort", onAbort, { once: true });
|
||||
work.then(
|
||||
(value) => finish(resolve, value),
|
||||
(error: unknown) => {
|
||||
if (settled) return;
|
||||
settled = true;
|
||||
clearTimeout(timer);
|
||||
signal?.removeEventListener("abort", onAbort);
|
||||
reject(error);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -154,6 +154,7 @@ interface WebClientEntry {
|
||||
audio: AudioFlowStats;
|
||||
webrtc: WebRtcAudioSession | null;
|
||||
lastLatencyProbeAt: number;
|
||||
lastAudioStatsProbeAt: number;
|
||||
connectionFailureCode?: string;
|
||||
screenPeerId: string;
|
||||
}
|
||||
@@ -296,6 +297,7 @@ export class VoiceBridge {
|
||||
audio: createAudioFlowStats(),
|
||||
webrtc: null,
|
||||
lastLatencyProbeAt: 0,
|
||||
lastAudioStatsProbeAt: 0,
|
||||
screenPeerId: entryId,
|
||||
};
|
||||
this.entries.set(entryId, entry!);
|
||||
@@ -1730,6 +1732,8 @@ async function handleCommand(
|
||||
sendJson: (message: Record<string, unknown>) => void,
|
||||
): Promise<void> {
|
||||
if (command.type === "latencyProbe") {
|
||||
// Keep the control-path probe for already-open older browser clients. The
|
||||
// current voice status panel exclusively requests actual audio counters.
|
||||
const sequence = command.payload.sequence as string;
|
||||
const now = Date.now();
|
||||
if (now - entry.lastLatencyProbeAt < 150) return;
|
||||
@@ -1747,6 +1751,19 @@ async function handleCommand(
|
||||
return;
|
||||
}
|
||||
|
||||
if (command.type === "audioStatsProbe") {
|
||||
const sequence = command.payload.sequence as string;
|
||||
const now = Date.now();
|
||||
if (now - entry.lastAudioStatsProbeAt < 750) return;
|
||||
entry.lastAudioStatsProbeAt = now;
|
||||
sendJson({
|
||||
type: "audioStats",
|
||||
sequence,
|
||||
stats: snapshotAudioStatus(entry),
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (command.type === "switchChannel") {
|
||||
const rawId = command.payload.channelId as string;
|
||||
const channelPassword = typeof command.payload.password === "string" ? command.payload.password : "";
|
||||
@@ -2042,6 +2059,33 @@ function snapshotAudioStats(entry: WebClientEntry): AudioFlowStats {
|
||||
return stats;
|
||||
}
|
||||
|
||||
function snapshotAudioStatus(entry: WebClientEntry): Record<string, number | string | null> {
|
||||
const stats = snapshotAudioStats(entry);
|
||||
return {
|
||||
transport: entry.webrtc ? "webrtc" : "websocket",
|
||||
ingressFrames: stats.ingressFrames,
|
||||
ingressDroppedFrames: stats.ingressDroppedFrames,
|
||||
ingressMaxGapMs: stats.ingressMaxGapMs,
|
||||
tsSendFrames: stats.tsSendFrames,
|
||||
tsSendErrors: stats.tsSendErrors,
|
||||
tsSendMaxGapMs: stats.tsSendMaxGapMs,
|
||||
tsReceiveFrames: stats.tsReceiveFrames,
|
||||
tsReceiveMaxGapMs: stats.tsReceiveMaxGapMs,
|
||||
egressFrames: stats.egressFrames,
|
||||
egressDroppedFrames: stats.egressDroppedFrames,
|
||||
egressMaxGapMs: stats.egressMaxGapMs,
|
||||
webrtcIngressRtpFrames: stats.webrtcIngressRtpFrames,
|
||||
webrtcIngressRtpMaxGapMs: stats.webrtcIngressRtpMaxGapMs,
|
||||
webrtcEgressRtpFrames: stats.webrtcEgressRtpFrames,
|
||||
webrtcEgressRtpMaxGapMs: stats.webrtcEgressRtpMaxGapMs,
|
||||
webrtcQueueDroppedFrames: stats.webrtcQueueDroppedFrames,
|
||||
webrtcQueueUnderrunTicks: stats.webrtcQueueUnderrunTicks,
|
||||
webrtcPacerLateTicks: stats.webrtcPacerLateTicks,
|
||||
webrtcIngressDecodeErrors: stats.webrtcIngressDecodeErrors,
|
||||
webrtcDownlinkDecodeErrors: stats.webrtcDownlinkDecodeErrors,
|
||||
};
|
||||
}
|
||||
|
||||
function mapChannelTree(snapshot: TSDirectorySnapshot, avatarCache = new Map<string, string | null>()): unknown[] {
|
||||
return snapshot.channels.map((channel) => ({
|
||||
id: String(channel.id),
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { parseClientCommand } from "./voice-protocol.js";
|
||||
|
||||
test("accepts a bounded audio stats snapshot request", () => {
|
||||
assert.deepEqual(parseClientCommand(JSON.stringify({
|
||||
type: "audioStatsProbe",
|
||||
payload: { sequence: "audio-sample-1" },
|
||||
})), {
|
||||
type: "audioStatsProbe",
|
||||
payload: { sequence: "audio-sample-1" },
|
||||
});
|
||||
});
|
||||
|
||||
test("continues accepting the legacy control-path probe for cached clients", () => {
|
||||
assert.deepEqual(parseClientCommand(JSON.stringify({
|
||||
type: "latencyProbe",
|
||||
payload: { sequence: "latency-old-client" },
|
||||
})), {
|
||||
type: "latencyProbe",
|
||||
payload: { sequence: "latency-old-client" },
|
||||
});
|
||||
});
|
||||
|
||||
test("rejects audio stats requests without a short sequence id", () => {
|
||||
const result = parseClientCommand(JSON.stringify({
|
||||
type: "audioStatsProbe",
|
||||
payload: { sequence: "x".repeat(65) },
|
||||
}));
|
||||
assert.deepEqual(result, {
|
||||
error: { code: "INVALID_AUDIO_STATS_PROBE", message: "音频状态采样标识无效" },
|
||||
});
|
||||
});
|
||||
@@ -1,5 +1,5 @@
|
||||
export interface ClientCommand {
|
||||
type: "switchChannel" | "moveClient" | "sendTextMessage" | "sendServerMessage" | "sendPrivateMessage" | "poke" | "setAway" | "setWhisperTargets" | "setWhisperActive" | "setMicrophoneMuted" | "setAccompanimentActive" | "setMemberVolume" | "latencyProbe";
|
||||
type: "switchChannel" | "moveClient" | "sendTextMessage" | "sendServerMessage" | "sendPrivateMessage" | "poke" | "setAway" | "setWhisperTargets" | "setWhisperActive" | "setMicrophoneMuted" | "setAccompanimentActive" | "setMemberVolume" | "latencyProbe" | "audioStatsProbe";
|
||||
requestId?: string;
|
||||
payload: Record<string, unknown>;
|
||||
}
|
||||
@@ -19,7 +19,7 @@ export function parseClientCommand(raw: string): ClientCommandResult {
|
||||
if (value.requestId !== undefined && (typeof value.requestId !== "string" || value.requestId.length > 64)) {
|
||||
return { error: { code: "INVALID_REQUEST_ID", message: "请求标识无效" } };
|
||||
}
|
||||
const supportedTypes = new Set(["switchChannel", "moveClient", "sendTextMessage", "sendServerMessage", "sendPrivateMessage", "poke", "setAway", "setWhisperTargets", "setWhisperActive", "setMicrophoneMuted", "setAccompanimentActive", "setMemberVolume", "latencyProbe"]);
|
||||
const supportedTypes = new Set(["switchChannel", "moveClient", "sendTextMessage", "sendServerMessage", "sendPrivateMessage", "poke", "setAway", "setWhisperTargets", "setWhisperActive", "setMicrophoneMuted", "setAccompanimentActive", "setMemberVolume", "latencyProbe", "audioStatsProbe"]);
|
||||
if (!supportedTypes.has(value.type)) {
|
||||
return { error: { code: "UNKNOWN_MESSAGE_TYPE", message: "不支持的消息类型" } };
|
||||
}
|
||||
@@ -74,6 +74,9 @@ export function parseClientCommand(raw: string): ClientCommandResult {
|
||||
if (value.type === "setMemberVolume" && (typeof value.payload.clientId !== "number" || !Number.isInteger(value.payload.clientId) || value.payload.clientId <= 0 || value.payload.clientId > 65535 || typeof value.payload.volume !== "number" || !Number.isFinite(value.payload.volume) || value.payload.volume < 0 || value.payload.volume > 4)) {
|
||||
return { error: { code: "INVALID_MEMBER_VOLUME", message: "成员音量无效" } };
|
||||
}
|
||||
if (value.type === "audioStatsProbe" && (typeof value.payload.sequence !== "string" || value.payload.sequence.length > 64)) {
|
||||
return { error: { code: "INVALID_AUDIO_STATS_PROBE", message: "音频状态采样标识无效" } };
|
||||
}
|
||||
if (value.type === "latencyProbe" && (typeof value.payload.sequence !== "string" || value.payload.sequence.length > 64)) {
|
||||
return { error: { code: "INVALID_LATENCY_PROBE", message: "延迟探测标识无效" } };
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user