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
@@ -146,6 +146,34 @@ enum Event {
|
|||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
entry: ServerLogEntry,
|
entry: ServerLogEntry,
|
||||||
},
|
},
|
||||||
|
/// Reply to a "clientconninfo <id>" request - live stats for one client's
|
||||||
|
/// connection (ping, packet loss, bytes/packets sent+received).
|
||||||
|
#[serde(rename = "clientConnectionInfo")]
|
||||||
|
ClientConnectionInfo {
|
||||||
|
client_id: u16,
|
||||||
|
ping_ms: Option<f64>,
|
||||||
|
connected_secs: Option<i64>,
|
||||||
|
ip: Option<String>,
|
||||||
|
packets_sent: u64,
|
||||||
|
bytes_sent: u64,
|
||||||
|
packets_received: u64,
|
||||||
|
bytes_received: u64,
|
||||||
|
packet_loss_percent: f32,
|
||||||
|
},
|
||||||
|
/// Reply to a "serverconninfo" request - aggregate connection stats for
|
||||||
|
/// the whole server-side link.
|
||||||
|
#[serde(rename = "serverConnectionInfo")]
|
||||||
|
ServerConnectionInfo {
|
||||||
|
ping_ms: f64,
|
||||||
|
connected_secs: i64,
|
||||||
|
packet_loss_percent: f32,
|
||||||
|
packets_sent_total: u64,
|
||||||
|
bytes_sent_total: u64,
|
||||||
|
packets_received_total: u64,
|
||||||
|
bytes_received_total: u64,
|
||||||
|
bandwidth_sent_last_second: u64,
|
||||||
|
bandwidth_received_last_second: u64,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
fn emit(event: &Event) {
|
fn emit(event: &Event) {
|
||||||
@@ -452,6 +480,11 @@ async fn run(args: Args) -> Result<()> {
|
|||||||
// stdin command, cleared via "unwhisper".
|
// stdin command, cleared via "unwhisper".
|
||||||
let mut whisper_channels: Vec<u64> = Vec::new();
|
let mut whisper_channels: Vec<u64> = Vec::new();
|
||||||
let mut whisper_clients: Vec<u16> = Vec::new();
|
let mut whisper_clients: Vec<u16> = Vec::new();
|
||||||
|
// Set by "clientconninfo"/"serverconninfo" while waiting for the server's
|
||||||
|
// reply to land in book state (it arrives async as a later BookEvents
|
||||||
|
// batch, not as a direct command result) - checked and emitted below.
|
||||||
|
let mut pending_client_conninfo: Option<ClientId> = None;
|
||||||
|
let mut pending_server_conninfo = false;
|
||||||
|
|
||||||
enum LoopOutcome {
|
enum LoopOutcome {
|
||||||
StdinLine(std::io::Result<Option<String>>),
|
StdinLine(std::io::Result<Option<String>>),
|
||||||
@@ -605,6 +638,39 @@ async fn run(args: Args) -> Result<()> {
|
|||||||
} else if l == "unwhisper" {
|
} else if l == "unwhisper" {
|
||||||
whisper_channels.clear();
|
whisper_channels.clear();
|
||||||
whisper_clients.clear();
|
whisper_clients.clear();
|
||||||
|
} else if let Some(rest) = l.strip_prefix("clientconninfo ") {
|
||||||
|
match rest.trim().parse::<u16>() {
|
||||||
|
Ok(id) => {
|
||||||
|
let client_id = ClientId(id);
|
||||||
|
let part = con.get_state()?.clients.get(&client_id).map(|c| c.connection_info());
|
||||||
|
match part {
|
||||||
|
// send_with_result (rather than send) so a missing-permission
|
||||||
|
// rejection (e.g. viewing another client's connection info
|
||||||
|
// without b_client_view_connection_info) surfaces as a visible
|
||||||
|
// error instead of leaving the dialog stuck loading forever.
|
||||||
|
Some(part) => match part.send_with_result(&mut con) {
|
||||||
|
Ok(handle) => {
|
||||||
|
pending_client_conninfo = Some(client_id);
|
||||||
|
pending_messages.insert(handle, "Connection info".into());
|
||||||
|
}
|
||||||
|
Err(e) => emit(&Event::Error { message: e.to_string() }),
|
||||||
|
},
|
||||||
|
None => {
|
||||||
|
emit(&Event::Error { message: format!("Unknown client id: {id}") })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(_) => emit(&Event::Error { message: format!("Invalid client id: {rest}") }),
|
||||||
|
}
|
||||||
|
} else if l == "serverconninfo" {
|
||||||
|
let part = con.get_state()?.server.connection_info();
|
||||||
|
match part.send_with_result(&mut con) {
|
||||||
|
Ok(handle) => {
|
||||||
|
pending_server_conninfo = true;
|
||||||
|
pending_messages.insert(handle, "Server connection info".into());
|
||||||
|
}
|
||||||
|
Err(e) => emit(&Event::Error { message: e.to_string() }),
|
||||||
|
}
|
||||||
} else if let Some(b64) = l.strip_prefix("audio ") {
|
} else if let Some(b64) = l.strip_prefix("audio ") {
|
||||||
match base64::engine::general_purpose::STANDARD.decode(b64.trim()) {
|
match base64::engine::general_purpose::STANDARD.decode(b64.trim()) {
|
||||||
Ok(bytes) => {
|
Ok(bytes) => {
|
||||||
@@ -704,6 +770,51 @@ async fn run(args: Args) -> Result<()> {
|
|||||||
log_book_event(con.get_state()?, event);
|
log_book_event(con.get_state()?, event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if let Some(client_id) = pending_client_conninfo {
|
||||||
|
match con.get_state()?.clients.get(&client_id) {
|
||||||
|
Some(client) => {
|
||||||
|
if let Some(data) = &client.connection_data {
|
||||||
|
emit(&Event::ClientConnectionInfo {
|
||||||
|
client_id: client_id.0,
|
||||||
|
ping_ms: data.ping.map(|d| d.as_seconds_f64() * 1000.0),
|
||||||
|
connected_secs: data.connected_time.map(|d| d.whole_seconds()),
|
||||||
|
ip: data.client_address.map(|a| a.ip().to_string()),
|
||||||
|
packets_sent: data.packets_sent_speech.unwrap_or(0)
|
||||||
|
+ data.packets_sent_keepalive.unwrap_or(0)
|
||||||
|
+ data.packets_sent_control.unwrap_or(0),
|
||||||
|
bytes_sent: data.bytes_sent_speech.unwrap_or(0)
|
||||||
|
+ data.bytes_sent_keepalive.unwrap_or(0)
|
||||||
|
+ data.bytes_sent_control.unwrap_or(0),
|
||||||
|
packets_received: data.packets_received_speech.unwrap_or(0)
|
||||||
|
+ data.packets_received_keepalive.unwrap_or(0)
|
||||||
|
+ data.packets_received_control.unwrap_or(0),
|
||||||
|
bytes_received: data.bytes_received_speech.unwrap_or(0)
|
||||||
|
+ data.bytes_received_keepalive.unwrap_or(0)
|
||||||
|
+ data.bytes_received_control.unwrap_or(0),
|
||||||
|
packet_loss_percent: data.client_to_server_packetloss_total,
|
||||||
|
});
|
||||||
|
pending_client_conninfo = None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => pending_client_conninfo = None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if pending_server_conninfo {
|
||||||
|
if let Some(data) = &con.get_state()?.server.connection_data {
|
||||||
|
emit(&Event::ServerConnectionInfo {
|
||||||
|
ping_ms: data.ping.as_seconds_f64() * 1000.0,
|
||||||
|
connected_secs: data.connected_time_total.whole_seconds(),
|
||||||
|
packet_loss_percent: data.packetloss_total,
|
||||||
|
packets_sent_total: data.packets_sent_total,
|
||||||
|
bytes_sent_total: data.bytes_sent_total,
|
||||||
|
packets_received_total: data.packets_received_total,
|
||||||
|
bytes_received_total: data.bytes_received_total,
|
||||||
|
bandwidth_sent_last_second: data.bandwidth_sent_last_second_total,
|
||||||
|
bandwidth_received_last_second: data.bandwidth_received_last_second_total,
|
||||||
|
});
|
||||||
|
pending_server_conninfo = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
emit(&snapshot(con.get_state()?));
|
emit(&snapshot(con.get_state()?));
|
||||||
}
|
}
|
||||||
Some(Ok(StreamItem::Audio(packet))) => {
|
Some(Ok(StreamItem::Audio(packet))) => {
|
||||||
|
|||||||
@@ -122,6 +122,14 @@ wss.on("connection", (socket: WebSocket) => {
|
|||||||
await connection?.setWhisperTargets(msg.channelIds ?? [], msg.clientIds ?? []);
|
await connection?.setWhisperTargets(msg.channelIds ?? [], msg.clientIds ?? []);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case "getClientConnectionInfo": {
|
||||||
|
await connection?.getClientConnectionInfo(msg.clientId);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "getServerConnectionInfo": {
|
||||||
|
await connection?.getServerConnectionInfo();
|
||||||
|
break;
|
||||||
|
}
|
||||||
case "disconnect": {
|
case "disconnect": {
|
||||||
await connection?.disconnect(msg.message ?? "");
|
await connection?.disconnect(msg.message ?? "");
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -66,7 +66,31 @@ export type Ts3ConnectionEvent =
|
|||||||
| { type: "talkers"; clients: number[] }
|
| { type: "talkers"; clients: number[] }
|
||||||
| { type: "disconnected"; reason: string }
|
| { type: "disconnected"; reason: string }
|
||||||
| { type: "error"; message: string }
|
| { type: "error"; message: string }
|
||||||
| ({ type: "serverLog" } & ServerLogEntry);
|
| ({ type: "serverLog" } & ServerLogEntry)
|
||||||
|
| {
|
||||||
|
type: "clientConnectionInfo";
|
||||||
|
clientId: number;
|
||||||
|
pingMs: number | null;
|
||||||
|
connectedSecs: number | null;
|
||||||
|
ip: string | null;
|
||||||
|
packetsSent: number;
|
||||||
|
bytesSent: number;
|
||||||
|
packetsReceived: number;
|
||||||
|
bytesReceived: number;
|
||||||
|
packetLossPercent: number;
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
type: "serverConnectionInfo";
|
||||||
|
pingMs: number;
|
||||||
|
connectedSecs: number;
|
||||||
|
packetLossPercent: number;
|
||||||
|
packetsSentTotal: number;
|
||||||
|
bytesSentTotal: number;
|
||||||
|
packetsReceivedTotal: number;
|
||||||
|
bytesReceivedTotal: number;
|
||||||
|
bandwidthSentLastSecond: number;
|
||||||
|
bandwidthReceivedLastSecond: number;
|
||||||
|
};
|
||||||
|
|
||||||
export interface Ts3ConnectOptions {
|
export interface Ts3ConnectOptions {
|
||||||
host: string;
|
host: string;
|
||||||
@@ -157,7 +181,31 @@ export class Ts3Connection {
|
|||||||
| { type: "talkers"; clients: number[] }
|
| { type: "talkers"; clients: number[] }
|
||||||
| { type: "disconnected"; reason: string }
|
| { type: "disconnected"; reason: string }
|
||||||
| { type: "error"; message: string }
|
| { type: "error"; message: string }
|
||||||
| ({ type: "serverLog" } & ServerLogEntry);
|
| ({ type: "serverLog" } & ServerLogEntry)
|
||||||
|
| {
|
||||||
|
type: "clientConnectionInfo";
|
||||||
|
client_id: number;
|
||||||
|
ping_ms: number | null;
|
||||||
|
connected_secs: number | null;
|
||||||
|
ip: string | null;
|
||||||
|
packets_sent: number;
|
||||||
|
bytes_sent: number;
|
||||||
|
packets_received: number;
|
||||||
|
bytes_received: number;
|
||||||
|
packet_loss_percent: number;
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
type: "serverConnectionInfo";
|
||||||
|
ping_ms: number;
|
||||||
|
connected_secs: number;
|
||||||
|
packet_loss_percent: number;
|
||||||
|
packets_sent_total: number;
|
||||||
|
bytes_sent_total: number;
|
||||||
|
packets_received_total: number;
|
||||||
|
bytes_received_total: number;
|
||||||
|
bandwidth_sent_last_second: number;
|
||||||
|
bandwidth_received_last_second: number;
|
||||||
|
};
|
||||||
|
|
||||||
if (event.type === "connected") {
|
if (event.type === "connected") {
|
||||||
this.emit({
|
this.emit({
|
||||||
@@ -205,6 +253,32 @@ export class Ts3Connection {
|
|||||||
fromSelf: event.from_self,
|
fromSelf: event.from_self,
|
||||||
message: event.message,
|
message: event.message,
|
||||||
});
|
});
|
||||||
|
} else if (event.type === "clientConnectionInfo") {
|
||||||
|
this.emit({
|
||||||
|
type: "clientConnectionInfo",
|
||||||
|
clientId: event.client_id,
|
||||||
|
pingMs: event.ping_ms,
|
||||||
|
connectedSecs: event.connected_secs,
|
||||||
|
ip: event.ip,
|
||||||
|
packetsSent: event.packets_sent,
|
||||||
|
bytesSent: event.bytes_sent,
|
||||||
|
packetsReceived: event.packets_received,
|
||||||
|
bytesReceived: event.bytes_received,
|
||||||
|
packetLossPercent: event.packet_loss_percent,
|
||||||
|
});
|
||||||
|
} else if (event.type === "serverConnectionInfo") {
|
||||||
|
this.emit({
|
||||||
|
type: "serverConnectionInfo",
|
||||||
|
pingMs: event.ping_ms,
|
||||||
|
connectedSecs: event.connected_secs,
|
||||||
|
packetLossPercent: event.packet_loss_percent,
|
||||||
|
packetsSentTotal: event.packets_sent_total,
|
||||||
|
bytesSentTotal: event.bytes_sent_total,
|
||||||
|
packetsReceivedTotal: event.packets_received_total,
|
||||||
|
bytesReceivedTotal: event.bytes_received_total,
|
||||||
|
bandwidthSentLastSecond: event.bandwidth_sent_last_second,
|
||||||
|
bandwidthReceivedLastSecond: event.bandwidth_received_last_second,
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
this.emit(event);
|
this.emit(event);
|
||||||
}
|
}
|
||||||
@@ -230,6 +304,14 @@ export class Ts3Connection {
|
|||||||
this.child?.stdin.write(`switch ${channelId}\n`);
|
this.child?.stdin.write(`switch ${channelId}\n`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getClientConnectionInfo(clientId: number): Promise<void> {
|
||||||
|
this.child?.stdin.write(`clientconninfo ${clientId}\n`);
|
||||||
|
}
|
||||||
|
|
||||||
|
async getServerConnectionInfo(): Promise<void> {
|
||||||
|
this.child?.stdin.write(`serverconninfo\n`);
|
||||||
|
}
|
||||||
|
|
||||||
async sendChatMessage(message: string): Promise<void> {
|
async sendChatMessage(message: string): Promise<void> {
|
||||||
const sanitized = message.replace(/[\r\n]+/g, " ").trim();
|
const sanitized = message.replace(/[\r\n]+/g, " ").trim();
|
||||||
if (sanitized) this.child?.stdin.write(`chat ${sanitized}\n`);
|
if (sanitized) this.child?.stdin.write(`chat ${sanitized}\n`);
|
||||||
|
|||||||
@@ -440,6 +440,42 @@
|
|||||||
color: var(--text-muted);
|
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 {
|
.ts-row-selected {
|
||||||
background: var(--row-hover);
|
background: var(--row-hover);
|
||||||
outline: 1px solid var(--border);
|
outline: 1px solid var(--border);
|
||||||
|
|||||||
+260
-1
@@ -282,6 +282,50 @@ interface ClientInfo {
|
|||||||
uid: string;
|
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
|
/** 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
|
* via Unicode regional indicator symbols. Returns null for codes the server
|
||||||
* doesn't report (empty string - common when geo-IP isn't configured). */
|
* doesn't report (empty string - common when geo-IP isn't configured). */
|
||||||
@@ -447,6 +491,7 @@ function InfoPanel({
|
|||||||
totalClientCount,
|
totalClientCount,
|
||||||
channels,
|
channels,
|
||||||
clients,
|
clients,
|
||||||
|
onShowServerConnectionInfo,
|
||||||
}: {
|
}: {
|
||||||
selected: SelectedItem | null;
|
selected: SelectedItem | null;
|
||||||
host: string;
|
host: string;
|
||||||
@@ -457,6 +502,7 @@ function InfoPanel({
|
|||||||
totalClientCount: number;
|
totalClientCount: number;
|
||||||
channels: ChannelInfo[];
|
channels: ChannelInfo[];
|
||||||
clients: ClientInfo[];
|
clients: ClientInfo[];
|
||||||
|
onShowServerConnectionInfo: () => void;
|
||||||
}) {
|
}) {
|
||||||
const t = useT();
|
const t = useT();
|
||||||
if (!selected || selected.type === "server") {
|
if (!selected || selected.type === "server") {
|
||||||
@@ -485,6 +531,9 @@ function InfoPanel({
|
|||||||
<div className="ts-info-row">
|
<div className="ts-info-row">
|
||||||
<span>{t("info.currentChannels")}</span> <span>{channels.length}</span>
|
<span>{t("info.currentChannels")}</span> <span>{channels.length}</span>
|
||||||
</div>
|
</div>
|
||||||
|
<button className="ts-info-connection-link" onClick={onShowServerConnectionInfo}>
|
||||||
|
🔌 {t("connectionInfo.serverTitle")}
|
||||||
|
</button>
|
||||||
</div>
|
</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({
|
function IdentitiesDialog({
|
||||||
identities,
|
identities,
|
||||||
activeId,
|
activeId,
|
||||||
@@ -2265,6 +2447,12 @@ function AppInner() {
|
|||||||
localStorage.getItem(ACTIVE_IDENTITY_KEY)
|
localStorage.getItem(ACTIVE_IDENTITY_KEY)
|
||||||
);
|
);
|
||||||
const [identitiesOpen, setIdentitiesOpen] = useState(false);
|
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 [selfMenuOpen, setSelfMenuOpen] = useState(false);
|
||||||
const selfMenuRef = useRef<HTMLDivElement | null>(null);
|
const selfMenuRef = useRef<HTMLDivElement | null>(null);
|
||||||
const [changeNicknameOpen, setChangeNicknameOpen] = useState(false);
|
const [changeNicknameOpen, setChangeNicknameOpen] = useState(false);
|
||||||
@@ -2712,6 +2900,32 @@ function AppInner() {
|
|||||||
setConnectError(data.message);
|
setConnectError(data.message);
|
||||||
}
|
}
|
||||||
break;
|
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 = (
|
const handleClientContextMenu = (
|
||||||
e: React.MouseEvent,
|
e: React.MouseEvent,
|
||||||
clientId: number,
|
clientId: number,
|
||||||
@@ -3495,7 +3721,14 @@ function AppInner() {
|
|||||||
<span className="ts-menu-item-label">{t("menu.self.setPhoneticNickname")}</span>
|
<span className="ts-menu-item-label">{t("menu.self.setPhoneticNickname")}</span>
|
||||||
</button>
|
</button>
|
||||||
<div className="ts-menu-separator" />
|
<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-icon">ℹ️</span>
|
||||||
<span className="ts-menu-item-label">{t("menu.self.connectionInfo")}</span>
|
<span className="ts-menu-item-label">{t("menu.self.connectionInfo")}</span>
|
||||||
</button>
|
</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 && (
|
{contactsOpen && (
|
||||||
<ContactsDialog
|
<ContactsDialog
|
||||||
contacts={contacts}
|
contacts={contacts}
|
||||||
@@ -4086,6 +4334,16 @@ function AppInner() {
|
|||||||
<span className="ts-menu-item-icon">📋</span>
|
<span className="ts-menu-item-icon">📋</span>
|
||||||
<span className="ts-menu-item-label">{t("clientContext.copyName")}</span>
|
<span className="ts-menu-item-label">{t("clientContext.copyName")}</span>
|
||||||
</button>
|
</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 && (
|
{!clientContextMenu.isSelf && (
|
||||||
<button
|
<button
|
||||||
className="ts-menu-item"
|
className="ts-menu-item"
|
||||||
@@ -4177,6 +4435,7 @@ function AppInner() {
|
|||||||
totalClientCount={clients.length}
|
totalClientCount={clients.length}
|
||||||
channels={channels}
|
channels={channels}
|
||||||
clients={clients}
|
clients={clients}
|
||||||
|
onShowServerConnectionInfo={handleShowServerConnectionInfo}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -167,6 +167,40 @@ export class DemoSocket {
|
|||||||
);
|
);
|
||||||
break;
|
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
|
// "disconnect" is intentionally unhandled here: handleDisconnect() in
|
||||||
// App.tsx always calls socket.close() right after sending it, and
|
// App.tsx always calls socket.close() right after sending it, and
|
||||||
// close() already emits the "disconnected" event below.
|
// close() already emits the "disconnected" event below.
|
||||||
|
|||||||
@@ -128,6 +128,21 @@ const translations: Record<Lang, Record<string, string>> = {
|
|||||||
"identities.generated": "Erstellt",
|
"identities.generated": "Erstellt",
|
||||||
"identities.pending": "Wird bei der nächsten Verbindung 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.recordingProfile": "Aufnahmeprofil",
|
||||||
"menu.self.playbackProfile": "Wiedergabeprofil",
|
"menu.self.playbackProfile": "Wiedergabeprofil",
|
||||||
"menu.self.hotkeyProfile": "Hotkeyprofil",
|
"menu.self.hotkeyProfile": "Hotkeyprofil",
|
||||||
@@ -291,6 +306,7 @@ const translations: Record<Lang, Record<string, string>> = {
|
|||||||
"clientContext.privateChat": "Privater Chat",
|
"clientContext.privateChat": "Privater Chat",
|
||||||
"clientContext.poke": "Anstupsen",
|
"clientContext.poke": "Anstupsen",
|
||||||
"clientContext.copyName": "Namen kopieren",
|
"clientContext.copyName": "Namen kopieren",
|
||||||
|
"clientContext.connectionInfo": "Verbindungsinformationen anzeigen",
|
||||||
"clientContext.addWhisperTarget": "Als Whisper-Ziel hinzufügen",
|
"clientContext.addWhisperTarget": "Als Whisper-Ziel hinzufügen",
|
||||||
"clientContext.removeWhisperTarget": "Als Whisper-Ziel entfernen",
|
"clientContext.removeWhisperTarget": "Als Whisper-Ziel entfernen",
|
||||||
"clientContext.assignChannelGroup": "Channel-Gruppe zuweisen",
|
"clientContext.assignChannelGroup": "Channel-Gruppe zuweisen",
|
||||||
@@ -451,6 +467,21 @@ const translations: Record<Lang, Record<string, string>> = {
|
|||||||
"identities.generated": "Generated",
|
"identities.generated": "Generated",
|
||||||
"identities.pending": "Will be generated on next connection",
|
"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.recordingProfile": "Recording Profile",
|
||||||
"menu.self.playbackProfile": "Playback Profile",
|
"menu.self.playbackProfile": "Playback Profile",
|
||||||
"menu.self.hotkeyProfile": "Hotkey Profile",
|
"menu.self.hotkeyProfile": "Hotkey Profile",
|
||||||
@@ -614,6 +645,7 @@ const translations: Record<Lang, Record<string, string>> = {
|
|||||||
"clientContext.privateChat": "Private chat",
|
"clientContext.privateChat": "Private chat",
|
||||||
"clientContext.poke": "Poke",
|
"clientContext.poke": "Poke",
|
||||||
"clientContext.copyName": "Copy name",
|
"clientContext.copyName": "Copy name",
|
||||||
|
"clientContext.connectionInfo": "Show connection info",
|
||||||
"clientContext.addWhisperTarget": "Add as whisper target",
|
"clientContext.addWhisperTarget": "Add as whisper target",
|
||||||
"clientContext.removeWhisperTarget": "Remove as whisper target",
|
"clientContext.removeWhisperTarget": "Remove as whisper target",
|
||||||
"clientContext.assignChannelGroup": "Assign channel group",
|
"clientContext.assignChannelGroup": "Assign channel group",
|
||||||
|
|||||||
Reference in new issue
Block a user