diff --git a/crates/voelin-ui/src/app.rs b/crates/voelin-ui/src/app.rs index 2b44e19..cab0dc7 100644 --- a/crates/voelin-ui/src/app.rs +++ b/crates/voelin-ui/src/app.rs @@ -208,6 +208,8 @@ pub(crate) struct SessionView { pub gateway_caps: Vec, /// The client whose member card is open. pub member_card: Option, + /// Viewers of the streams in the gateway's directory, by stream id. + pub stream_viewers: HashMap, /// Downloads started from chat, by transfer id. pub downloads: HashMap, /// The next transfer id. @@ -232,6 +234,7 @@ impl Default for SessionView { server_groups: Vec::new(), gateway_caps: Vec::new(), member_card: None, + stream_viewers: HashMap::new(), downloads: HashMap::new(), next_transfer: 1, } diff --git a/crates/voelin-ui/src/chat.rs b/crates/voelin-ui/src/chat.rs index b2a8ba6..84030c8 100644 --- a/crates/voelin-ui/src/chat.rs +++ b/crates/voelin-ui/src/chat.rs @@ -497,6 +497,23 @@ impl App { self.set_status(format!("{request}: {message}")); return; } + // The stream directory: how many watch each stream. + GatewayUpdate::Streams { streams } => { + view.stream_viewers = streams.iter().filter_map(viewers_of).collect(); + return self.stream_viewers_changed(current); + } + GatewayUpdate::StreamStarted { stream } + | GatewayUpdate::StreamUpdated { stream } + | GatewayUpdate::StreamRegistered { stream } => { + if let Some((id, viewers)) = viewers_of(&stream) { + view.stream_viewers.insert(id, viewers); + } + return self.stream_viewers_changed(current); + } + GatewayUpdate::StreamEnded { id, .. } => { + view.stream_viewers.remove(&id); + return self.stream_viewers_changed(current); + } // Posts, pins and reactions also arrive as stored messages. _ => return, } @@ -505,6 +522,13 @@ impl App { } } + fn stream_viewers_changed(&self, current: bool) { + if current { + self.refresh_streams(); + self.refresh_viewer(); + } + } + /// The message a Slint row stands for, in the current chat. fn message_of(&self, key: i32) -> Option<&HistoryMessage> { let view = self.view()?; @@ -717,6 +741,11 @@ impl App { } } +/// A directory entry's stream id and viewer count, when it has both. +fn viewers_of(entry: &voelin_gateway_proto::StreamEntry) -> Option<(String, u32)> { + Some((entry.stream_id.clone()?, entry.viewers?)) +} + fn pin_row(key: i32, pin: Pin) -> PinRow { PinRow { key, message: pin.message, by: pin.by.name, ts_ms: pin.ts_ms } } diff --git a/crates/voelin-ui/src/dev.rs b/crates/voelin-ui/src/dev.rs index 3d287d6..eff4253 100644 --- a/crates/voelin-ui/src/dev.rs +++ b/crates/voelin-ui/src/dev.rs @@ -35,7 +35,7 @@ use voelin_core::{ Event, GatewayUpdate, HistoryMessage, HistorySource, ObserveState, SessionState, Source, VoiceState, }; -use voelin_gateway_proto::{ReactionCount, TopicInfo, UserRef, feature}; +use voelin_gateway_proto::{ReactionCount, StreamEntry, StreamSource, TopicInfo, UserRef, feature}; use voelin_model::{ ChannelInfo, ChatMessage, ChatTarget, ClientInfo, GroupInfo, Presence, ServerFlavor, }; @@ -608,7 +608,26 @@ fn demo_chat(app: &mut App, session: u64) { source: HistorySource::Gateway, complete: true, }); - // The gateway's answers for the drawers (no gateway runs in demo mode). + // The gateway's answers (no gateway runs in demo mode): the stream + // directory, and the pins and topics for the drawers. + app.handle_event(Event::Gateway { + session, + update: GatewayUpdate::Streams { + streams: vec![StreamEntry { + id: "demo-stream".into(), + stream_id: Some("demo-stream".into()), + streamer: UserRef { uid: "demo-2".into(), name: "Lumen".into() }, + client_id: Some(2), + channel: Some(2), + title: "Exploring the Lands Between".into(), + kind: "screen".into(), + started_ms: now - 12 * 60_000, + viewers: Some(12), + source: StreamSource::Registered, + event_id: None, + }], + }, + }); let by = |name: &str| UserRef { uid: format!("demo-{name}"), name: name.into() }; app.handle_event(Event::Gateway { session, diff --git a/crates/voelin-ui/src/streams.rs b/crates/voelin-ui/src/streams.rs index 47c2948..1941fee 100644 --- a/crates/voelin-ui/src/streams.rs +++ b/crates/voelin-ui/src/streams.rs @@ -50,8 +50,6 @@ pub(crate) struct Watch { layers: Vec, /// The layer chosen by hand; `None` follows the bandwidth estimate. layer: Option, - /// People watching the same stream, as the directory reports it. - viewers: u32, } impl Watch { @@ -227,6 +225,7 @@ impl App { name: s.name.clone().into(), streamer: view.nickname(s.streamer.0).into(), streamer_id: i32::from(s.streamer.0), + viewers: view.stream_viewers.get(&s.id).map_or(0, |v| *v as i32), audio: s.audio, watching, own: view.state.own_client == Some(s.streamer.0), @@ -317,7 +316,7 @@ impl App { bridge.set_share_status(status.into()); } - fn refresh_viewer(&self) { + pub(crate) fn refresh_viewer(&self) { let Some(ui) = self.ui.upgrade() else { return }; let bridge = ui.global::(); let Some(watch) = &self.watch else { @@ -348,7 +347,8 @@ impl App { .map_or(-1, |s| i32::from(s.streamer.0)); bridge.set_viewer_streamer_id(streamer); bridge.set_viewer_elapsed(watch.elapsed().into()); - bridge.set_viewer_count(watch.viewers as i32); + let viewers = self.view().and_then(|v| v.stream_viewers.get(&watch.stream_id)).copied(); + bridge.set_viewer_count(viewers.unwrap_or(0) as i32); let qualities = watch.qualities(); let chosen = watch .layer @@ -624,7 +624,6 @@ impl App { since: None, layers: Vec::new(), layer: None, - viewers: 0, }); self.refresh_viewer(); self.refresh_streams(); @@ -662,7 +661,6 @@ impl App { since: None, layers: Vec::new(), layer: None, - viewers: 0, }); let runtime = self.engine.runtime().clone(); let wake = || later(|app| app.show_picture()); @@ -692,8 +690,7 @@ impl App { }); self.start_demo(); if let (Some(watch), Some((id, title, streamer))) = (&mut self.watch, sample) { - (watch.stream_id, watch.title, watch.streamer, watch.viewers) = - (id, title, streamer, 12); + (watch.stream_id, watch.title, watch.streamer) = (id, title, streamer); } self.refresh_viewer(); } diff --git a/crates/voelin-ui/ui/bridge.slint b/crates/voelin-ui/ui/bridge.slint index 31bcf70..297e7b4 100644 --- a/crates/voelin-ui/ui/bridge.slint +++ b/crates/voelin-ui/ui/bridge.slint @@ -225,6 +225,8 @@ export struct StreamItem { streamer: string, // The streamer's client id (their avatar in the members). streamer-id: int, + // How many watch it (the gateway's directory; 0 unknown). + viewers: int, audio: bool, // "Screen", "Window", "Camera"; and the announced bitrate ("8 Mbit/s"). kind: string, diff --git a/crates/voelin-ui/ui/screens/voice.slint b/crates/voelin-ui/ui/screens/voice.slint index 981e902..84a2f4f 100644 --- a/crates/voelin-ui/ui/screens/voice.slint +++ b/crates/voelin-ui/ui/screens/voice.slint @@ -140,8 +140,8 @@ component StreamCard inherits Rectangle { large: true; y: (parent.height - self.height) / 2; } - if stream.watching && Bridge.viewer-count > 0: Chip { - text: @tr("{} watching", Bridge.viewer-count); + if stream.viewers > 0: Chip { + text: @tr("{} watching", stream.viewers); icon: Icons.eye; tint: #ffffff; fill: #060a18a0; diff --git a/docs/screenshots/desktop-about.png b/docs/screenshots/desktop-about.png index 75760a4..a505706 100644 Binary files a/docs/screenshots/desktop-about.png and b/docs/screenshots/desktop-about.png differ diff --git a/docs/screenshots/desktop-add-server.png b/docs/screenshots/desktop-add-server.png index 1d18567..3dfc86c 100644 Binary files a/docs/screenshots/desktop-add-server.png and b/docs/screenshots/desktop-add-server.png differ diff --git a/docs/screenshots/desktop-client-volume.png b/docs/screenshots/desktop-client-volume.png index b7f200d..19ba642 100644 Binary files a/docs/screenshots/desktop-client-volume.png and b/docs/screenshots/desktop-client-volume.png differ diff --git a/docs/screenshots/desktop-emoji-picker.png b/docs/screenshots/desktop-emoji-picker.png index 4e55164..1fa4087 100644 Binary files a/docs/screenshots/desktop-emoji-picker.png and b/docs/screenshots/desktop-emoji-picker.png differ diff --git a/docs/screenshots/desktop-home.png b/docs/screenshots/desktop-home.png index 3297df2..0a96abf 100644 Binary files a/docs/screenshots/desktop-home.png and b/docs/screenshots/desktop-home.png differ diff --git a/docs/screenshots/desktop-light.png b/docs/screenshots/desktop-light.png index 278f4f3..b05669e 100644 Binary files a/docs/screenshots/desktop-light.png and b/docs/screenshots/desktop-light.png differ diff --git a/docs/screenshots/desktop-member-card.png b/docs/screenshots/desktop-member-card.png index dccb403..d4a03c1 100644 Binary files a/docs/screenshots/desktop-member-card.png and b/docs/screenshots/desktop-member-card.png differ diff --git a/docs/screenshots/desktop-pins.png b/docs/screenshots/desktop-pins.png index c63831d..74b3f4c 100644 Binary files a/docs/screenshots/desktop-pins.png and b/docs/screenshots/desktop-pins.png differ diff --git a/docs/screenshots/desktop-popout.png b/docs/screenshots/desktop-popout.png index 11209ac..98161da 100644 Binary files a/docs/screenshots/desktop-popout.png and b/docs/screenshots/desktop-popout.png differ diff --git a/docs/screenshots/desktop-server.png b/docs/screenshots/desktop-server.png index 294e8bb..be44a37 100644 Binary files a/docs/screenshots/desktop-server.png and b/docs/screenshots/desktop-server.png differ diff --git a/docs/screenshots/desktop-settings-appearance.png b/docs/screenshots/desktop-settings-appearance.png index 6b2cb2e..250f927 100644 Binary files a/docs/screenshots/desktop-settings-appearance.png and b/docs/screenshots/desktop-settings-appearance.png differ diff --git a/docs/screenshots/desktop-settings-voice.png b/docs/screenshots/desktop-settings-voice.png index 5ecb7a6..35fd332 100644 Binary files a/docs/screenshots/desktop-settings-voice.png and b/docs/screenshots/desktop-settings-voice.png differ diff --git a/docs/screenshots/desktop-share-dialog.png b/docs/screenshots/desktop-share-dialog.png index bd2e4cd..d530e5f 100644 Binary files a/docs/screenshots/desktop-share-dialog.png and b/docs/screenshots/desktop-share-dialog.png differ diff --git a/docs/screenshots/desktop-stream-viewer.png b/docs/screenshots/desktop-stream-viewer.png index 493f1d0..24f4721 100644 Binary files a/docs/screenshots/desktop-stream-viewer.png and b/docs/screenshots/desktop-stream-viewer.png differ diff --git a/docs/screenshots/desktop-topic.png b/docs/screenshots/desktop-topic.png index b8c121c..289f19a 100644 Binary files a/docs/screenshots/desktop-topic.png and b/docs/screenshots/desktop-topic.png differ diff --git a/docs/screenshots/desktop-topics.png b/docs/screenshots/desktop-topics.png index 76b2c0c..fbfaedf 100644 Binary files a/docs/screenshots/desktop-topics.png and b/docs/screenshots/desktop-topics.png differ diff --git a/docs/screenshots/desktop-voice.png b/docs/screenshots/desktop-voice.png index d93fa14..fae4f61 100644 Binary files a/docs/screenshots/desktop-voice.png and b/docs/screenshots/desktop-voice.png differ diff --git a/docs/screenshots/mobile-chat.png b/docs/screenshots/mobile-chat.png index 79ec7fc..1ad4fcf 100644 Binary files a/docs/screenshots/mobile-chat.png and b/docs/screenshots/mobile-chat.png differ diff --git a/docs/screenshots/mobile-home.png b/docs/screenshots/mobile-home.png index f03f613..3f07a62 100644 Binary files a/docs/screenshots/mobile-home.png and b/docs/screenshots/mobile-home.png differ diff --git a/docs/screenshots/mobile-servers.png b/docs/screenshots/mobile-servers.png index 536c9ef..34c295a 100644 Binary files a/docs/screenshots/mobile-servers.png and b/docs/screenshots/mobile-servers.png differ diff --git a/docs/screenshots/mobile-settings.png b/docs/screenshots/mobile-settings.png index 938206e..4af59ef 100644 Binary files a/docs/screenshots/mobile-settings.png and b/docs/screenshots/mobile-settings.png differ diff --git a/docs/screenshots/mobile-you.png b/docs/screenshots/mobile-you.png index b70f5db..8145f60 100644 Binary files a/docs/screenshots/mobile-you.png and b/docs/screenshots/mobile-you.png differ