voelin-ui: show how many watch a stream, from the gateway's directory

The viewer count in the player and on the stream cards was never filled
in a real session: the engine subscribes to the gateway's stream
directory, whose entries carry the number of viewers, but the UI dropped
those updates. Keep the counts per session by stream id from
`GatewayUpdate::Streams`, `StreamStarted`, `StreamUpdated`,
`StreamRegistered` and `StreamEnded`, and show them in the player ("12
watching") and on the voice channel's stream cards. The sample data
answers with a directory, like a gateway, instead of setting the count.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
selikhovandClaude Opus 5.5 committed 2026-10-03 06:40:50 +03:00
1 parent 1041ffaf5c
commit 99bc5af617
28 files changed
+62 -12

No files matched your search

+3
View File
@@ -208,6 +208,8 @@ pub(crate) struct SessionView {
pub gateway_caps: Vec<String>,
/// The client whose member card is open.
pub member_card: Option<u16>,
/// Viewers of the streams in the gateway's directory, by stream id.
pub stream_viewers: HashMap<String, u32>,
/// Downloads started from chat, by transfer id.
pub downloads: HashMap<u64, crate::chat::Download>,
/// 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,
}
+29
View File
@@ -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 }
}
+21 -2
View File
@@ -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,
+5 -8
View File
@@ -50,8 +50,6 @@ pub(crate) struct Watch {
layers: Vec<LayerSpec>,
/// The layer chosen by hand; `None` follows the bandwidth estimate.
layer: Option<LayerId>,
/// 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::<Bridge>();
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();
}
+2
View File
@@ -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,
+2 -2
View File
@@ -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;
Binary file not shown.

Before

Width:  |  Height:  |  Size: 121 KiB

After

Width:  |  Height:  |  Size: 121 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 104 KiB

After

Width:  |  Height:  |  Size: 104 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 92 KiB

After

Width:  |  Height:  |  Size: 92 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 132 KiB

After

Width:  |  Height:  |  Size: 132 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 81 KiB

After

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 141 KiB

After

Width:  |  Height:  |  Size: 141 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 129 KiB

After

Width:  |  Height:  |  Size: 129 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 107 KiB

After

Width:  |  Height:  |  Size: 107 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 112 KiB

After

Width:  |  Height:  |  Size: 112 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 54 KiB

After

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 115 KiB

After

Width:  |  Height:  |  Size: 115 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 107 KiB

After

Width:  |  Height:  |  Size: 107 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 97 KiB

After

Width:  |  Height:  |  Size: 97 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 92 KiB

After

Width:  |  Height:  |  Size: 92 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 105 KiB

After

Width:  |  Height:  |  Size: 105 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 123 KiB

After

Width:  |  Height:  |  Size: 124 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 42 KiB

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 42 KiB

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 28 KiB