mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-06 05:22:49 +08:00
fix: validate merged voice fallback and host toolbar features
This commit is contained in:
1 parent
02509ea551
commit
001457d004
32 files changed
+319
-102
No files matched your search
+31
-38
@@ -7,7 +7,8 @@ import type { TeamSpeakProtocol } from "../server/teamspeak-adapter.js";
|
||||
import { DEFAULT_WEBRTC_UDP_PORT_RANGE } from "../server/webrtc-config.js";
|
||||
import type { VoiceProfileSetting } from "../shared/voice-profile.js";
|
||||
|
||||
export const DATABASE_SCHEMA_VERSION = 14;
|
||||
export const DATABASE_SCHEMA_VERSION = 13;
|
||||
const VOICE_SETTINGS_META_KEY = "voice_settings_v1";
|
||||
export type AccessMode = "fixed" | "open";
|
||||
|
||||
export interface PersistedSettings {
|
||||
@@ -158,12 +159,6 @@ interface SettingsRow extends Record<string, unknown> {
|
||||
webrtc_stun_server: string;
|
||||
webrtc_udp_start: number;
|
||||
webrtc_udp_end: number;
|
||||
voice_profile: string | null;
|
||||
voice_turn_urls: string | null;
|
||||
voice_turn_secret_encrypted: string | null;
|
||||
voice_turn_ttl_seconds: number | null;
|
||||
voice_opus_ws: number | null;
|
||||
voice_jitter_max_ms: number | null;
|
||||
relay_configured: number;
|
||||
relay_enabled: number;
|
||||
relay_name: string;
|
||||
@@ -267,6 +262,7 @@ export class WebSpeakDatabase {
|
||||
|
||||
getSettings(): PersistedSettings {
|
||||
const row = this.database.prepare("SELECT * FROM settings WHERE id = 1").get() as SettingsRow;
|
||||
const voice = this.readVoiceSettings();
|
||||
return {
|
||||
siteName: row.site_name,
|
||||
welcomeText: row.welcome_text,
|
||||
@@ -289,12 +285,7 @@ export class WebSpeakDatabase {
|
||||
webRtcStunServer: row.webrtc_stun_server,
|
||||
webRtcUdpStart: row.webrtc_udp_start,
|
||||
webRtcUdpEnd: row.webrtc_udp_end,
|
||||
voiceProfile: row.voice_profile === "legacy" || row.voice_profile === "adaptive" || row.voice_profile === "auto" ? row.voice_profile : null,
|
||||
voiceTurnUrls: row.voice_turn_urls,
|
||||
voiceTurnSecretEncrypted: row.voice_turn_secret_encrypted,
|
||||
voiceTurnTtlSeconds: row.voice_turn_ttl_seconds,
|
||||
voiceOpusWs: row.voice_opus_ws === null ? null : row.voice_opus_ws === 1,
|
||||
voiceJitterMaxMs: row.voice_jitter_max_ms,
|
||||
...voice,
|
||||
relayConfigured: row.relay_configured === 1,
|
||||
relayEnabled: row.relay_enabled === 1,
|
||||
relayName: row.relay_name,
|
||||
@@ -780,33 +771,35 @@ export class WebSpeakDatabase {
|
||||
); CREATE INDEX workspace_invites_expiry ON workspace_invites(expires_at);
|
||||
PRAGMA user_version = 13;`);
|
||||
});
|
||||
version = 13;
|
||||
}
|
||||
if (version === 13) {
|
||||
this.transaction(() => {
|
||||
this.database.exec(`
|
||||
-- Console-managed voice deployment overrides. NULL keeps the
|
||||
-- environment baseline; an empty TURN URL or secret explicitly
|
||||
-- disables the corresponding environment value.
|
||||
ALTER TABLE settings ADD COLUMN voice_profile TEXT CHECK (voice_profile IS NULL OR voice_profile IN ('auto', 'legacy', 'adaptive'));
|
||||
ALTER TABLE settings ADD COLUMN voice_turn_urls TEXT;
|
||||
ALTER TABLE settings ADD COLUMN voice_turn_secret_encrypted TEXT;
|
||||
ALTER TABLE settings ADD COLUMN voice_turn_ttl_seconds INTEGER CHECK (voice_turn_ttl_seconds IS NULL OR voice_turn_ttl_seconds BETWEEN 300 AND 86400);
|
||||
ALTER TABLE settings ADD COLUMN voice_opus_ws INTEGER CHECK (voice_opus_ws IS NULL OR voice_opus_ws IN (0, 1));
|
||||
ALTER TABLE settings ADD COLUMN voice_jitter_max_ms INTEGER CHECK (voice_jitter_max_ms IS NULL OR voice_jitter_max_ms BETWEEN 80 AND 500);
|
||||
PRAGMA user_version = 14;
|
||||
`);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/** Optional settings must survive a code-only rollback to the 0.3.3 schema. */
|
||||
private readVoiceSettings(): Pick<PersistedSettings, "voiceProfile" | "voiceTurnUrls" | "voiceTurnSecretEncrypted" | "voiceTurnTtlSeconds" | "voiceOpusWs" | "voiceJitterMaxMs"> {
|
||||
let value: Record<string, unknown> = {};
|
||||
try {
|
||||
const parsed: unknown = JSON.parse(this.getMeta(VOICE_SETTINGS_META_KEY) ?? "{}");
|
||||
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) value = parsed as Record<string, unknown>;
|
||||
} catch { /* A malformed optional value inherits the deployment defaults. */ }
|
||||
return {
|
||||
voiceProfile: value.voiceProfile === "legacy" || value.voiceProfile === "adaptive" || value.voiceProfile === "auto"
|
||||
? value.voiceProfile : null,
|
||||
voiceTurnUrls: typeof value.voiceTurnUrls === "string" ? value.voiceTurnUrls : null,
|
||||
voiceTurnSecretEncrypted: typeof value.voiceTurnSecretEncrypted === "string" ? value.voiceTurnSecretEncrypted : null,
|
||||
voiceTurnTtlSeconds: Number.isInteger(value.voiceTurnTtlSeconds) && Number(value.voiceTurnTtlSeconds) >= 300 && Number(value.voiceTurnTtlSeconds) <= 86400
|
||||
? Number(value.voiceTurnTtlSeconds) : null,
|
||||
voiceOpusWs: typeof value.voiceOpusWs === "boolean" ? value.voiceOpusWs : null,
|
||||
voiceJitterMaxMs: Number.isInteger(value.voiceJitterMaxMs) && Number(value.voiceJitterMaxMs) >= 80 && Number(value.voiceJitterMaxMs) <= 500
|
||||
? Number(value.voiceJitterMaxMs) : null,
|
||||
};
|
||||
}
|
||||
|
||||
private writeSettings(settings: SettingsUpdate, now: string): void {
|
||||
this.database.prepare(
|
||||
`UPDATE settings SET
|
||||
site_name = ?, welcome_text = ?, welcome_text_en = ?, welcome_text_de = ?, welcome_text_ru = ?, welcome_text_ja = ?, access_mode = ?, ts_host = ?, ts_port = ?, ts_target = ?,
|
||||
ts_password_encrypted = ?, webrtc_enabled = ?, webrtc_public_host = ?, webrtc_ipv6_enabled = ?, webrtc_stun_server = ?, webrtc_udp_start = ?,
|
||||
webrtc_udp_end = ?, voice_profile = ?, voice_turn_urls = ?, voice_turn_secret_encrypted = ?, voice_turn_ttl_seconds = ?, voice_opus_ws = ?, voice_jitter_max_ms = ?,
|
||||
relay_configured = ?, relay_enabled = ?, relay_name = ?,
|
||||
webrtc_udp_end = ?, relay_configured = ?, relay_enabled = ?, relay_name = ?,
|
||||
relay_host = ?, relay_port = ?, relay_token_encrypted = ?, updated_at = ?
|
||||
WHERE id = 1`,
|
||||
).run(
|
||||
@@ -827,12 +820,6 @@ export class WebSpeakDatabase {
|
||||
settings.webRtcStunServer ?? "",
|
||||
settings.webRtcUdpStart ?? DEFAULT_WEBRTC_UDP_PORT_RANGE[0],
|
||||
settings.webRtcUdpEnd ?? DEFAULT_WEBRTC_UDP_PORT_RANGE[1],
|
||||
settings.voiceProfile ?? null,
|
||||
settings.voiceTurnUrls ?? null,
|
||||
settings.voiceTurnSecretEncrypted ?? null,
|
||||
settings.voiceTurnTtlSeconds ?? null,
|
||||
settings.voiceOpusWs == null ? null : settings.voiceOpusWs ? 1 : 0,
|
||||
settings.voiceJitterMaxMs ?? null,
|
||||
settings.relayConfigured ? 1 : 0,
|
||||
settings.relayEnabled ? 1 : 0,
|
||||
settings.relayName,
|
||||
@@ -841,6 +828,12 @@ export class WebSpeakDatabase {
|
||||
settings.relayTokenEncrypted,
|
||||
now,
|
||||
);
|
||||
// writeSettings is called within the caller's settings transaction. Older
|
||||
// binaries ignore this key and keep it intact when updating other fields.
|
||||
this.setMeta(VOICE_SETTINGS_META_KEY, JSON.stringify({
|
||||
...this.readVoiceSettings(),
|
||||
...Object.fromEntries(Object.entries(settings).filter(([key, value]) => key.startsWith("voice") && value !== undefined)),
|
||||
}));
|
||||
}
|
||||
|
||||
private insertAudit(event: string, details: Record<string, unknown>, now: string): void {
|
||||
|
||||
Reference in new issue
Block a user