Take ServerFlavor out of the engine API

Event::ServerInfo carried voelin_model::ServerFlavor, a TeamSpeak notion. It
now carries backend: BackendInfo { product, version } (plain strings, with
label() for a sentence) next to the capabilities. The voice source decides
the flavor from the version string (voice.rs backend_of) and puts the
backend and capabilities in VoiceEvent::Connected; session.rs forwards them
and no longer classifies anything.

The UI reads backend.product for a server's chip (ServerItem.flavor becomes
product, as does the session view's field) and backend.label() for the
"Connected to ..." status line; the sample data builds its own backend and
the TeamSpeak 6 capabilities, pinned against the flavor's by a test.
voelinctl's engine mode prints the label. ServerFlavor stays in voelin-model
for the gateway and the voice source.

Shown text is unchanged. New tests: the voice source's backend for TS3, TS6
and an unrecognised version, BackendInfo::label, the status line, the sample
servers' backends, and the server item's product.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Sonnet 5.5 committed 2026-10-14 13:59:20 +03:00
1 parent df7be67d4c
commit b0f95a384f
13 files changed
+257 -46

No files matched your search

+2 -2
View File
@@ -194,7 +194,7 @@ fn connected(viewers: &[ViewerInfo]) -> usize {
mod tests {
use voelin_core::SessionState;
use voelin_core::stream::EndReason;
use voelin_model::{Capabilities, ChannelInfo, ClientInfo, ServerFlavor};
use voelin_model::{Capabilities, ChannelInfo, ClientInfo};
use super::*;
@@ -244,7 +244,7 @@ mod tests {
let info = Event::ServerInfo {
session: 1,
name: "Home".into(),
flavor: ServerFlavor::Unknown(String::new()),
backend: voelin_core::BackendInfo::default(),
capabilities: Capabilities::default(),
};
assert_eq!(fg.update_at(&info, 6).voice, notice("Connecting…", "Home", false, 0));
+45 -2
View File
@@ -76,7 +76,6 @@ pub use voelin_audio::settings::TransmitMode;
pub use voelin_audio::{AudioSettings, ProcessingSettings, VadSettings};
use voelin_model::{
Capabilities, ChannelId, ChatMessage, ChatTarget, FileRef, GroupInfo, Presence, ServerDetails,
ServerFlavor,
};
use crate::audio::{AudioEvent, AudioHandle, AudioIn};
@@ -507,6 +506,30 @@ pub enum JoinFailure {
Other(String),
}
/// The software on the other end of a session, as its link names it. It is
/// for people to read; nothing branches on it (what the server can do is
/// [`Capabilities`]).
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct BackendInfo {
/// What it is called ("TeamSpeak 6"); empty when it was not recognised.
pub product: String,
/// Its version as the product shows it ("6.0.0-beta13.1"); what the
/// server said, as it is, when `product` is empty.
pub version: String,
}
impl BackendInfo {
/// For a sentence: the product and the version, whichever there are
/// ("TeamSpeak 6 6.0.0-beta13.1", "TeamSpeak 3", "custom 9").
pub fn label(&self) -> String {
match (self.product.is_empty(), self.version.is_empty()) {
(false, false) => format!("{} {}", self.product, self.version),
(false, true) => self.product.clone(),
(true, _) => self.version.clone(),
}
}
}
/// What the engine reports.
#[derive(Clone, Debug)]
pub enum Event {
@@ -514,10 +537,12 @@ pub enum Event {
session: SessionId,
state: SessionState,
},
/// The server answered: its name, the software it runs and what that
/// software can do (the UI hides what it cannot).
ServerInfo {
session: SessionId,
name: String,
flavor: ServerFlavor,
backend: BackendInfo,
capabilities: Capabilities,
},
/// Full presence of the session (the UI rebuilds its view from it).
@@ -1111,3 +1136,21 @@ fn command_session(command: &Command) -> SessionId {
fn one_rustls_crypto_provider() {
let _ = rustls::ClientConfig::builder();
}
#[cfg(test)]
mod tests {
use super::BackendInfo;
#[test]
fn a_backend_reads_as_its_product_and_version() {
let backend = |product: &str, version: &str| BackendInfo {
product: product.into(),
version: version.into(),
};
assert_eq!(backend("TeamSpeak 6", "6.0.0-beta13.1").label(), "TeamSpeak 6 6.0.0-beta13.1");
assert_eq!(backend("TeamSpeak 3", "").label(), "TeamSpeak 3");
// Not recognised: the version string alone, or nothing.
assert_eq!(backend("", "custom 9").label(), "custom 9");
assert_eq!(BackendInfo::default().label(), "");
}
}
+11 -4
View File
@@ -1925,7 +1925,14 @@ impl Session {
fn voice_event(&mut self, e: VoiceEvent) {
match e {
VoiceEvent::Connected { name, flavor, own_client, server_uid, own_uid } => {
VoiceEvent::Connected {
name,
backend,
capabilities,
own_client,
server_uid,
own_uid,
} => {
self.state.voice = VoiceState::Connected;
self.state.own_client = Some(own_client);
if own_uid.is_some() {
@@ -1940,7 +1947,6 @@ impl Session {
{
let _ = tx.send(GatewayCmd::RetryNow);
}
let capabilities = flavor.capabilities();
if capabilities.streams
&& let Some((generation, voice)) = &self.voice
{
@@ -1964,7 +1970,7 @@ impl Session {
self.streams = Some(streams);
self.feed_directory();
}
self.emit(Event::ServerInfo { session: self.id, name, flavor, capabilities });
self.emit(Event::ServerInfo { session: self.id, name, backend, capabilities });
self.reopen_relayed_chats();
self.open_histories();
}
@@ -2977,7 +2983,8 @@ mod banner_tests {
session.gateway = Some((session.next_generation(), tx));
let connected = || VoiceEvent::Connected {
name: "test".into(),
flavor: voelin_model::ServerFlavor::Unknown(String::new()),
backend: crate::BackendInfo::default(),
capabilities: voelin_model::Capabilities::default(),
own_client: 1,
server_uid: "server=".into(),
own_uid: None,
+73 -4
View File
@@ -26,7 +26,7 @@ use tsclientlib::{
};
use tsproto_packets::packets::{AudioData, CodecType, InAudioBuf, OutAudio, OutCommand, OutPacket};
use voelin_audio::{EncodedVoice, TalkerId, VoiceCodec, VoicePacket};
use voelin_model::{ChannelId, ChatMessage, ChatTarget, Presence, ServerFlavor};
use voelin_model::{Capabilities, ChannelId, ChatMessage, ChatTarget, Presence, ServerFlavor};
use voelin_stream::{PeerConfig, Request, StreamNotification};
use crate::book::presence_from_book;
@@ -34,7 +34,7 @@ use crate::cache;
use crate::files::{self, FileEntry, Report, RequestId, Sink, TransferId, TransferState};
use crate::offline::{OfflineMessage, OfflineMessageInfo};
use crate::settings::{FILES_PROGRESS_MS, SharedSettings};
use crate::{Event, JoinFailure, POKE_MESSAGE_MAX, SessionId};
use crate::{BackendInfo, Event, JoinFailure, POKE_MESSAGE_MAX, SessionId};
#[derive(Clone, Debug)]
pub struct VoiceOptions {
@@ -197,7 +197,10 @@ pub(crate) enum VoiceCmd {
pub(crate) enum VoiceEvent {
Connected {
name: String,
flavor: ServerFlavor,
/// The server software, and what it can do (the connection knows
/// both from the server's version).
backend: BackendInfo,
capabilities: Capabilities,
own_client: u16,
/// The server's unique id (from its public key, as the server
/// generation computes it).
@@ -227,6 +230,21 @@ pub(crate) enum VoiceEvent {
Disconnected(Option<String>),
}
/// What the engine is told of the server this connection reached: the
/// product and version to show, and what the product can do. The flavor
/// (TeamSpeak 3 or 6) is decided here, from the version the server sent, and
/// goes no further.
fn backend_of(flavor: &ServerFlavor) -> (BackendInfo, Capabilities) {
let (product, version) = match flavor {
ServerFlavor::Ts3(version) => ("TeamSpeak 3", version.to_string()),
ServerFlavor::Ts6(version) => ("TeamSpeak 6", version.to_string()),
// Not recognised: the version string as it came, for the status
// line and the log.
ServerFlavor::Unknown(raw) => ("", raw.clone()),
};
(BackendInfo { product: product.into(), version }, flavor.capabilities())
}
fn now_ms() -> i64 {
std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
@@ -479,9 +497,11 @@ async fn run_inner(
.get(&state.own_client)
.and_then(|c| c.uid.as_ref())
.map(|u| u.as_ref().to_string());
let (backend, capabilities) = backend_of(&flavor);
let _ = events.send(VoiceEvent::Connected {
name: state.server.name.clone(),
flavor,
backend,
capabilities,
own_client: state.own_client.0,
server_uid: server_uid.clone(),
own_uid,
@@ -1478,6 +1498,55 @@ mod audio_packet_tests {
}
}
#[cfg(test)]
mod backend_tests {
use super::*;
/// What a connection tells the engine about the server it reached: the
/// product and version the UI shows, and the capabilities the old flavor
/// carried through the event.
fn told(version: &str) -> (BackendInfo, Capabilities) {
backend_of(&ServerFlavor::from_version_string(version))
}
#[test]
fn a_teamspeak_3_server_is_named_with_its_capabilities() {
let (backend, capabilities) = told("3.13.8 [Build: 1779874471]");
assert_eq!(
backend,
BackendInfo { product: "TeamSpeak 3".into(), version: "3.13.8".into() }
);
assert_eq!(backend.label(), "TeamSpeak 3 3.13.8");
assert!(!capabilities.streams && capabilities.raw_query && capabilities.file_transfer);
}
#[test]
fn a_teamspeak_6_server_is_named_with_its_capabilities() {
let (backend, capabilities) = told("6.0.0-beta13.1 [Build: 1790080330]");
assert_eq!(
backend,
BackendInfo { product: "TeamSpeak 6".into(), version: "6.0.0-beta13.1".into() }
);
assert_eq!(backend.label(), "TeamSpeak 6 6.0.0-beta13.1");
assert!(capabilities.streams && !capabilities.raw_query && capabilities.http_query);
// The capabilities are the flavor's own.
assert_eq!(
capabilities,
ServerFlavor::from_version_string("6.0.0-beta13.1 [Build: 1790080330]").capabilities()
);
}
/// A version nobody recognises names no product: the status line shows
/// the string as the server sent it, and nothing is switched on.
#[test]
fn an_unrecognised_server_keeps_its_version_string_and_no_capabilities() {
let (backend, capabilities) = told("custom 9");
assert_eq!(backend, BackendInfo { product: String::new(), version: "custom 9".into() });
assert_eq!(backend.label(), "custom 9");
assert_eq!(capabilities, Capabilities::default());
}
}
#[cfg(test)]
mod join_tests {
use super::*;
+31 -9
View File
@@ -24,8 +24,8 @@ use voelin_core::settings::{
};
use voelin_core::stream::StreamInfo;
use voelin_core::{
AudioSettings, Command, Engine, Event, History, HistoryMessage, ObserveState, SessionState,
VoiceState,
AudioSettings, BackendInfo, Command, Engine, Event, History, HistoryMessage, ObserveState,
SessionState, VoiceState,
};
use voelin_model::{Capabilities, ChannelId, ChatMessage, ChatTarget, GroupInfo, Presence};
use voelin_platform::crash;
@@ -1143,16 +1143,11 @@ impl App {
}
self.join_after_connect(id);
}
Event::ServerInfo { session, name, flavor, capabilities } => {
Event::ServerInfo { session, name, backend, capabilities } => {
self.sessions.entry(session as i64).or_default().capabilities = capabilities;
self.adopt_server_name(session as i64, &name);
if self.current == Some(session as i64) {
let kind = match flavor {
voelin_model::ServerFlavor::Ts3(v) => format!("TeamSpeak 3 {v}"),
voelin_model::ServerFlavor::Ts6(v) => format!("TeamSpeak 6 {v}"),
voelin_model::ServerFlavor::Unknown(v) => v,
};
self.set_status(format!("Connected to {name} ({kind})"));
self.set_status(connected_status(&name, &backend));
}
self.refresh_streams();
self.autoshare();
@@ -1331,10 +1326,37 @@ impl App {
}
}
/// The status line once a server answered: "Connected to Nightfall Guild
/// (TeamSpeak 6 6.0.0-beta13.1)".
fn connected_status(name: &str, backend: &BackendInfo) -> String {
format!("Connected to {name} ({})", backend.label())
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn the_status_line_names_the_servers_software() {
let backend = |product: &str, version: &str| BackendInfo {
product: product.into(),
version: version.into(),
};
assert_eq!(
connected_status("Nightfall Guild", &backend("TeamSpeak 6", "6.0.0-beta13.1")),
"Connected to Nightfall Guild (TeamSpeak 6 6.0.0-beta13.1)"
);
assert_eq!(
connected_status("Pixel Lounge", &backend("TeamSpeak 3", "3.13.8")),
"Connected to Pixel Lounge (TeamSpeak 3 3.13.8)"
);
// Not recognised: the version string the server sent.
assert_eq!(
connected_status("Home", &backend("", "custom 9")),
"Connected to Home (custom 9)"
);
}
#[test]
fn channel_unread_ignores_private_tabs() {
let mut view = SessionView::default();
+42 -7
View File
@@ -70,8 +70,8 @@ use slint::{ComponentHandle, Rgba8Pixel, SharedPixelBuffer};
use voelin_core::gateway::Pin;
use voelin_core::stream::{StreamInfo, StreamKind};
use voelin_core::{
Contact, Event, GatewayUpdate, HistoryMessage, HistorySource, JoinFailure, ObserveState,
OfflineMessageInfo, Relation, SessionState, Source, VoiceState,
BackendInfo, Contact, Event, GatewayUpdate, HistoryMessage, HistorySource, JoinFailure,
ObserveState, OfflineMessageInfo, Relation, SessionState, Source, VoiceState,
};
use voelin_gateway_proto::{
Action, Attendee, ConfigEntry, ConfigSource, EventInfo, EventKind, EventSpec, PermRule,
@@ -79,7 +79,7 @@ use voelin_gateway_proto::{
feature,
};
use voelin_model::{
BannerMode, ChannelInfo, ChatMessage, ChatTarget, ClientInfo, GroupInfo, Presence, ServerFlavor,
BannerMode, Capabilities, ChannelInfo, ChatMessage, ChatTarget, ClientInfo, GroupInfo, Presence,
};
use voelin_store::{Bookmark, MessageSource};
@@ -501,6 +501,26 @@ fn open_channel_password(app: &mut App, wrong: bool) {
const DEMO: i64 = 9001;
/// The software of the sample voice server, as a link reports it, and what
/// that software can do (streams, files, offline messages).
fn demo_teamspeak_6() -> (BackendInfo, Capabilities) {
let backend = BackendInfo { product: "TeamSpeak 6".into(), version: "6.0.0-beta13.1".into() };
let capabilities = Capabilities {
streams: true,
raw_query: false,
ssh_query: true,
http_query: true,
file_transfer: true,
offline_messages: true,
};
(backend, capabilities)
}
/// The software of the sample server seen through a gateway.
fn demo_teamspeak_3() -> BackendInfo {
BackendInfo { product: "TeamSpeak 3".into(), version: "3.13.8".into() }
}
fn channel(id: u64, parent: u64, order: u64, name: &str) -> ChannelInfo {
ChannelInfo { id, parent, order, name: name.into(), ..Default::default() }
}
@@ -641,10 +661,9 @@ fn demo_ui(app: &mut App) {
sort_id,
..Default::default()
};
let flavor = ServerFlavor::from_version_string("6.0.0-beta13.1 [Build: 1]");
let capabilities = flavor.capabilities();
let (backend, capabilities) = demo_teamspeak_6();
let events = [
Event::ServerInfo { session, name: "Nightfall Guild".into(), flavor, capabilities },
Event::ServerInfo { session, name: "Nightfall Guild".into(), backend, capabilities },
Event::Groups {
session,
server_groups: Arc::new(vec![
@@ -756,7 +775,7 @@ fn demo_social(app: &mut App) {
app.handle_event(Event::ServerInfo {
session: session + 1,
name: "Pixel Lounge".into(),
flavor: ServerFlavor::from_version_string("3.13.8 [Build: 1]"),
backend: demo_teamspeak_3(),
capabilities: Default::default(),
});
@@ -1893,6 +1912,22 @@ pub(crate) fn answer_older(session: i64, target: ChatTarget, oldest: Option<Hist
mod tests {
use super::*;
/// The sample servers say what they run, as they did when the engine told
/// a flavor: the home page's chip reads the product, the status line the
/// product and version, and the sample voice server keeps the
/// capabilities of a TeamSpeak 6 server (its streams).
#[test]
fn demo_servers_name_their_software() {
let (backend, capabilities) = demo_teamspeak_6();
assert_eq!(backend.product, "TeamSpeak 6");
assert_eq!(backend.label(), "TeamSpeak 6 6.0.0-beta13.1");
let flavor = voelin_model::ServerFlavor::from_version_string("6.0.0-beta13.1 [Build: 1]");
assert_eq!(capabilities, flavor.capabilities());
let backend = demo_teamspeak_3();
assert_eq!(backend.product, "TeamSpeak 3");
assert_eq!(backend.label(), "TeamSpeak 3 3.13.8");
}
/// Two pages back from the sample chat's first message, each older than
/// the one before, the second one the last.
#[test]
+2 -2
View File
@@ -466,9 +466,9 @@ impl App {
.filter(|v| !v.presence.channels.is_empty())
.map(|v| vm::tree::stats(&v.presence))
.unwrap_or_default();
let flavor = view.map(|v| v.extra.flavor.clone()).unwrap_or_default();
let product = view.map(|v| v.extra.product.clone()).unwrap_or_default();
let icon = self.server_list_icon(b);
vm::servers::item(b, &state, unread, live, detail, flavor, icon, tint)
vm::servers::item(b, &state, unread, live, detail, product, icon, tint)
})
.collect();
vm::list::sync(&self.models.servers, &items);
+6 -8
View File
@@ -56,8 +56,9 @@ pub(crate) struct SessionExtra {
/// When this session's presence first came (ms): friends found in it
/// then are not "coming online".
pub presence_since: i64,
/// "TeamSpeak 6", "TeamSpeak 3" once the server told its version.
pub flavor: String,
/// "TeamSpeak 6", "TeamSpeak 3" once the server told what it runs;
/// empty before that, and for software nobody recognised.
pub product: String,
}
/// A poke we got.
@@ -785,12 +786,9 @@ impl App {
touched.people = true;
touched.home = true;
}
Event::ServerInfo { session, flavor, .. } => {
self.sessions.entry(*session as i64).or_default().extra.flavor = match flavor {
voelin_model::ServerFlavor::Ts3(_) => "TeamSpeak 3".into(),
voelin_model::ServerFlavor::Ts6(_) => "TeamSpeak 6".into(),
voelin_model::ServerFlavor::Unknown(_) => String::new(),
};
Event::ServerInfo { session, backend, .. } => {
self.sessions.entry(*session as i64).or_default().extra.product =
backend.product.clone();
touched.people = true;
touched.home = true;
}
+25 -3
View File
@@ -65,7 +65,7 @@ pub fn status(state: &SessionState) -> &'static str {
/// A server of the rail and the home page. `unread`: messages in its
/// chats; `live`: streams on it; `detail`: who is there ("9 online · 7
/// channels"), empty for its address; `flavor`: "TeamSpeak 6" once
/// channels"), empty for its address; `product`: "TeamSpeak 6" once
/// reached; `icon`: the server's icon (empty: its initials) on `tint`
/// ([`tints`]).
#[allow(clippy::too_many_arguments)]
@@ -75,7 +75,7 @@ pub fn item(
unread: i32,
live: bool,
detail: String,
flavor: String,
product: String,
icon: slint::Image,
tint: Color,
) -> ServerItem {
@@ -90,7 +90,7 @@ pub fn item(
unread,
live,
detail: if detail.is_empty() { bookmark.address.clone() } else { detail }.into(),
flavor: flavor.into(),
product: product.into(),
gateway: bookmark.gateway_url.is_some() || bookmark.query.is_some(),
}
}
@@ -314,6 +314,28 @@ mod tests {
std::fs::remove_dir_all(dir).unwrap();
}
/// The chip of a server reads the product its session reported.
#[test]
fn a_server_shows_the_product_it_runs() {
let bookmark = Bookmark { address: "example.test".into(), ..Default::default() };
let state = SessionState::default();
let on = |product: &str| {
item(
&bookmark,
&state,
0,
false,
String::new(),
product.into(),
Default::default(),
Color::default(),
)
};
assert_eq!(on("TeamSpeak 6").product.as_str(), "TeamSpeak 6");
// Before the server answered, and for software nobody recognised: none.
assert_eq!(on("").product.as_str(), "");
}
fn named(names: &[&str]) -> Vec<Bookmark> {
names.iter().map(|n| Bookmark { name: (*n).into(), ..Default::default() }).collect()
}
+1 -1
View File
@@ -20,7 +20,7 @@ export struct ServerItem {
// "9 online · 7 channels" while its presence is known, else the address.
detail: string,
// "TeamSpeak 6", "TeamSpeak 3", "" before it was reached.
flavor: string,
product: string,
// Gateway or query credentials: presence without joining.
gateway: bool,
}
+2 -2
View File
@@ -534,8 +534,8 @@ component ServerCard inherits Rectangle {
spacing: Theme.space-2;
alignment: start;
padding-top: Theme.space-1;
if root.server.flavor != "": Chip {
text: root.server.flavor;
if root.server.product != "": Chip {
text: root.server.product;
outlined: true;
}
if root.server.gateway: Chip {
+15
View File
@@ -87,6 +87,21 @@ the native command only when voice-connected *and* in that channel, otherwise th
gateway, otherwise a local query relay. UI states: `Offline`,
`Observing (Gateway|Query)` (invisible), `Connecting`, `Connected`.
## What the engine tells of the server's software
`Event::ServerInfo { session, name, backend, capabilities }` is the one place
the UI learns what it is talking to. `backend` is a `BackendInfo { product,
version }` of plain strings ("TeamSpeak 6", "6.0.0-beta13.1"; an empty
`product` and the server's own version string when the software was not
recognised), and `capabilities` is what that software can do (streams, query
kinds, files, offline messages). The UI shows `product` on a server's chip
and `BackendInfo::label()` in the status line, and branches on capabilities
only. The TeamSpeak 3 / 6 classification (`voelin_model::ServerFlavor`, from
the `virtualserver_version` string) happens in the voice source
(`voice.rs::backend_of`), which puts both in `VoiceEvent::Connected`; no
`ServerFlavor` appears in the engine's public API, so another link (a Voelin
server) can fill the same two fields.
## Chat history
Every chat message a session sees is stored in the client database
+2 -2
View File
@@ -236,8 +236,8 @@ pub async fn run(args: GatewayArgs) -> Result<()> {
Event::Presence { session: SESSION, presence } => {
nicknames = presence.clients.values().map(|c| (c.id, c.nickname.clone())).collect();
}
Event::ServerInfo { session: SESSION, name, flavor, .. } => {
out.print(format!("server {name:?} {flavor:?}"));
Event::ServerInfo { session: SESSION, name, backend, .. } => {
out.print(format!("server {name:?} {}", backend.label()));
}
Event::StreamsChanged { session: SESSION, streams } => {
for s in &streams {