Add Connection Info on Android and count received voice
Connection Info gains a "Voice received" section on both frontends, counting what our own playback made of a speaker's voice (everyone's, for ourselves): packets received, frames played and missed, packets out of order, dropped as too late, and discarded as copies. Android gets the window itself as a page from the client sheet. The rows and their formatting live in core, shared by both frontends; the Swing dialog keeps its tabs on one row. A minute's bandwidth now shows as the average rate it is labelled as, not the minute's bytes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,6 +3,8 @@ package com.ts3client.ui;
|
||||
import com.formdev.flatlaf.util.ScaledEmptyBorder;
|
||||
import com.formdev.flatlaf.util.UIScale;
|
||||
import com.ts3client.net.ConnectionStats;
|
||||
import com.ts3client.net.ConnectionStatsFormat;
|
||||
import com.ts3client.net.ConnectionStatsFormat.Row;
|
||||
import com.ts3client.net.TeamspeakConnection;
|
||||
|
||||
import javax.swing.Box;
|
||||
@@ -22,14 +24,16 @@ import java.awt.GridBagLayout;
|
||||
import java.awt.Insets;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Live "Client Connection Info" window, reachable from a client's right-click
|
||||
* menu. Mirrors the TeamSpeak 3 dialog: a summary header (address, version,
|
||||
* platform, idle/connected time, ping, filetransfer) above a
|
||||
* <em>Total / Speech / Keep Alive / Control</em> tab strip, each tab showing
|
||||
* that category's packet loss, packet and byte totals and live bandwidth.
|
||||
* that category's packet loss, packet and byte totals and live bandwidth, plus a
|
||||
* <em>Voice received</em> tab with what our own playback made of the client's voice
|
||||
* (everyone's, for ourselves): missed, out-of-order, late and duplicate packets.
|
||||
*
|
||||
* <p>Polls the {@link TeamspeakConnection} once a second while open; for the
|
||||
* local client the figures update live from local counters, for a remote client
|
||||
@@ -38,6 +42,9 @@ import java.text.DecimalFormat;
|
||||
public final class ConnectionInfoDialog extends JDialog {
|
||||
|
||||
private static final int REFRESH_MS = 1000;
|
||||
/** Wide enough for the tab strip to stay on one row. */
|
||||
private static final int MIN_WIDTH = 560;
|
||||
private static final String SELF_ADDRESS = "This computer";
|
||||
|
||||
private final TeamspeakConnection conn;
|
||||
private final int clientId;
|
||||
@@ -45,18 +52,12 @@ public final class ConnectionInfoDialog extends JDialog {
|
||||
private final java.util.concurrent.atomic.AtomicBoolean inFlight =
|
||||
new java.util.concurrent.atomic.AtomicBoolean();
|
||||
|
||||
private final JLabel addressValue = value();
|
||||
private final JLabel versionValue = value();
|
||||
private final JLabel platformValue = value();
|
||||
private final JLabel idleValue = value();
|
||||
private final JLabel connectedValue = value();
|
||||
private final JLabel pingValue = value();
|
||||
private final JLabel filetransferValue = value();
|
||||
|
||||
private final KindTab totalTab = new KindTab();
|
||||
private final KindTab speechTab = new KindTab();
|
||||
private final KindTab keepAliveTab = new KindTab();
|
||||
private final KindTab controlTab = new KindTab();
|
||||
private final Rows summary = new Rows(ConnectionStatsFormat.summaryRows(null, SELF_ADDRESS));
|
||||
private final Rows total = tab(ConnectionStatsFormat.trafficRows(null, null));
|
||||
private final Rows speech = tab(ConnectionStatsFormat.trafficRows(null, ConnectionStats.Kind.SPEECH));
|
||||
private final Rows keepAlive = tab(ConnectionStatsFormat.trafficRows(null, ConnectionStats.Kind.KEEPALIVE));
|
||||
private final Rows control = tab(ConnectionStatsFormat.trafficRows(null, ConnectionStats.Kind.CONTROL));
|
||||
private final Rows voice = tab(ConnectionStatsFormat.voiceRows(null));
|
||||
|
||||
public ConnectionInfoDialog(Frame owner, TeamspeakConnection conn, int clientId, String nickname) {
|
||||
super(owner, "Connection Info — " + nickname, false);
|
||||
@@ -66,7 +67,7 @@ public final class ConnectionInfoDialog extends JDialog {
|
||||
JPanel content = new JPanel(new BorderLayout(0, UIScale.scale(10)));
|
||||
content.setBackground(Theme.windowBg());
|
||||
content.setBorder(new ScaledEmptyBorder(12, 14, 12, 14));
|
||||
content.add(buildSummary(), BorderLayout.NORTH);
|
||||
content.add(summary, BorderLayout.NORTH);
|
||||
content.add(buildTabs(), BorderLayout.CENTER);
|
||||
content.add(buildButtons(), BorderLayout.SOUTH);
|
||||
setContentPane(content);
|
||||
@@ -74,7 +75,7 @@ public final class ConnectionInfoDialog extends JDialog {
|
||||
Dialogs.closeOnEscape(this);
|
||||
// Disposing is what stops the refresh timer, so the window button must not merely hide.
|
||||
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||
pack();
|
||||
fit();
|
||||
setLocationRelativeTo(owner);
|
||||
|
||||
addWindowListener(new WindowAdapter() {
|
||||
@@ -91,28 +92,15 @@ public final class ConnectionInfoDialog extends JDialog {
|
||||
|
||||
// ---- construction ----
|
||||
|
||||
private JPanel buildSummary() {
|
||||
JPanel grid = new JPanel(new GridBagLayout());
|
||||
grid.setBackground(Theme.windowBg());
|
||||
int row = 0;
|
||||
addRow(grid, row++, "Address", addressValue);
|
||||
addRow(grid, row++, "Client version", versionValue);
|
||||
addRow(grid, row++, "Platform", platformValue);
|
||||
addRow(grid, row++, "Ping", pingValue);
|
||||
addRow(grid, row++, "Idle time", idleValue);
|
||||
addRow(grid, row++, "Connected", connectedValue);
|
||||
addRow(grid, row, "Filetransfer (↑/↓)", filetransferValue);
|
||||
return grid;
|
||||
}
|
||||
|
||||
private JTabbedPane buildTabs() {
|
||||
JTabbedPane tabs = new JTabbedPane();
|
||||
tabs.setFont(Theme.uiFont());
|
||||
tabs.setBackground(Theme.windowBg());
|
||||
tabs.addTab("Total", totalTab);
|
||||
tabs.addTab("Speech", speechTab);
|
||||
tabs.addTab("Keep Alive", keepAliveTab);
|
||||
tabs.addTab("Control", controlTab);
|
||||
tabs.addTab("Total", total);
|
||||
tabs.addTab("Speech", speech);
|
||||
tabs.addTab("Keep Alive", keepAlive);
|
||||
tabs.addTab("Control", control);
|
||||
tabs.addTab("Voice received", voice);
|
||||
return tabs;
|
||||
}
|
||||
|
||||
@@ -127,32 +115,10 @@ public final class ConnectionInfoDialog extends JDialog {
|
||||
return bar;
|
||||
}
|
||||
|
||||
private static JLabel value() {
|
||||
JLabel l = new JLabel("—");
|
||||
l.setFont(Theme.uiFont());
|
||||
l.setForeground(Theme.treeText());
|
||||
return l;
|
||||
}
|
||||
|
||||
private static void addRow(JPanel grid, int row, String label, JLabel valueLabel) {
|
||||
GridBagConstraints lc = new GridBagConstraints();
|
||||
lc.gridx = 0;
|
||||
lc.gridy = row;
|
||||
lc.anchor = GridBagConstraints.WEST;
|
||||
lc.insets = UIScale.scale(new Insets(2, 0, 2, 16));
|
||||
JLabel key = new JLabel(label);
|
||||
key.setFont(Theme.uiFont());
|
||||
key.setForeground(new Color(0x5A6B7B));
|
||||
grid.add(key, lc);
|
||||
|
||||
GridBagConstraints vc = new GridBagConstraints();
|
||||
vc.gridx = 1;
|
||||
vc.gridy = row;
|
||||
vc.weightx = 1;
|
||||
vc.anchor = GridBagConstraints.WEST;
|
||||
vc.fill = GridBagConstraints.HORIZONTAL;
|
||||
vc.insets = UIScale.scale(new Insets(2, 0, 2, 0));
|
||||
grid.add(valueLabel, vc);
|
||||
private static Rows tab(List<Row> rows) {
|
||||
Rows tab = new Rows(rows);
|
||||
tab.setBorder(new ScaledEmptyBorder(10, 12, 10, 12));
|
||||
return tab;
|
||||
}
|
||||
|
||||
// ---- live update ----
|
||||
@@ -171,21 +137,12 @@ public final class ConnectionInfoDialog extends JDialog {
|
||||
|
||||
private void apply(ConnectionStats s) {
|
||||
if (!isDisplayable()) return;
|
||||
|
||||
addressValue.setText(s.self ? "This computer" : orDash(s.ip));
|
||||
versionValue.setText(orDash(s.version));
|
||||
platformValue.setText(orDash(s.platform));
|
||||
pingValue.setText(formatPing(s.pingMs, s.pingDeviationMs));
|
||||
idleValue.setText(formatDuration(s.idleTimeMs));
|
||||
connectedValue.setText(formatDuration(s.connectedTimeMs));
|
||||
filetransferValue.setText(formatRate(s.filetransferBandwidthSent)
|
||||
+ " / " + formatRate(s.filetransferBandwidthReceived));
|
||||
|
||||
totalTab.update(totalSample(s));
|
||||
speechTab.update(kindSample(s, ConnectionStats.Kind.SPEECH));
|
||||
keepAliveTab.update(kindSample(s, ConnectionStats.Kind.KEEPALIVE));
|
||||
controlTab.update(kindSample(s, ConnectionStats.Kind.CONTROL));
|
||||
|
||||
summary.update(ConnectionStatsFormat.summaryRows(s, SELF_ADDRESS));
|
||||
total.update(ConnectionStatsFormat.trafficRows(s, null));
|
||||
speech.update(ConnectionStatsFormat.trafficRows(s, ConnectionStats.Kind.SPEECH));
|
||||
keepAlive.update(ConnectionStatsFormat.trafficRows(s, ConnectionStats.Kind.KEEPALIVE));
|
||||
control.update(ConnectionStatsFormat.trafficRows(s, ConnectionStats.Kind.CONTROL));
|
||||
voice.update(ConnectionStatsFormat.voiceRows(s.voiceReceived));
|
||||
growToFit();
|
||||
}
|
||||
|
||||
@@ -198,133 +155,54 @@ public final class ConnectionInfoDialog extends JDialog {
|
||||
Dimension pref = getContentPane().getPreferredSize();
|
||||
Dimension have = getContentPane().getSize();
|
||||
if (pref.width > have.width || pref.height > have.height) {
|
||||
pack();
|
||||
fit();
|
||||
}
|
||||
}
|
||||
|
||||
private static Sample totalSample(ConnectionStats s) {
|
||||
Sample sample = new Sample();
|
||||
sample.packetLoss = s.packetLoss;
|
||||
sample.packetsSent = s.packetsSentTotal;
|
||||
sample.packetsReceived = s.packetsReceivedTotal;
|
||||
sample.bytesSent = s.bytesSentTotal;
|
||||
sample.bytesReceived = s.bytesReceivedTotal;
|
||||
sample.bwSentSecond = s.bandwidthSentLastSecond;
|
||||
sample.bwReceivedSecond = s.bandwidthReceivedLastSecond;
|
||||
sample.bwSentMinute = s.bandwidthSentLastMinute;
|
||||
sample.bwReceivedMinute = s.bandwidthReceivedLastMinute;
|
||||
return sample;
|
||||
private void fit() {
|
||||
pack();
|
||||
setSize(Math.max(getWidth(), UIScale.scale(MIN_WIDTH)), getHeight());
|
||||
}
|
||||
|
||||
private static Sample kindSample(ConnectionStats s, ConnectionStats.Kind kind) {
|
||||
Sample sample = new Sample();
|
||||
ConnectionStats.KindStats k = s.kind(kind);
|
||||
if (k == null) return sample; // all fields stay unknown (-1)
|
||||
sample.packetLoss = k.packetLoss;
|
||||
sample.packetsSent = k.packetsSent;
|
||||
sample.packetsReceived = k.packetsReceived;
|
||||
sample.bytesSent = k.bytesSent;
|
||||
sample.bytesReceived = k.bytesReceived;
|
||||
sample.bwSentSecond = k.bandwidthSentLastSecond;
|
||||
sample.bwReceivedSecond = k.bandwidthReceivedLastSecond;
|
||||
sample.bwSentMinute = k.bandwidthSentLastMinute;
|
||||
sample.bwReceivedMinute = k.bandwidthReceivedLastMinute;
|
||||
return sample;
|
||||
}
|
||||
/** A grid of labelled figures, laid out once and refreshed in place. */
|
||||
private static final class Rows extends JPanel {
|
||||
private final JLabel[] values;
|
||||
|
||||
// ---- one category tab ----
|
||||
|
||||
/** Numeric snapshot fed to a {@link KindTab}; -1 means "unknown". */
|
||||
private static final class Sample {
|
||||
double packetLoss = -1;
|
||||
long packetsSent = -1;
|
||||
long packetsReceived = -1;
|
||||
long bytesSent = -1;
|
||||
long bytesReceived = -1;
|
||||
long bwSentSecond = -1;
|
||||
long bwReceivedSecond = -1;
|
||||
long bwSentMinute = -1;
|
||||
long bwReceivedMinute = -1;
|
||||
}
|
||||
|
||||
private static final class KindTab extends JPanel {
|
||||
private final JLabel packetLoss = value();
|
||||
private final JLabel packets = value();
|
||||
private final JLabel bytes = value();
|
||||
private final JLabel bandwidthSecond = value();
|
||||
private final JLabel bandwidthMinute = value();
|
||||
|
||||
KindTab() {
|
||||
Rows(List<Row> rows) {
|
||||
super(new GridBagLayout());
|
||||
setBackground(Theme.windowBg());
|
||||
setBorder(new ScaledEmptyBorder(10, 12, 10, 12));
|
||||
int row = 0;
|
||||
addRow(this, row++, "Packet loss", packetLoss);
|
||||
addRow(this, row++, "Packets (↑/↓)", packets);
|
||||
addRow(this, row++, "Transferred (↑/↓)", bytes);
|
||||
addRow(this, row++, "Bandwidth · last second (↑/↓)", bandwidthSecond);
|
||||
addRow(this, row, "Bandwidth · last minute (↑/↓)", bandwidthMinute);
|
||||
values = new JLabel[rows.size()];
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
values[i] = new JLabel(rows.get(i).value());
|
||||
values[i].setFont(Theme.uiFont());
|
||||
values[i].setForeground(Theme.treeText());
|
||||
addRow(i, rows.get(i).label(), values[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void update(Sample s) {
|
||||
packetLoss.setText(formatLoss(s.packetLoss));
|
||||
packets.setText(formatCount(s.packetsSent) + " / " + formatCount(s.packetsReceived));
|
||||
bytes.setText(formatBytes(s.bytesSent) + " / " + formatBytes(s.bytesReceived));
|
||||
bandwidthSecond.setText(formatRate(s.bwSentSecond) + " / " + formatRate(s.bwReceivedSecond));
|
||||
bandwidthMinute.setText(formatRate(s.bwSentMinute) + " / " + formatRate(s.bwReceivedMinute));
|
||||
void update(List<Row> rows) {
|
||||
for (int i = 0; i < values.length; i++) values[i].setText(rows.get(i).value());
|
||||
}
|
||||
}
|
||||
|
||||
// ---- formatting ----
|
||||
private void addRow(int row, String label, JLabel valueLabel) {
|
||||
GridBagConstraints lc = new GridBagConstraints();
|
||||
lc.gridx = 0;
|
||||
lc.gridy = row;
|
||||
lc.anchor = GridBagConstraints.WEST;
|
||||
lc.insets = UIScale.scale(new Insets(2, 0, 2, 16));
|
||||
JLabel key = new JLabel(label);
|
||||
key.setFont(Theme.uiFont());
|
||||
key.setForeground(new Color(0x5A6B7B));
|
||||
add(key, lc);
|
||||
|
||||
private static final DecimalFormat GROUPED = new DecimalFormat("#,##0");
|
||||
|
||||
private static String orDash(String s) {
|
||||
return (s == null || s.isEmpty()) ? "—" : s;
|
||||
}
|
||||
|
||||
private static String formatPing(double ms, double deviationMs) {
|
||||
if (ms < 0) return "—";
|
||||
String base = Math.round(ms) + " ms";
|
||||
if (deviationMs > 0) base += " (± " + Math.round(deviationMs) + " ms)";
|
||||
return base;
|
||||
}
|
||||
|
||||
private static String formatLoss(double fraction) {
|
||||
if (fraction < 0) return "—";
|
||||
return new DecimalFormat("0.00").format(fraction * 100.0) + " %";
|
||||
}
|
||||
|
||||
private static String formatCount(long n) {
|
||||
return n < 0 ? "—" : GROUPED.format(n);
|
||||
}
|
||||
|
||||
private static String formatBytes(long bytes) {
|
||||
if (bytes < 0) return "—";
|
||||
if (bytes < 1024) return bytes + " B";
|
||||
double kib = bytes / 1024.0;
|
||||
if (kib < 1024) return new DecimalFormat("0.0").format(kib) + " KiB";
|
||||
double mib = kib / 1024.0;
|
||||
if (mib < 1024) return new DecimalFormat("0.00").format(mib) + " MiB";
|
||||
return new DecimalFormat("0.00").format(mib / 1024.0) + " GiB";
|
||||
}
|
||||
|
||||
private static String formatRate(long bytesPerSecond) {
|
||||
return bytesPerSecond < 0 ? "—" : formatBytes(bytesPerSecond) + "/s";
|
||||
}
|
||||
|
||||
private static String formatDuration(long ms) {
|
||||
if (ms < 0) return "—";
|
||||
long totalSeconds = ms / 1000;
|
||||
long days = totalSeconds / 86400;
|
||||
long hours = (totalSeconds % 86400) / 3600;
|
||||
long minutes = (totalSeconds % 3600) / 60;
|
||||
long seconds = totalSeconds % 60;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (days > 0) sb.append(days).append("d ");
|
||||
if (days > 0 || hours > 0) sb.append(hours).append("h ");
|
||||
if (days > 0 || hours > 0 || minutes > 0) sb.append(minutes).append("m ");
|
||||
sb.append(seconds).append("s");
|
||||
return sb.toString();
|
||||
GridBagConstraints vc = new GridBagConstraints();
|
||||
vc.gridx = 1;
|
||||
vc.gridy = row;
|
||||
vc.weightx = 1;
|
||||
vc.anchor = GridBagConstraints.WEST;
|
||||
vc.fill = GridBagConstraints.HORIZONTAL;
|
||||
vc.insets = UIScale.scale(new Insets(2, 0, 2, 0));
|
||||
add(valueLabel, vc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user