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:
2026-10-06 20:26:59 +00:00
co-authored by Claude Opus 5.5
parent c8c54bd381
commit 9458ff3400
14 changed files with 437 additions and 198 deletions
@@ -2,6 +2,7 @@ package com.ts3client.android
import com.ts3client.contacts.ContactType
import com.ts3client.net.ChannelNode
import com.ts3client.net.ConnectionStats
import com.ts3client.net.Details
import com.ts3client.net.GroupChoice
import com.ts3client.net.ban.BanEntry
@@ -214,6 +215,11 @@ class ServerController internal constructor(
// ---- ban list ----
/** The server's bans, or why they could not be read. */
/** One reading of a client's connection figures, or null when not connected. */
suspend fun connectionStats(clientId: Int): ConnectionStats? =
if (!session.isConnected) null
else suspendCoroutine { done -> conn.requestConnectionInfo(clientId) { done.resume(it) } }
suspend fun banList(): Result<List<BanEntry>> = suspendCoroutine { done ->
conn.requestBanList { bans, error ->
done.resume(if (error == null) Result.success(bans) else Result.failure(IllegalStateException(error)))
@@ -0,0 +1,68 @@
package com.ts3client.android.ui
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.ts3client.android.ServerController
import com.ts3client.net.ConnectionStats
import com.ts3client.net.ConnectionStatsFormat
import kotlinx.coroutines.delay
private const val REFRESH_MS = 1000L
private const val SELF_ADDRESS = "This device"
/** A client's connection figures, read again every second while shown, and what our playback made of their voice. */
@Composable
fun ConnectionInfoScreen(server: ServerController, clientId: Int, nickname: String, onBack: () -> Unit) {
var stats by remember { mutableStateOf<ConnectionStats?>(null) }
LaunchedEffect(clientId) {
while (true) {
stats = server.connectionStats(clientId) ?: break
delay(REFRESH_MS)
}
}
val s = stats
SubScreen("Connection info", onBack) { padding ->
Column(Modifier.padding(padding).verticalScroll(rememberScrollState()).padding(bottom = 16.dp)) {
Text(nickname, Modifier.padding(horizontal = 16.dp, vertical = 8.dp), style = MaterialTheme.typography.titleLarge)
Figures(ConnectionStatsFormat.summaryRows(s, SELF_ADDRESS))
Section("Voice received")
Figures(ConnectionStatsFormat.voiceRows(s?.voiceReceived))
Section("Total")
Figures(ConnectionStatsFormat.trafficRows(s, null))
for ((kind, title) in KINDS) {
Section(title)
Figures(ConnectionStatsFormat.trafficRows(s, kind))
}
}
}
}
private val KINDS = listOf(
ConnectionStats.Kind.SPEECH to "Speech",
ConnectionStats.Kind.KEEPALIVE to "Keep alive",
ConnectionStats.Kind.CONTROL to "Control",
)
@Composable
private fun Figures(rows: List<ConnectionStatsFormat.Row>) {
for (row in rows) {
Row(Modifier.padding(horizontal = 16.dp, vertical = 4.dp)) {
Text(row.label, Modifier.weight(1f), color = MaterialTheme.colorScheme.onSurfaceVariant)
Text(row.value, Modifier.weight(1f), textAlign = TextAlign.End)
}
}
}
@@ -129,6 +129,7 @@ fun ServerScreen(
var channelSheet by remember { mutableStateOf<Int?>(null) }
var serverSheet by remember { mutableStateOf(false) }
var banList by rememberSaveable { mutableStateOf(false) }
var connectionInfo by rememberSaveable { mutableStateOf<Int?>(null) }
/** The client to move, while a channel for them is being picked. */
var moving by remember { mutableStateOf<Int?>(null) }
val infoUpdates by server.infoUpdates.collectAsStateWithLifecycle()
@@ -207,6 +208,10 @@ fun ServerScreen(
BanListScreen(server, vm.banReasons, onBack = { banList = false })
return
}
connectionInfo?.let { id ->
ConnectionInfoScreen(server, id, tree.client(id)?.name ?: "", onBack = { connectionInfo = null })
return
}
BackHandler(showChat) { showChat = false }
BackHandler(moving != null && !showChat) { moving = null }
@@ -334,6 +339,7 @@ fun ServerScreen(
onAway = { server.setAway(it); clientSheet = null },
onAddContact = { server.addContact(id, it) },
onEditContact = { clientSheet = null; onEditContact(client.uniqueId) },
onConnectionInfo = { clientSheet = null; connectionInfo = id },
onMove = if (server.canMoveClients) ({ clientSheet = null; moving = id }) else null,
onMoveToOwnChannel = if (server.canMoveClients && tree.channel(state.channelId)?.clients?.none { it.id == id } == true) {
{ server.moveClient(id, state.channelId); clientSheet = null }
@@ -53,6 +53,7 @@ fun ClientSheet(
onAway: (Boolean) -> Unit,
onAddContact: (ContactType) -> Unit,
onEditContact: () -> Unit,
onConnectionInfo: () -> Unit,
/** Null when the client cannot be moved. */
onMove: (() -> Unit)?,
/** Null when the client cannot be moved, or is in our channel already. */
@@ -87,6 +88,7 @@ fun ClientSheet(
}
details?.let { DetailsSection(it, onLink, Modifier.padding(bottom = 8.dp)) }
onFindInTree?.let { Action("CHANNEL_SWITCH", "Find client in channel tree", onClick = it) }
Action("INFO", "Connection info", onClick = onConnectionInfo)
if (client.self) {
Action("AWAY", if (away) "Back" else "Away") { onAway(!away) }
moderation()