mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 12:02:50 +08:00
feat: include relay route in connection records
This commit is contained in:
1 parent
69043748a1
commit
defbb766e4
3 files changed
+43
-7
No files matched your search
@@ -12,6 +12,8 @@ export interface AdminConnectionRecord {
|
||||
nickname: string;
|
||||
clientIp: string;
|
||||
target: string;
|
||||
relayName: string | null;
|
||||
relayTarget: string | null;
|
||||
startedAt: string;
|
||||
connectedAt: string | null;
|
||||
disconnectedAt: string | null;
|
||||
@@ -431,7 +433,7 @@ function readRecentLogs(logFile: string | undefined, limit: number): AdminLogEnt
|
||||
try {
|
||||
const raw = JSON.parse(line) as Record<string, unknown>;
|
||||
const context: Record<string, string | number | boolean> = {};
|
||||
for (const key of ["component", "entryId", "code", "reason", "attempt", "target", "nickname", "clientIp", "channel", "reconnect", "port"]) {
|
||||
for (const key of ["component", "entryId", "code", "reason", "attempt", "target", "nickname", "clientIp", "relayName", "relayTarget", "channel", "reconnect", "port"]) {
|
||||
const value = raw[key];
|
||||
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") context[key] = value;
|
||||
}
|
||||
@@ -463,6 +465,8 @@ export function readConnectionHistory(logFile: string | undefined, limit: number
|
||||
nickname: string;
|
||||
clientIp: string;
|
||||
target: string;
|
||||
relayName: string;
|
||||
relayTarget: string;
|
||||
startedAt: string | null;
|
||||
connectedAt: string | null;
|
||||
disconnectedAt: string | null;
|
||||
@@ -478,6 +482,8 @@ export function readConnectionHistory(logFile: string | undefined, limit: number
|
||||
nickname: "",
|
||||
clientIp: "",
|
||||
target: "",
|
||||
relayName: "",
|
||||
relayTarget: "",
|
||||
startedAt: null,
|
||||
connectedAt: null,
|
||||
disconnectedAt: null,
|
||||
@@ -488,9 +494,13 @@ export function readConnectionHistory(logFile: string | undefined, limit: number
|
||||
const nickname = typeof log.raw.nickname === "string" ? log.raw.nickname : "";
|
||||
const clientIp = typeof log.raw.clientIp === "string" ? log.raw.clientIp : "";
|
||||
const target = typeof log.raw.target === "string" ? log.raw.target : "";
|
||||
const relayName = typeof log.raw.relayName === "string" ? log.raw.relayName : "";
|
||||
const relayTarget = typeof log.raw.relayTarget === "string" ? log.raw.relayTarget : "";
|
||||
if (nickname) current.nickname = nickname;
|
||||
if (clientIp) current.clientIp = clientIp;
|
||||
if (target) current.target = target;
|
||||
if (relayName) current.relayName = relayName;
|
||||
if (relayTarget) current.relayTarget = relayTarget;
|
||||
if (log.message === "WebClient connecting") {
|
||||
current.startedAt ??= log.timestamp;
|
||||
current.status = "connecting";
|
||||
@@ -528,6 +538,8 @@ export function readConnectionHistory(logFile: string | undefined, limit: number
|
||||
nickname: record.nickname || "—",
|
||||
clientIp: record.clientIp || "—",
|
||||
target: record.target || "—",
|
||||
relayName: record.relayName || null,
|
||||
relayTarget: record.relayTarget || null,
|
||||
startedAt: record.startedAt,
|
||||
connectedAt: record.connectedAt,
|
||||
disconnectedAt: record.disconnectedAt,
|
||||
|
||||
@@ -125,6 +125,7 @@ interface WebClientEntry {
|
||||
rememberIdentity: boolean;
|
||||
clientIp: string;
|
||||
target: TeamSpeakTarget;
|
||||
accelerationRelay?: { name: string; target: string };
|
||||
acceleration?: AccelerationRelayOptions;
|
||||
identityLeaseKey?: string;
|
||||
webrtcPublicHost?: string;
|
||||
@@ -206,7 +207,14 @@ export class VoiceBridge {
|
||||
return;
|
||||
}
|
||||
|
||||
this.logger.info({ entryId, nickname, clientIp, channel: channelName, target: formatTeamSpeakTarget(target) }, "WebClient connecting");
|
||||
this.logger.info({
|
||||
entryId,
|
||||
nickname,
|
||||
clientIp,
|
||||
channel: channelName,
|
||||
target: formatTeamSpeakTarget(target),
|
||||
...(acceleration ? { relayName: acceleration.name, relayTarget: formatTeamSpeakTarget({ host: acceleration.relayHost, port: acceleration.relayPort }) } : {}),
|
||||
}, "WebClient connecting");
|
||||
let tsClient: TSClient;
|
||||
try {
|
||||
tsClient = new TSClient({ target, nickname, serverPassword, defaultChannel: channelName, identity, ...(acceleration ? { acceleration } : {}) }, this.logger);
|
||||
@@ -226,6 +234,7 @@ export class VoiceBridge {
|
||||
rememberIdentity: connection.rememberIdentity === true,
|
||||
clientIp,
|
||||
target,
|
||||
...(acceleration ? { accelerationRelay: { name: acceleration.name, target: formatTeamSpeakTarget({ host: acceleration.relayHost, port: acceleration.relayPort }) } } : {}),
|
||||
...(acceleration ? { acceleration } : {}),
|
||||
...(identityLeaseKey ? { identityLeaseKey } : {}),
|
||||
...(webrtcPublicHost ? { webrtcPublicHost } : {}),
|
||||
@@ -325,7 +334,13 @@ export class VoiceBridge {
|
||||
reconnectStartedAt = 0;
|
||||
if (!wasReconnecting) {
|
||||
entry!.eventLog.push({ id: `event-${Date.now().toString(36)}-connected`, kind: "connection", message: "已连接到服务器", timestamp: Date.now() });
|
||||
this.logger.info({ entryId: entry!.id, nickname: entry!.nickname, clientIp: entry!.clientIp, target: formatTeamSpeakTarget(entry!.target) }, "Web client connected to TeamSpeak");
|
||||
this.logger.info({
|
||||
entryId: entry!.id,
|
||||
nickname: entry!.nickname,
|
||||
clientIp: entry!.clientIp,
|
||||
target: formatTeamSpeakTarget(entry!.target),
|
||||
...(entry!.accelerationRelay ? { relayName: entry!.accelerationRelay.name, relayTarget: entry!.accelerationRelay.target } : {}),
|
||||
}, "Web client connected to TeamSpeak");
|
||||
}
|
||||
session.transition("connected");
|
||||
sendJson({
|
||||
@@ -765,6 +780,7 @@ export class VoiceBridge {
|
||||
nickname: entry.nickname,
|
||||
clientIp: entry.clientIp,
|
||||
target: formatTeamSpeakTarget(entry.target),
|
||||
...(entry.accelerationRelay ? { relayName: entry.accelerationRelay.name, relayTarget: entry.accelerationRelay.target } : {}),
|
||||
reason,
|
||||
...(entry.connectionFailureCode ? { failureCode: entry.connectionFailureCode } : {}),
|
||||
durationSeconds: Math.max(0, Math.floor((Date.now() - entry.session.createdAt) / 1000)),
|
||||
@@ -799,13 +815,13 @@ export class VoiceBridge {
|
||||
return typeof configured === "function" ? configured() : configured;
|
||||
}
|
||||
|
||||
private getAccelerationOptions(relayId = ""): AccelerationRelayOptions | undefined {
|
||||
private getAccelerationOptions(relayId = ""): ConfiguredAccelerationRelay | undefined {
|
||||
const configured = this.options.acceleration;
|
||||
const relays = typeof configured === "function" ? configured() : configured;
|
||||
if (!relays?.length) return undefined;
|
||||
const selected = relayId ? relays.find((relay) => relay.id === relayId) : relays[0];
|
||||
if (!selected) return undefined;
|
||||
return { relayHost: selected.relayHost, relayPort: selected.relayPort, token: selected.token };
|
||||
return selected;
|
||||
}
|
||||
|
||||
private async handleWebRtcOffer(
|
||||
|
||||
@@ -107,7 +107,7 @@ const overview = reactive({ gateway: { version: "", uptimeSeconds: 0 }, teamSpea
|
||||
interface AdminSession { id: string; nickname: string; target: string; state: string; createdAt: string; ageSeconds: number; tsClientId: number | null; channelId: string | null; memberCount: number }
|
||||
interface ManagedInvite { id: string; target: string; channel: string; expiresAt: string; maxUses: number; useCount: number; createdAt: string; revokedAt: string | null; status: "active" | "expired" | "exhausted" | "revoked" }
|
||||
interface AdminLog { timestamp: string | null; level: string; message: string; context: Record<string, string | number | boolean> }
|
||||
interface AdminConnectionRecord { id: string; nickname: string; clientIp: string; target: string; startedAt: string; connectedAt: string | null; disconnectedAt: string | null; durationSeconds: number | null; status: "active" | "connecting" | "disconnected" | "failed"; reason: string | null }
|
||||
interface AdminConnectionRecord { id: string; nickname: string; clientIp: string; target: string; relayName: string | null; relayTarget: string | null; startedAt: string; connectedAt: string | null; disconnectedAt: string | null; durationSeconds: number | null; status: "active" | "connecting" | "disconnected" | "failed"; reason: string | null }
|
||||
const operationsLoading = ref(false);
|
||||
const terminatingSession = ref("");
|
||||
const inviteForm = reactive({ channel: "", expiresInHours: 24, maxUses: 0 });
|
||||
@@ -298,6 +298,7 @@ const copy = {
|
||||
connectionHistory: "用户连接记录",
|
||||
connectionHistoryLead: "按用户合并连接、断开与持续时间。",
|
||||
connectionFromTo: "来源 {{ip}} → 目标 {{target}}",
|
||||
connectionViaRelay: "中继 {{relay}}",
|
||||
connectionActive: "连接中",
|
||||
connectionConnecting: "准备连接",
|
||||
connectionDisconnected: "已断开",
|
||||
@@ -496,6 +497,7 @@ const copy = {
|
||||
connectionHistory: "User connection records",
|
||||
connectionHistoryLead: "Connections, disconnects, and durations grouped by user.",
|
||||
connectionFromTo: "From {{ip}} To {{target}}",
|
||||
connectionViaRelay: "Via relay {{relay}}",
|
||||
connectionActive: "Connected",
|
||||
connectionConnecting: "Connecting",
|
||||
connectionDisconnected: "Disconnected",
|
||||
@@ -654,6 +656,7 @@ const germanCopy = {
|
||||
logViewer: "Laufzeitprotokoll",
|
||||
connectionHistory: "Verbindungsaufzeichnungen",
|
||||
connectionFromTo: "Von {{ip}} zu {{target}}",
|
||||
connectionViaRelay: "Über Relay {{relay}}",
|
||||
connectionActive: "Verbunden",
|
||||
connectionConnecting: "Verbindung wird hergestellt",
|
||||
connectionDisconnected: "Getrennt",
|
||||
@@ -735,7 +738,12 @@ function formatDate(value: string | null) { return value ? new Intl.DateTimeForm
|
||||
function formatUptime(seconds: number) { const hours = Math.floor(seconds / 3600); const minutes = Math.floor((seconds % 3600) / 60); return language.value === "zh" ? `已运行 ${hours} 小时 ${minutes} 分钟` : language.value === "de" ? `${hours} Std. ${minutes} Min. aktiv` : `Up ${hours}h ${minutes}m`; }
|
||||
function formatAge(seconds: number | null) { if (seconds == null) return "—"; if (seconds < 60) return language.value === "zh" ? `${seconds} 秒` : language.value === "de" ? `${seconds} Sek.` : `${seconds}s`; const minutes = Math.floor(seconds / 60); if (minutes < 60) return language.value === "zh" ? `${minutes} 分钟` : language.value === "de" ? `${minutes} Min.` : `${minutes}m`; const hours = Math.floor(minutes / 60); return language.value === "zh" ? `${hours} 小时 ${minutes % 60} 分钟` : language.value === "de" ? `${hours} Std. ${minutes % 60} Min.` : `${hours}h ${minutes % 60}m`; }
|
||||
function connectionStatusLabel(status: AdminConnectionRecord["status"]) { const names: Record<AdminConnectionRecord["status"], keyof typeof copy.zh> = { active: "connectionActive", connecting: "connectionConnecting", disconnected: "connectionDisconnected", failed: "connectionFailed" }; return tr(names[status]); }
|
||||
function connectionRoute(record: AdminConnectionRecord) { return tr("connectionFromTo", { ip: record.clientIp || "—", target: record.target || "—" }); }
|
||||
function connectionRoute(record: AdminConnectionRecord) {
|
||||
const route = tr("connectionFromTo", { ip: record.clientIp || "—", target: record.target || "—" });
|
||||
if (!record.relayName && !record.relayTarget) return route;
|
||||
const relay = [record.relayName, record.relayTarget].filter(Boolean).join(" · ") || "—";
|
||||
return `${route} · ${tr("connectionViaRelay", { relay })}`;
|
||||
}
|
||||
function sessionStateLabel(state: string) { const names: Record<string, { zh: string; en: string; de: string }> = { connecting: { zh: "连接中", en: "Connecting", de: "Verbindung wird hergestellt" }, authenticating: { zh: "认证中", en: "Authenticating", de: "Authentifizierung" }, syncing: { zh: "同步中", en: "Syncing", de: "Synchronisierung" }, connected: { zh: "已连接", en: "Connected", de: "Verbunden" }, interrupted: { zh: "已中断", en: "Interrupted", de: "Unterbrochen" }, reconnecting: { zh: "重连中", en: "Reconnecting", de: "Wiederverbindung" }, disconnecting: { zh: "断开中", en: "Disconnecting", de: "Wird getrennt" }, failed: { zh: "失败", en: "Failed", de: "Fehlgeschlagen" }, idle: { zh: "空闲", en: "Idle", de: "Inaktiv" } }; return names[state]?.[language.value] ?? state; }
|
||||
function inviteStatusLabel(status: ManagedInvite["status"]) { const names: Record<ManagedInvite["status"], keyof typeof copy.zh> = { active: "active", expired: "expired", exhausted: "exhausted", revoked: "revoked" }; return tr(names[status]); }
|
||||
function formatContext(context: Record<string, string | number | boolean>) { return Object.entries(context).map(([key, value]) => `${key}=${value}`).join(" · "); }
|
||||
|
||||
Reference in new issue
Block a user