diff --git a/crates/voelin-core/src/link.rs b/crates/voelin-core/src/link.rs index 81a06fc..52369ad 100644 --- a/crates/voelin-core/src/link.rs +++ b/crates/voelin-core/src/link.rs @@ -20,9 +20,19 @@ //! then [`LinkEvent::Presence`] whenever anything in the server's tree or //! client list changed (a full snapshot each time) and //! [`LinkEvent::OwnChannel`] when we moved. -//! - The last event is [`LinkEvent::Disconnected`], with the reason if it was -//! not asked for, whichever way the connection ended. A link that gets -//! [`LinkCmd::Disconnect`] (or whose command channel closes) leaves. +//! - [`LinkEvent::Disconnected`], with the reason if it was not asked for, +//! reports that the connection ended, whichever way it did; a link sends it +//! once, and nothing from the connection itself follows it. A link that +//! gets [`LinkCmd::Disconnect`] (or whose command channel closes) leaves. +//! It is not promised to be the last event of the link: the stream task of +//! a connection with streams is a task of its own, which winds down after +//! the connection, so [`LinkEvent::OwnStream`] (`Ended`) and +//! [`LinkEvent::StreamAudioEnded`] from it, and the bus events of its +//! streams, may follow `Disconnected` (`TsLink` ends the stream task as the +//! connection's loop ends, which usually, not always, puts them before it). +//! The session does not depend on the order: it ends our own stream and +//! the audio of watched streams itself when it hears `Disconnected`, and +//! ignores what a link says after that, like the events of a replaced one. //! - Streams (screen sharing) are the link's business from the capabilities //! on: when [`Capabilities::streams`] is set in `Connected`, it runs the //! stream task, takes [`LinkCmd::Stream`] and reports through the event @@ -30,7 +40,11 @@ //! session first (file lists, transfers, offline messages, stream state). //! What the session must place itself comes as events: our own stream's //! life ([`LinkEvent::OwnStream`], for the gateway directory) and the audio -//! of watched streams ([`LinkEvent::StreamAudio`], for the audio thread). +//! of watched streams ([`LinkEvent::StreamAudio`], for the audio thread, +//! and [`LinkEvent::StreamAudioEnded`] when a stream's audio is over). +//! When the session replaces a connection it gives the old link +//! `StreamCmd::Shutdown` before [`LinkCmd::Disconnect`] (the streams hear +//! of their end before the link stops reading commands). //! - What the session must see first (chat, pokes, who is talking, audio) //! comes as [`LinkEvent`]s; the answers to requests the UI made (a file //! list, a request's `Done`) go straight to the event bus with @@ -49,9 +63,28 @@ //! the Voelin protocol's QUIC transport becomes the other implementation, //! both behind the backend-neutral `voelin_proto::link::Session` of //! VoelinProtocol; `ServerLink` is this crate's side of that seam until then. -//! Two fields of the types here still carry TeamSpeak types: the identity and -//! version in [`ConnectOptions`] and the account proof in [`LinkCtx`]; they -//! leave with `TsLink`. +//! +//! # What is still TeamSpeak's +//! +//! The seam is not backend-neutral yet. What still has TeamSpeak types or +//! TeamSpeak's shape, and changes when `TsLink` leaves: +//! +//! - Types of the TeamSpeak crates: [`ConnectOptions::identity`] and +//! [`ConnectOptions::client_version`] (`tsclientlib`), and the account +//! proof in [`LinkCtx`] (`myts_identity` of `tsproto`, `myts_data` of +//! `tsclientlib`). +//! - Client ids are TeamSpeak's `u16`: `own_client` of +//! [`LinkEvent::Connected`], `from` of [`LinkEvent::Poke`], `client` of +//! [`LinkEvent::Talking`] and of [`LinkCmd::Poke`], the `author_id` of a +//! [`ChatMessage`], and the viewer and streamer ids of the stream API. +//! - [`LinkEvent::Presence`] snapshots have TeamSpeak's shape: `u16` client +//! ids, `u64` channel and group ids, server and channel groups, talk +//! power, icons, badges and the myTeamSpeak avatar. +//! - The stream vocabulary is that of `voelin-stream`, the TeamSpeak 6 stream +//! protocol: `PeerConfig` in [`ConnectOptions::stream_peer`], `MediaFrame` +//! in the frames of watched streams ([`LinkCtx`]), `VideoFormat` in +//! `StreamCmd::VideoFrame`, and `VideoCodec` and `FrameSource` of the same +//! API (re-exported from [`crate::stream`]). use std::path::PathBuf; use std::sync::Arc; @@ -73,7 +106,7 @@ use crate::{BackendInfo, Event, SessionId}; pub trait ServerLink: Send + Sync + 'static { /// Connect to the server `options` names and run the connection on its /// own task: take commands from `cmds`, report through `events`, and end - /// with [`LinkEvent::Disconnected`]. Does not block. + /// the connection with [`LinkEvent::Disconnected`]. Does not block. fn spawn( &self, options: ConnectOptions, @@ -290,6 +323,8 @@ pub enum LinkEvent { StreamAudioEnded(String), /// A command failed (the connection stays). Error(String), - /// The connection ended; the reason if it was not asked for. The last event. + /// The connection ended; the reason if it was not asked for. Sent once; + /// the stream task's closing reports may still follow (see the module + /// documentation). Disconnected(Option), } diff --git a/docs/architecture.md b/docs/architecture.md index 2eaeb38..58daaef 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -107,7 +107,16 @@ task and returns: `Capabilities`, our client id, the server's unique id), `Presence` (a full snapshot each time), `OwnChannel`, `Chat`, `Poke`, `Audio` (a received `VoicePacket`), `Talking`, `OwnStream`, `StreamAudio` (the audio of a watched - stream, for the audio thread's mixer), `Error` and, last, `Disconnected`. + stream, for the audio thread's mixer), `StreamAudioEnded` (that stream's + audio is over), `Error` and `Disconnected`. `Disconnected` ends the + connection and is sent once, but it is not promised to be the last event: + the stream task of a connection winds down after the connection, so its + closing `OwnStream(Ended)` and `StreamAudioEnded` (and the bus events of + its streams) may follow it. `TsLink` ends the stream task as the + connection's loop ends, which usually puts them first, not always. The + session does not depend on it: on `Disconnected` it ends our own stream and + the audio of watched streams itself, and what the link says after that is + ignored like the events of a replaced link. Everything backend-neutral stays in `session.rs`: merging the three sources, the dedup of a message that arrives twice, the chat history, contacts, the @@ -136,10 +145,24 @@ in-process TeamSpeak gateway), and the QUIC transport of VoelinProtocol becomes the other implementation, both behind the backend-neutral `voelin_proto::link::Session` that the protocol spec defines (the spec replaces `voelin_core::link::ServerLink` by it, because the gateway -implements the trait and the client depends on the gateway). What still has -TeamSpeak types in the seam, and leaves with `TsLink`: the identity and -version in `ConnectOptions`, the myTeamSpeak account proof in `LinkCtx`, and the -peer and media vocabulary of the stream API (below). +implements the trait and the client depends on the gateway). The seam is not +backend-neutral yet. What still has TeamSpeak types, or TeamSpeak's shape, and +changes when `TsLink` leaves: + +- `ConnectOptions.identity` and `ConnectOptions.client_version` + (`tsclientlib` types), and the myTeamSpeak account proof in `LinkCtx` + (`myts_identity` of `tsproto`, `myts_data` of `tsclientlib`); +- client ids are TeamSpeak's `u16`: our own in `Connected`, `Poke` and + `Talking`, `LinkCmd::Poke`, a chat message's `author_id`, and the viewer + and streamer ids of the stream API; +- the `Presence` snapshots: `u16` client ids, `u64` channel and group ids, + server and channel groups, talk power, icons, badges, the myTeamSpeak + avatar; +- the stream vocabulary of `voelin-stream` (the TeamSpeak 6 stream + protocol): `PeerConfig` in `ConnectOptions.stream_peer`, `MediaFrame` in + the frames of watched streams, `VideoFormat` in `StreamCmd::VideoFrame`, + and `VideoCodec` and `FrameSource`, which `voelin_core::stream` + re-exports with them (see Streams, below). ## What the engine tells of the server's software