mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-02 19:42:51 +08:00
feat(admin): manage WebRTC settings from console
This commit is contained in:
1 parent
ecff06e9a1
commit
5c3d1b7e5d
11 files changed
+163
-58
No files matched your search
@@ -332,6 +332,10 @@ function readSettingsInput(body: Record<string, unknown>): AdminSettingsInput {
|
||||
accessMode: body.accessMode === "open" ? "open" : body.accessMode === "fixed" ? "fixed" : body.accessMode as never,
|
||||
siteName: readString(body, "siteName", 80),
|
||||
welcomeText: readOptionalString(body, "welcomeText", 500),
|
||||
webRtcEnabled: body.webRtcEnabled === true,
|
||||
webRtcPublicHost: readOptionalString(body, "webRtcPublicHost", 253),
|
||||
webRtcUdpStart: readOptionalNumber(body, "webRtcUdpStart", 40000),
|
||||
webRtcUdpEnd: readOptionalNumber(body, "webRtcUdpEnd", 40099),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,9 @@ import { type AccessMode, type ManagedInviteRecord, type SettingsUpdate, WebSpea
|
||||
import { hashAdminPassword, validateAdminPassword, verifyAdminPassword } from "../security/admin-password.js";
|
||||
import { decryptSecret, encryptSecret } from "../security/secret-crypto.js";
|
||||
import { probeTeamSpeak, TeamSpeakProbeError, type TeamSpeakProbeResult } from "../server/teamspeak-probe.js";
|
||||
import type { WebRtcAudioOptions } from "../server/webrtc-audio.js";
|
||||
|
||||
const MAX_WEBRTC_UDP_PORTS = 100;
|
||||
|
||||
export interface AdminSettingsInput {
|
||||
target: string;
|
||||
@@ -15,6 +18,10 @@ export interface AdminSettingsInput {
|
||||
accessMode: AccessMode;
|
||||
siteName: string;
|
||||
welcomeText: string;
|
||||
webRtcEnabled: boolean;
|
||||
webRtcPublicHost: string;
|
||||
webRtcUdpStart: number;
|
||||
webRtcUdpEnd: number;
|
||||
}
|
||||
|
||||
export interface ConnectionPolicy {
|
||||
@@ -108,11 +115,24 @@ export class AdminService {
|
||||
lastTestAt: settings.lastTestAt,
|
||||
lastTestLatencyMs: settings.lastTestLatencyMs,
|
||||
lastTestError: settings.lastTestError,
|
||||
webRtcEnabled: settings.webRtcEnabled,
|
||||
webRtcPublicHost: settings.webRtcPublicHost,
|
||||
webRtcUdpStart: settings.webRtcUdpStart,
|
||||
webRtcUdpEnd: settings.webRtcUdpEnd,
|
||||
internalPort: 3040,
|
||||
updatedAt: settings.updatedAt,
|
||||
};
|
||||
}
|
||||
|
||||
getWebRtcAudioOptions(): WebRtcAudioOptions {
|
||||
const settings = this.database.getSettings();
|
||||
return {
|
||||
enabled: settings.webRtcEnabled,
|
||||
...(settings.webRtcPublicHost ? { publicHost: settings.webRtcPublicHost } : {}),
|
||||
icePortRange: [settings.webRtcUdpStart, settings.webRtcUdpEnd],
|
||||
};
|
||||
}
|
||||
|
||||
updateSettings(input: AdminSettingsInput): void {
|
||||
const current = this.database.getSettings();
|
||||
const settings = this.normalizeSettings(input, current);
|
||||
@@ -252,6 +272,21 @@ export class AdminService {
|
||||
if (input.accessMode !== "fixed" && input.accessMode !== "open") {
|
||||
throw new AdminInputError("INVALID_ACCESS_MODE", "Access mode is invalid");
|
||||
}
|
||||
if (typeof input.webRtcEnabled !== "boolean") {
|
||||
throw new AdminInputError("INVALID_WEBRTC_ENABLED", "WebRTC enabled value is invalid");
|
||||
}
|
||||
const webRtcPublicHost = input.webRtcPublicHost.trim();
|
||||
if (webRtcPublicHost.length > 253 || /[\s/\\]/.test(webRtcPublicHost)) {
|
||||
throw new AdminInputError("INVALID_WEBRTC_HOST", "WebRTC public host is invalid");
|
||||
}
|
||||
if (
|
||||
!Number.isInteger(input.webRtcUdpStart) || input.webRtcUdpStart < 1 || input.webRtcUdpStart > 65_535
|
||||
|| !Number.isInteger(input.webRtcUdpEnd) || input.webRtcUdpEnd < 1 || input.webRtcUdpEnd > 65_535
|
||||
|| input.webRtcUdpStart > input.webRtcUdpEnd
|
||||
|| input.webRtcUdpEnd - input.webRtcUdpStart + 1 > MAX_WEBRTC_UDP_PORTS
|
||||
) {
|
||||
throw new AdminInputError("INVALID_WEBRTC_PORTS", "WebRTC UDP port range is invalid");
|
||||
}
|
||||
|
||||
let encryptedPassword = current.tsPasswordEncrypted;
|
||||
const action = input.passwordAction ?? (input.serverPassword === undefined ? "keep" : "replace");
|
||||
@@ -264,6 +299,10 @@ export class AdminService {
|
||||
tsHost: target.host,
|
||||
tsPort: target.port,
|
||||
tsPasswordEncrypted: encryptedPassword,
|
||||
webRtcEnabled: input.webRtcEnabled,
|
||||
webRtcPublicHost,
|
||||
webRtcUdpStart: input.webRtcUdpStart,
|
||||
webRtcUdpEnd: input.webRtcUdpEnd,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -292,6 +331,10 @@ export class AdminService {
|
||||
tsHost: settings.tsHost,
|
||||
tsPort: settings.tsPort,
|
||||
tsPasswordEncrypted: settings.tsPasswordEncrypted,
|
||||
webRtcEnabled: settings.webRtcEnabled,
|
||||
webRtcPublicHost: settings.webRtcPublicHost,
|
||||
webRtcUdpStart: settings.webRtcUdpStart,
|
||||
webRtcUdpEnd: settings.webRtcUdpEnd,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -307,6 +350,10 @@ export class AdminService {
|
||||
tsHost: legacy.tsHost,
|
||||
tsPort: legacy.tsPort,
|
||||
tsPasswordEncrypted: legacy.tsServerPassword ? encryptSecret(legacy.tsServerPassword, this.masterSecret) : null,
|
||||
webRtcEnabled: current.webRtcEnabled,
|
||||
webRtcPublicHost: current.webRtcPublicHost,
|
||||
webRtcUdpStart: current.webRtcUdpStart,
|
||||
webRtcUdpEnd: current.webRtcUdpEnd,
|
||||
}, "LEGACY_CONFIG_IMPORTED");
|
||||
this.database.setMeta("legacy_config_imported", "1");
|
||||
this.database.setMeta("legacy_import_notice_pending", "1");
|
||||
|
||||
Reference in new issue
Block a user