Find TeamSpeak 6 streams that started before we joined
The server announces a stream (notifystreamstarted) only to the clients in the streamer's channel when it starts. A client that connects or enters the channel later saw the streamer's client_is_streaming flag but could not watch. The probe (docs/research/ts6-late-join.md) found that `requeststreaminfo clid=<streamer>` answers with notifystreaminfo, one part per stream of the client, from any channel. voelin-stream gets a discovery module. Streams::update_clients takes the clients on the server (channel and streaming flag), keeps the directory to the streams in our channel, and looks up the streams of streamers in our channel we were not told about: after connecting, after we or they change channels, and when an announcement did not come. The answer fills the directory like an announcement, so Event::StreamsChanged lists the stream and it is watched like any other. Where streams are looked up is a StreamLookup trait (the server now; a gateway directory can plug in with Streams::add_lookup and report through Streams::discovered). notifystreamupdated (updatestream) now updates the directory. The engine and `voelinctl stream list/watch` feed the client list in. The declarations learn the notifystreaminfo answer's fields, notifystreamupdated and requeststreaminfo. Tests: a fake-server session test and an engine live test with a viewer that arrives after the stream is live, discovery unit tests, parsing of the server's answers; it-smoke gets a late-viewer step. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NJvYyRmTjKcb9i8eyYXK5G
This commit is contained in:
1 parent
1fa6095a5f
commit
90c23362ef
15 files changed
+977
-76
No files matched your search
@@ -8,6 +8,7 @@ use tracing::debug;
|
||||
use tsclientlib::ClientId;
|
||||
use voelin_audio::AudioSettings;
|
||||
use voelin_model::{ChatMessage, ChatTarget, Presence};
|
||||
use voelin_stream::ClientState;
|
||||
|
||||
use crate::audio::{self, AudioEvent, AudioHandle, AudioIn};
|
||||
use crate::gateway::{self, GatewayCmd, GatewayEvent};
|
||||
@@ -66,8 +67,9 @@ struct Session {
|
||||
streams: Option<StreamHandle>,
|
||||
stream_peer: PeerConfig,
|
||||
frames: broadcast::Sender<StreamFrame>,
|
||||
/// `client_is_streaming` of the voice presence, as last told to the streams.
|
||||
streaming_clients: BTreeMap<u16, Option<bool>>,
|
||||
/// Channel and `client_is_streaming` of the voice presence, as last told
|
||||
/// to the streams.
|
||||
streaming_clients: BTreeMap<u16, ClientState>,
|
||||
open_chats: HashSet<ChatTarget>,
|
||||
dedup: Dedup,
|
||||
sources_tx: mpsc::UnboundedSender<SourceEvent>,
|
||||
@@ -460,8 +462,11 @@ impl Session {
|
||||
}
|
||||
}
|
||||
if let Some(s) = &self.streams {
|
||||
let clients: BTreeMap<_, _> =
|
||||
p.clients.values().map(|c| (c.id, c.streaming)).collect();
|
||||
let clients: BTreeMap<_, _> = p
|
||||
.clients
|
||||
.values()
|
||||
.map(|c| (c.id, ClientState { channel: c.channel, streaming: c.streaming }))
|
||||
.collect();
|
||||
if clients != self.streaming_clients {
|
||||
self.streaming_clients = clients.clone();
|
||||
s.send(StreamInput::Clients(clients));
|
||||
|
||||
@@ -12,15 +12,15 @@ use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use tokio::sync::{broadcast, mpsc};
|
||||
use tracing::debug;
|
||||
use tsclientlib::ClientId;
|
||||
use voelin_stream::{
|
||||
ClientState, Output, Request, StreamEvent, StreamNotification, StreamerEvent, StreamerOptions,
|
||||
Streams, WatchEvent,
|
||||
};
|
||||
pub use voelin_stream::{
|
||||
Codec, EncodedFrame, EndReason, FrameSource, Frequency, LeaveReason, MediaFrame, MediaKind,
|
||||
MediaTime, PeerConfig, StreamInfo, StreamKind, StreamSetup, SyntheticSource, VideoCodec,
|
||||
ViewerInfo, ViewerState,
|
||||
};
|
||||
use voelin_stream::{
|
||||
Output, Request, StreamEvent, StreamNotification, StreamerEvent, StreamerOptions, Streams,
|
||||
WatchEvent,
|
||||
};
|
||||
|
||||
use crate::audio::{AudioHandle, AudioIn};
|
||||
use crate::voice::VoiceCmd;
|
||||
@@ -135,8 +135,8 @@ pub(crate) enum StreamInput {
|
||||
Frame(EncodedFrame),
|
||||
Notification(StreamNotification),
|
||||
RequestFailed(Request, String),
|
||||
/// Clients on the server with their `client_is_streaming`.
|
||||
Clients(BTreeMap<u16, Option<bool>>),
|
||||
/// Clients on the server: channel and `client_is_streaming`.
|
||||
Clients(BTreeMap<u16, ClientState>),
|
||||
/// The voice connection is gone.
|
||||
Shutdown(String),
|
||||
}
|
||||
@@ -165,7 +165,6 @@ impl StreamHandle {
|
||||
audio,
|
||||
tx: tx.clone(),
|
||||
sink: None,
|
||||
clients: BTreeMap::new(),
|
||||
};
|
||||
tokio::spawn(task.run(rx));
|
||||
Self { tx }
|
||||
@@ -188,8 +187,6 @@ struct StreamTask {
|
||||
tx: mpsc::UnboundedSender<StreamInput>,
|
||||
/// The sink of our live stream.
|
||||
sink: Option<StreamSink>,
|
||||
/// Clients on the server and their `client_is_streaming`.
|
||||
clients: BTreeMap<u16, Option<bool>>,
|
||||
}
|
||||
|
||||
impl StreamTask {
|
||||
@@ -250,19 +247,9 @@ impl StreamTask {
|
||||
Ok(())
|
||||
}
|
||||
StreamInput::Clients(clients) => {
|
||||
// Streams of clients that left or stopped streaming are gone.
|
||||
// Only changes count: a snapshot may predate the streaming flag
|
||||
// of a stream that was just announced.
|
||||
for (client, streaming) in &clients {
|
||||
let was = self.clients.get(client).copied().flatten();
|
||||
if let (Some(was), Some(now)) = (was, *streaming)
|
||||
&& was != now
|
||||
{
|
||||
self.streams.set_client_streaming(ClientId(*client), now);
|
||||
}
|
||||
}
|
||||
self.streams.retain_streamers(|c| clients.contains_key(&c.0));
|
||||
self.clients = clients;
|
||||
// Streams of clients that left, stopped streaming or are not
|
||||
// in our channel are gone; unannounced ones are looked up.
|
||||
self.streams.update_clients(clients);
|
||||
Ok(())
|
||||
}
|
||||
StreamInput::Shutdown(_) => Ok(()),
|
||||
@@ -433,6 +420,7 @@ mod tests {
|
||||
Request::RemoveViewer { id, viewer, reason } => {
|
||||
both(StreamNotification::ViewerLeft { id, viewer, reason: Some(reason) })
|
||||
}
|
||||
Request::StreamInfo { .. } => Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user