mirror of
https://github.com/Moepchi/webspeak3.git
synced 2026-12-01 00:42:49 +08:00
Add client and server connection-info windows
Sends raw getconnectioninfo/serverrequestconnectioninfo commands and reads the reply out of tsclientlib's bookkeeping state (it already tracks ping, packet loss, bytes/packets sent+received internally - just needed to be requested and surfaced). Wired into the client context menu (any client), the Selbst menu (self), and a new link in the server info panel. Uses send_with_result() so a permission-denied rejection surfaces as a visible error instead of silently doing nothing; the dialogs also fall back to a "no response" message after 6s in case the server declines without any reply at all (observed against a real server where a guest lacked b_virtualserver_connectioninfo_view). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a300daedeb
commit
74f688aba8
7 files changed
+565
-3
No files matched your search
@@ -440,6 +440,42 @@
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.ts-info-connection-link {
|
||||
margin-top: 0.5rem;
|
||||
background: none;
|
||||
border: none;
|
||||
padding: 0;
|
||||
color: var(--accent);
|
||||
font-size: 12px;
|
||||
cursor: pointer;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.ts-info-connection-link:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.ts-connection-info-dialog {
|
||||
width: 380px;
|
||||
}
|
||||
|
||||
.ts-connection-info-loading {
|
||||
padding: 1rem;
|
||||
text-align: center;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.ts-connection-info-grid {
|
||||
display: grid;
|
||||
grid-template-columns: auto 1fr;
|
||||
gap: 0.35rem 0.75rem;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.ts-connection-info-grid span:nth-child(odd) {
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.ts-row-selected {
|
||||
background: var(--row-hover);
|
||||
outline: 1px solid var(--border);
|
||||
|
||||
+260
-1
@@ -282,6 +282,50 @@ interface ClientInfo {
|
||||
uid: string;
|
||||
}
|
||||
|
||||
interface ClientConnectionInfoData {
|
||||
clientId: number;
|
||||
pingMs: number | null;
|
||||
connectedSecs: number | null;
|
||||
ip: string | null;
|
||||
packetsSent: number;
|
||||
bytesSent: number;
|
||||
packetsReceived: number;
|
||||
bytesReceived: number;
|
||||
packetLossPercent: number;
|
||||
}
|
||||
|
||||
interface ServerConnectionInfoData {
|
||||
pingMs: number;
|
||||
connectedSecs: number;
|
||||
packetLossPercent: number;
|
||||
packetsSentTotal: number;
|
||||
bytesSentTotal: number;
|
||||
packetsReceivedTotal: number;
|
||||
bytesReceivedTotal: number;
|
||||
bandwidthSentLastSecond: number;
|
||||
bandwidthReceivedLastSecond: number;
|
||||
}
|
||||
|
||||
function formatBytes(bytes: number): string {
|
||||
if (bytes < 1024) return `${bytes} B`;
|
||||
const units = ["KB", "MB", "GB", "TB"];
|
||||
let value = bytes / 1024;
|
||||
let unitIndex = 0;
|
||||
while (value >= 1024 && unitIndex < units.length - 1) {
|
||||
value /= 1024;
|
||||
unitIndex++;
|
||||
}
|
||||
return `${value.toFixed(1)} ${units[unitIndex]}`;
|
||||
}
|
||||
|
||||
function formatDurationSecs(totalSeconds: number): string {
|
||||
const hours = Math.floor(totalSeconds / 3600);
|
||||
const minutes = Math.floor((totalSeconds % 3600) / 60);
|
||||
const seconds = Math.floor(totalSeconds % 60);
|
||||
const pad = (n: number) => String(n).padStart(2, "0");
|
||||
return hours > 0 ? `${hours}:${pad(minutes)}:${pad(seconds)}` : `${minutes}:${pad(seconds)}`;
|
||||
}
|
||||
|
||||
/** Converts an ISO 3166-1 alpha-2 country code (e.g. "DE") to its flag emoji
|
||||
* via Unicode regional indicator symbols. Returns null for codes the server
|
||||
* doesn't report (empty string - common when geo-IP isn't configured). */
|
||||
@@ -447,6 +491,7 @@ function InfoPanel({
|
||||
totalClientCount,
|
||||
channels,
|
||||
clients,
|
||||
onShowServerConnectionInfo,
|
||||
}: {
|
||||
selected: SelectedItem | null;
|
||||
host: string;
|
||||
@@ -457,6 +502,7 @@ function InfoPanel({
|
||||
totalClientCount: number;
|
||||
channels: ChannelInfo[];
|
||||
clients: ClientInfo[];
|
||||
onShowServerConnectionInfo: () => void;
|
||||
}) {
|
||||
const t = useT();
|
||||
if (!selected || selected.type === "server") {
|
||||
@@ -485,6 +531,9 @@ function InfoPanel({
|
||||
<div className="ts-info-row">
|
||||
<span>{t("info.currentChannels")}</span> <span>{channels.length}</span>
|
||||
</div>
|
||||
<button className="ts-info-connection-link" onClick={onShowServerConnectionInfo}>
|
||||
🔌 {t("connectionInfo.serverTitle")}
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1271,6 +1320,139 @@ function WhisperListsDialog({
|
||||
);
|
||||
}
|
||||
|
||||
function ClientConnectionInfoDialog({
|
||||
clientName,
|
||||
info,
|
||||
onClose,
|
||||
}: {
|
||||
clientName: string;
|
||||
info: ClientConnectionInfoData | null;
|
||||
onClose: () => void;
|
||||
}) {
|
||||
const t = useT();
|
||||
const backdrop = useBackdropDismiss(onClose);
|
||||
// The server may silently decline (e.g. missing permission to view another
|
||||
// client's connection info) without ever replying - fall back to an error
|
||||
// instead of spinning forever.
|
||||
const [timedOut, setTimedOut] = useState(false);
|
||||
useEffect(() => {
|
||||
setTimedOut(false);
|
||||
if (info) return;
|
||||
const id = window.setTimeout(() => setTimedOut(true), 6000);
|
||||
return () => window.clearTimeout(id);
|
||||
}, [info, clientName]);
|
||||
|
||||
return (
|
||||
<div className="ts-dialog-backdrop" {...backdrop}>
|
||||
<div className="ts-dialog ts-connection-info-dialog" onClick={(e) => e.stopPropagation()}>
|
||||
<div className="ts-dialog-titlebar">
|
||||
<span>{t("connectionInfo.clientTitle", { name: clientName })}</span>
|
||||
<button onClick={onClose} title={t("dialog.close")}>
|
||||
✕
|
||||
</button>
|
||||
</div>
|
||||
<div className="ts-dialog-body">
|
||||
{!info ? (
|
||||
<div className="ts-connection-info-loading">
|
||||
{timedOut ? t("connectionInfo.unavailable") : t("connectionInfo.loading")}
|
||||
</div>
|
||||
) : (
|
||||
<div className="ts-connection-info-grid">
|
||||
<span>{t("connectionInfo.ping")}</span>
|
||||
<span>{info.pingMs != null ? `${info.pingMs.toFixed(1)} ms` : "-"}</span>
|
||||
<span>{t("connectionInfo.connectedSince")}</span>
|
||||
<span>{info.connectedSecs != null ? formatDurationSecs(info.connectedSecs) : "-"}</span>
|
||||
<span>{t("connectionInfo.ip")}</span>
|
||||
<span>{info.ip ?? "-"}</span>
|
||||
<span>{t("connectionInfo.packetLoss")}</span>
|
||||
<span>{info.packetLossPercent.toFixed(2)}%</span>
|
||||
<span>{t("connectionInfo.packetsSent")}</span>
|
||||
<span>{info.packetsSent.toLocaleString()}</span>
|
||||
<span>{t("connectionInfo.packetsReceived")}</span>
|
||||
<span>{info.packetsReceived.toLocaleString()}</span>
|
||||
<span>{t("connectionInfo.bytesSent")}</span>
|
||||
<span>{formatBytes(info.bytesSent)}</span>
|
||||
<span>{t("connectionInfo.bytesReceived")}</span>
|
||||
<span>{formatBytes(info.bytesReceived)}</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="ts-dialog-buttons">
|
||||
<div className="ts-dialog-buttons-right">
|
||||
<button onClick={onClose}>{t("dialog.close")}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ServerConnectionInfoDialog({
|
||||
info,
|
||||
onClose,
|
||||
}: {
|
||||
info: ServerConnectionInfoData | null;
|
||||
onClose: () => void;
|
||||
}) {
|
||||
const t = useT();
|
||||
const backdrop = useBackdropDismiss(onClose);
|
||||
// The server may silently decline (e.g. missing b_virtualserver_connectioninfo_view
|
||||
// permission) without ever replying - fall back to an error instead of spinning forever.
|
||||
const [timedOut, setTimedOut] = useState(false);
|
||||
useEffect(() => {
|
||||
setTimedOut(false);
|
||||
if (info) return;
|
||||
const id = window.setTimeout(() => setTimedOut(true), 6000);
|
||||
return () => window.clearTimeout(id);
|
||||
}, [info]);
|
||||
|
||||
return (
|
||||
<div className="ts-dialog-backdrop" {...backdrop}>
|
||||
<div className="ts-dialog ts-connection-info-dialog" onClick={(e) => e.stopPropagation()}>
|
||||
<div className="ts-dialog-titlebar">
|
||||
<span>{t("connectionInfo.serverTitle")}</span>
|
||||
<button onClick={onClose} title={t("dialog.close")}>
|
||||
✕
|
||||
</button>
|
||||
</div>
|
||||
<div className="ts-dialog-body">
|
||||
{!info ? (
|
||||
<div className="ts-connection-info-loading">
|
||||
{timedOut ? t("connectionInfo.unavailable") : t("connectionInfo.loading")}
|
||||
</div>
|
||||
) : (
|
||||
<div className="ts-connection-info-grid">
|
||||
<span>{t("connectionInfo.ping")}</span>
|
||||
<span>{info.pingMs.toFixed(1)} ms</span>
|
||||
<span>{t("connectionInfo.connectedSince")}</span>
|
||||
<span>{formatDurationSecs(info.connectedSecs)}</span>
|
||||
<span>{t("connectionInfo.packetLoss")}</span>
|
||||
<span>{info.packetLossPercent.toFixed(2)}%</span>
|
||||
<span>{t("connectionInfo.packetsSent")}</span>
|
||||
<span>{info.packetsSentTotal.toLocaleString()}</span>
|
||||
<span>{t("connectionInfo.packetsReceived")}</span>
|
||||
<span>{info.packetsReceivedTotal.toLocaleString()}</span>
|
||||
<span>{t("connectionInfo.bytesSent")}</span>
|
||||
<span>{formatBytes(info.bytesSentTotal)}</span>
|
||||
<span>{t("connectionInfo.bytesReceived")}</span>
|
||||
<span>{formatBytes(info.bytesReceivedTotal)}</span>
|
||||
<span>{t("connectionInfo.bandwidthSent")}</span>
|
||||
<span>{formatBytes(info.bandwidthSentLastSecond)}/s</span>
|
||||
<span>{t("connectionInfo.bandwidthReceived")}</span>
|
||||
<span>{formatBytes(info.bandwidthReceivedLastSecond)}/s</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="ts-dialog-buttons">
|
||||
<div className="ts-dialog-buttons-right">
|
||||
<button onClick={onClose}>{t("dialog.close")}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function IdentitiesDialog({
|
||||
identities,
|
||||
activeId,
|
||||
@@ -2265,6 +2447,12 @@ function AppInner() {
|
||||
localStorage.getItem(ACTIVE_IDENTITY_KEY)
|
||||
);
|
||||
const [identitiesOpen, setIdentitiesOpen] = useState(false);
|
||||
const [clientConnectionInfoTarget, setClientConnectionInfoTarget] = useState<{ id: number; name: string } | null>(
|
||||
null
|
||||
);
|
||||
const [clientConnectionInfo, setClientConnectionInfo] = useState<ClientConnectionInfoData | null>(null);
|
||||
const [serverConnectionInfoOpen, setServerConnectionInfoOpen] = useState(false);
|
||||
const [serverConnectionInfo, setServerConnectionInfo] = useState<ServerConnectionInfoData | null>(null);
|
||||
const [selfMenuOpen, setSelfMenuOpen] = useState(false);
|
||||
const selfMenuRef = useRef<HTMLDivElement | null>(null);
|
||||
const [changeNicknameOpen, setChangeNicknameOpen] = useState(false);
|
||||
@@ -2712,6 +2900,32 @@ function AppInner() {
|
||||
setConnectError(data.message);
|
||||
}
|
||||
break;
|
||||
case "clientConnectionInfo":
|
||||
setClientConnectionInfo({
|
||||
clientId: data.clientId,
|
||||
pingMs: data.pingMs,
|
||||
connectedSecs: data.connectedSecs,
|
||||
ip: data.ip,
|
||||
packetsSent: data.packetsSent,
|
||||
bytesSent: data.bytesSent,
|
||||
packetsReceived: data.packetsReceived,
|
||||
bytesReceived: data.bytesReceived,
|
||||
packetLossPercent: data.packetLossPercent,
|
||||
});
|
||||
break;
|
||||
case "serverConnectionInfo":
|
||||
setServerConnectionInfo({
|
||||
pingMs: data.pingMs,
|
||||
connectedSecs: data.connectedSecs,
|
||||
packetLossPercent: data.packetLossPercent,
|
||||
packetsSentTotal: data.packetsSentTotal,
|
||||
bytesSentTotal: data.bytesSentTotal,
|
||||
packetsReceivedTotal: data.packetsReceivedTotal,
|
||||
bytesReceivedTotal: data.bytesReceivedTotal,
|
||||
bandwidthSentLastSecond: data.bandwidthSentLastSecond,
|
||||
bandwidthReceivedLastSecond: data.bandwidthReceivedLastSecond,
|
||||
});
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -3270,6 +3484,18 @@ function AppInner() {
|
||||
});
|
||||
};
|
||||
|
||||
const handleShowClientConnectionInfo = (clientId: number, clientName: string) => {
|
||||
setClientConnectionInfoTarget({ id: clientId, name: clientName });
|
||||
setClientConnectionInfo(null);
|
||||
socketRef.current?.send(JSON.stringify({ type: "getClientConnectionInfo", clientId }));
|
||||
};
|
||||
|
||||
const handleShowServerConnectionInfo = () => {
|
||||
setServerConnectionInfoOpen(true);
|
||||
setServerConnectionInfo(null);
|
||||
socketRef.current?.send(JSON.stringify({ type: "getServerConnectionInfo" }));
|
||||
};
|
||||
|
||||
const handleClientContextMenu = (
|
||||
e: React.MouseEvent,
|
||||
clientId: number,
|
||||
@@ -3495,7 +3721,14 @@ function AppInner() {
|
||||
<span className="ts-menu-item-label">{t("menu.self.setPhoneticNickname")}</span>
|
||||
</button>
|
||||
<div className="ts-menu-separator" />
|
||||
<button className="ts-menu-item" disabled title={t("clientContext.notSupported")}>
|
||||
<button
|
||||
className="ts-menu-item"
|
||||
disabled={!ownClient}
|
||||
onClick={() => {
|
||||
if (ownClient) handleShowClientConnectionInfo(ownClient.id, ownClient.name);
|
||||
setSelfMenuOpen(false);
|
||||
}}
|
||||
>
|
||||
<span className="ts-menu-item-icon">ℹ️</span>
|
||||
<span className="ts-menu-item-label">{t("menu.self.connectionInfo")}</span>
|
||||
</button>
|
||||
@@ -3917,6 +4150,21 @@ function AppInner() {
|
||||
/>
|
||||
)}
|
||||
|
||||
{clientConnectionInfoTarget && (
|
||||
<ClientConnectionInfoDialog
|
||||
clientName={clientConnectionInfoTarget.name}
|
||||
info={clientConnectionInfo?.clientId === clientConnectionInfoTarget.id ? clientConnectionInfo : null}
|
||||
onClose={() => setClientConnectionInfoTarget(null)}
|
||||
/>
|
||||
)}
|
||||
|
||||
{serverConnectionInfoOpen && (
|
||||
<ServerConnectionInfoDialog
|
||||
info={serverConnectionInfo}
|
||||
onClose={() => setServerConnectionInfoOpen(false)}
|
||||
/>
|
||||
)}
|
||||
|
||||
{contactsOpen && (
|
||||
<ContactsDialog
|
||||
contacts={contacts}
|
||||
@@ -4086,6 +4334,16 @@ function AppInner() {
|
||||
<span className="ts-menu-item-icon">📋</span>
|
||||
<span className="ts-menu-item-label">{t("clientContext.copyName")}</span>
|
||||
</button>
|
||||
<button
|
||||
className="ts-menu-item"
|
||||
onClick={() => {
|
||||
handleShowClientConnectionInfo(clientContextMenu.clientId, clientContextMenu.clientName);
|
||||
setClientContextMenu(null);
|
||||
}}
|
||||
>
|
||||
<span className="ts-menu-item-icon">🔌</span>
|
||||
<span className="ts-menu-item-label">{t("clientContext.connectionInfo")}</span>
|
||||
</button>
|
||||
{!clientContextMenu.isSelf && (
|
||||
<button
|
||||
className="ts-menu-item"
|
||||
@@ -4177,6 +4435,7 @@ function AppInner() {
|
||||
totalClientCount={clients.length}
|
||||
channels={channels}
|
||||
clients={clients}
|
||||
onShowServerConnectionInfo={handleShowServerConnectionInfo}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -167,6 +167,40 @@ export class DemoSocket {
|
||||
);
|
||||
break;
|
||||
}
|
||||
case "getClientConnectionInfo": {
|
||||
this.after(400, () =>
|
||||
this.emit({
|
||||
type: "clientConnectionInfo",
|
||||
clientId: msg.clientId,
|
||||
pingMs: 12.4,
|
||||
connectedSecs: 217,
|
||||
ip: msg.clientId === SELF_ID ? "127.0.0.1" : null,
|
||||
packetsSent: 4213,
|
||||
bytesSent: 512_340,
|
||||
packetsReceived: 3987,
|
||||
bytesReceived: 498_120,
|
||||
packetLossPercent: 0,
|
||||
})
|
||||
);
|
||||
break;
|
||||
}
|
||||
case "getServerConnectionInfo": {
|
||||
this.after(400, () =>
|
||||
this.emit({
|
||||
type: "serverConnectionInfo",
|
||||
pingMs: 8.1,
|
||||
connectedSecs: 217,
|
||||
packetLossPercent: 0,
|
||||
packetsSentTotal: 21_004,
|
||||
bytesSentTotal: 2_411_000,
|
||||
packetsReceivedTotal: 19_872,
|
||||
bytesReceivedTotal: 2_198_500,
|
||||
bandwidthSentLastSecond: 4200,
|
||||
bandwidthReceivedLastSecond: 3900,
|
||||
})
|
||||
);
|
||||
break;
|
||||
}
|
||||
// "disconnect" is intentionally unhandled here: handleDisconnect() in
|
||||
// App.tsx always calls socket.close() right after sending it, and
|
||||
// close() already emits the "disconnected" event below.
|
||||
|
||||
@@ -128,6 +128,21 @@ const translations: Record<Lang, Record<string, string>> = {
|
||||
"identities.generated": "Erstellt",
|
||||
"identities.pending": "Wird bei der nächsten Verbindung erstellt",
|
||||
|
||||
"connectionInfo.clientTitle": "Verbindungsinformationen - {name}",
|
||||
"connectionInfo.serverTitle": "Serververbindungsinformationen",
|
||||
"connectionInfo.loading": "Wird geladen…",
|
||||
"connectionInfo.unavailable": "Keine Antwort vom Server (fehlende Berechtigung?).",
|
||||
"connectionInfo.ping": "Ping:",
|
||||
"connectionInfo.connectedSince": "Verbunden seit:",
|
||||
"connectionInfo.ip": "IP-Adresse:",
|
||||
"connectionInfo.packetLoss": "Paketverlust:",
|
||||
"connectionInfo.packetsSent": "Pakete gesendet:",
|
||||
"connectionInfo.packetsReceived": "Pakete empfangen:",
|
||||
"connectionInfo.bytesSent": "Daten gesendet:",
|
||||
"connectionInfo.bytesReceived": "Daten empfangen:",
|
||||
"connectionInfo.bandwidthSent": "Bandbreite gesendet:",
|
||||
"connectionInfo.bandwidthReceived": "Bandbreite empfangen:",
|
||||
|
||||
"menu.self.recordingProfile": "Aufnahmeprofil",
|
||||
"menu.self.playbackProfile": "Wiedergabeprofil",
|
||||
"menu.self.hotkeyProfile": "Hotkeyprofil",
|
||||
@@ -291,6 +306,7 @@ const translations: Record<Lang, Record<string, string>> = {
|
||||
"clientContext.privateChat": "Privater Chat",
|
||||
"clientContext.poke": "Anstupsen",
|
||||
"clientContext.copyName": "Namen kopieren",
|
||||
"clientContext.connectionInfo": "Verbindungsinformationen anzeigen",
|
||||
"clientContext.addWhisperTarget": "Als Whisper-Ziel hinzufügen",
|
||||
"clientContext.removeWhisperTarget": "Als Whisper-Ziel entfernen",
|
||||
"clientContext.assignChannelGroup": "Channel-Gruppe zuweisen",
|
||||
@@ -451,6 +467,21 @@ const translations: Record<Lang, Record<string, string>> = {
|
||||
"identities.generated": "Generated",
|
||||
"identities.pending": "Will be generated on next connection",
|
||||
|
||||
"connectionInfo.clientTitle": "Connection Info - {name}",
|
||||
"connectionInfo.serverTitle": "Server Connection Info",
|
||||
"connectionInfo.loading": "Loading…",
|
||||
"connectionInfo.unavailable": "No response from the server (missing permission?).",
|
||||
"connectionInfo.ping": "Ping:",
|
||||
"connectionInfo.connectedSince": "Connected since:",
|
||||
"connectionInfo.ip": "IP address:",
|
||||
"connectionInfo.packetLoss": "Packet loss:",
|
||||
"connectionInfo.packetsSent": "Packets sent:",
|
||||
"connectionInfo.packetsReceived": "Packets received:",
|
||||
"connectionInfo.bytesSent": "Data sent:",
|
||||
"connectionInfo.bytesReceived": "Data received:",
|
||||
"connectionInfo.bandwidthSent": "Bandwidth sent:",
|
||||
"connectionInfo.bandwidthReceived": "Bandwidth received:",
|
||||
|
||||
"menu.self.recordingProfile": "Recording Profile",
|
||||
"menu.self.playbackProfile": "Playback Profile",
|
||||
"menu.self.hotkeyProfile": "Hotkey Profile",
|
||||
@@ -614,6 +645,7 @@ const translations: Record<Lang, Record<string, string>> = {
|
||||
"clientContext.privateChat": "Private chat",
|
||||
"clientContext.poke": "Poke",
|
||||
"clientContext.copyName": "Copy name",
|
||||
"clientContext.connectionInfo": "Show connection info",
|
||||
"clientContext.addWhisperTarget": "Add as whisper target",
|
||||
"clientContext.removeWhisperTarget": "Remove as whisper target",
|
||||
"clientContext.assignChannelGroup": "Assign channel group",
|
||||
|
||||
Reference in new issue
Block a user