From 2b1185f84d300df3f140309b8f22466a12938439 Mon Sep 17 00:00:00 2001 From: selikhov Date: Sun, 4 Oct 2026 03:01:21 +0300 Subject: [PATCH] voelin-ui: watch a streaming user's stream from the channel list The user asked to click a user who streams in the channel list and join their stream. Three ways now: - The LIVE mark on a streaming user's row in the channel tree joins the stream at once (a button for screen readers too). - Clicking the user opens their dialog as before; while they stream it offers "Watch 's stream". - The member card offers "Watch stream" too. All go through `watch_client`: it watches the user's stream when it is known, and otherwise (a stream that started before we joined or in another channel, still being looked up) remembers the request and starts watching as soon as `StreamsChanged` brings the stream. Co-Authored-By: Claude Opus 5.5 --- crates/voelin-ui/src/app.rs | 4 +++ crates/voelin-ui/src/bind/streams.rs | 5 ++++ crates/voelin-ui/src/members.rs | 5 ++++ crates/voelin-ui/src/settings_page.rs | 1 + crates/voelin-ui/src/streams.rs | 32 +++++++++++++++++++++- crates/voelin-ui/ui/bridge.slint | 7 +++++ crates/voelin-ui/ui/screens/channels.slint | 19 ++++++++++++- crates/voelin-ui/ui/screens/dialogs.slint | 9 ++++++ crates/voelin-ui/ui/screens/members.slint | 7 +++++ 9 files changed, 87 insertions(+), 2 deletions(-) diff --git a/crates/voelin-ui/src/app.rs b/crates/voelin-ui/src/app.rs index d0d26b3..8c39b0e 100644 --- a/crates/voelin-ui/src/app.rs +++ b/crates/voelin-ui/src/app.rs @@ -388,6 +388,9 @@ pub(crate) struct App { pub share_error: String, /// The stream in the viewer. pub watch: Option, + /// A client whose stream was asked for before it was known (session, + /// client): watched when the lookup brings it. + pub pending_watch: Option<(i64, u16)>, /// Stream volume in percent, kept between streams. pub stream_volume: f32, /// `VOELIN_DEMO_STREAM`: the viewer shows a local test stream. @@ -595,6 +598,7 @@ pub fn run(options: RunOptions) -> Result<()> { share_busy: false, share_error: String::new(), watch: None, + pending_watch: None, stream_volume: 100.0, demo: switches.demo_stream, demo_ui: switches.demo_ui, diff --git a/crates/voelin-ui/src/bind/streams.rs b/crates/voelin-ui/src/bind/streams.rs index 936e4b2..3502e04 100644 --- a/crates/voelin-ui/src/bind/streams.rs +++ b/crates/voelin-ui/src/bind/streams.rs @@ -22,6 +22,11 @@ pub(super) fn wire(ui: &MainWindow) { bridge.on_watch_stream(|id| { with_app(|app| app.watch_stream(id.to_string())); }); + bridge.on_watch_client(|client| { + if let Ok(client) = u16::try_from(client) { + with_app(|app| app.watch_client(client)); + } + }); bridge.on_show_viewer(|| { with_app(|app| app.show_viewer(true)); }); diff --git a/crates/voelin-ui/src/members.rs b/crates/voelin-ui/src/members.rs index 7928102..4aa3b2a 100644 --- a/crates/voelin-ui/src/members.rs +++ b/crates/voelin-ui/src/members.rs @@ -70,6 +70,7 @@ impl App { volume: playback.volume * 100.0, muted: playback.muted, known: uid.is_some(), + streaming: client.streaming == Some(true), }) }) .unwrap_or_default(); @@ -91,6 +92,10 @@ impl App { self.open_member(-1); } } + "watch" => { + self.open_member(-1); + self.watch_client(client_id); + } "poke" => { self.command(|session| Command::Poke { session, diff --git a/crates/voelin-ui/src/settings_page.rs b/crates/voelin-ui/src/settings_page.rs index 260623f..b0c9bb3 100644 --- a/crates/voelin-ui/src/settings_page.rs +++ b/crates/voelin-ui/src/settings_page.rs @@ -207,6 +207,7 @@ impl App { name: info.nickname.into(), volume: playback.volume * 100.0, muted: playback.muted, + streaming: info.streaming == Some(true), }); } true diff --git a/crates/voelin-ui/src/streams.rs b/crates/voelin-ui/src/streams.rs index ebd449c..085d832 100644 --- a/crates/voelin-ui/src/streams.rs +++ b/crates/voelin-ui/src/streams.rs @@ -179,10 +179,19 @@ impl App { .iter() .find(|s| view.state.own_client != Some(s.streamer.0)) .map(|s| s.id.clone()); + // A client whose stream was asked for while it was looked up. + let pending = self + .pending_watch + .filter(|(s, _)| *s == session as i64) + .and_then(|(_, client)| streams.iter().find(|s| s.streamer.0 == client)) + .map(|s| s.id.clone()); view.streams = streams; self.refresh_streams(); self.refresh_servers(); - if autowatch && let Some(id) = first { + if let Some(id) = pending { + self.pending_watch = None; + self.watch_stream(id); + } else if autowatch && let Some(id) = first { self.watch_stream(id); } } @@ -763,6 +772,27 @@ impl App { self.refresh_tree(); } + /// Watch the stream of `client` (a click on a streaming user in the + /// channel tree or the members): at once if it is known, else as soon as + /// the lookup brings it (it may have started in another channel or + /// before we joined). + pub(crate) fn watch_client(&mut self, client: u16) { + let Some(session) = self.current else { return }; + let Some(view) = self.sessions.get(&session) else { return }; + if view.state.own_client == Some(client) { + return; + } + if let Some(id) = view.streams.iter().find(|s| s.streamer.0 == client).map(|s| s.id.clone()) + { + self.pending_watch = None; + self.watch_stream(id); + } else if view.presence.clients.get(&client).is_some_and(|c| c.streaming == Some(true)) { + let name = view.nickname(client); + self.pending_watch = Some((session, client)); + self.set_status(format!("Looking up {name}'s stream…")); + } + } + /// `VOELIN_OPEN=watch`: watch the first stream of our channel. pub(crate) fn watch_first_stream(&mut self) { let Some(id) = self.view().and_then(|v| { diff --git a/crates/voelin-ui/ui/bridge.slint b/crates/voelin-ui/ui/bridge.slint index 1265383..ea7fe46 100644 --- a/crates/voelin-ui/ui/bridge.slint +++ b/crates/voelin-ui/ui/bridge.slint @@ -105,6 +105,8 @@ export struct MemberCard { muted: bool, // The client has a unique id, so contacts and private chats work. known: bool, + // The client streams: the card offers to watch it. + streaming: bool, } export struct ChatTab { @@ -299,6 +301,8 @@ export struct ClientAudio { name: string, volume: float, muted: bool, + // The client streams: the dialog offers to watch it. + streaming: bool, } // The appearance settings (`ui.*` keys). @@ -489,6 +493,9 @@ export global Bridge { callback respond-viewer(int, bool); callback kick-viewer(int); callback watch-stream(string); + // Watch the stream of a client (a streaming user in the tree or the + // members), as soon as it is known. + callback watch-client(int); callback show-viewer(); callback hide-viewer(); callback leave-stream(); diff --git a/crates/voelin-ui/ui/screens/channels.slint b/crates/voelin-ui/ui/screens/channels.slint index 79aec82..4e85959 100644 --- a/crates/voelin-ui/ui/screens/channels.slint +++ b/crates/voelin-ui/ui/screens/channels.slint @@ -226,9 +226,26 @@ component TreeRow inherits Rectangle { alignment: center; SpeakingBars { } } + // A click on someone's LIVE mark watches their stream. if item.streaming: VerticalLayout { alignment: center; - LiveBadge { } + LiveBadge { + accessible-role: AccessibleRole.button; + accessible-label: item.myself ? @tr("Your stream") : @tr("Watch {}'s stream", item.name); + accessible-action-default => { + if !item.myself { + Bridge.watch-client(item.id); + } + } + TouchArea { + mouse-cursor: item.myself ? MouseCursor.default : MouseCursor.pointer; + clicked => { + if !item.myself { + Bridge.watch-client(item.id); + } + } + } + } } if item.local-muted: Icon { source: Icons.volume-x; diff --git a/crates/voelin-ui/ui/screens/dialogs.slint b/crates/voelin-ui/ui/screens/dialogs.slint index 99cb8cf..d4c22d8 100644 --- a/crates/voelin-ui/ui/screens/dialogs.slint +++ b/crates/voelin-ui/ui/screens/dialogs.slint @@ -499,6 +499,15 @@ export component ClientAudioDialog inherits Modal { Bridge.client-audio-changed(Bridge.client-audio); } } + if Bridge.client-audio.streaming: Button { + kind: ButtonKind.primary; + icon: Icons.monitor; + text: @tr("Watch {}'s stream", Bridge.client-audio.name); + clicked => { + Bridge.watch-client(Bridge.client-audio.id); + done(); + } + } Rectangle { vertical-stretch: 1; } Footer { Button { diff --git a/crates/voelin-ui/ui/screens/members.slint b/crates/voelin-ui/ui/screens/members.slint index f17eab5..39429cc 100644 --- a/crates/voelin-ui/ui/screens/members.slint +++ b/crates/voelin-ui/ui/screens/members.slint @@ -308,6 +308,13 @@ export component MemberCardPopup inherits Rectangle { } } Divider { } + if Bridge.member-card.streaming: Button { + small: true; + kind: ButtonKind.primary; + icon: Icons.monitor; + text: @tr("Watch stream"); + clicked => { Bridge.member-action("watch"); } + } HorizontalLayout { spacing: Theme.space-2; Button {