Split the streams controller: the state, the events and the rows into voelin-ui-vm
What we share and what we watch are in the AppState now (Sharing, Watching), with the transitions of the engine's stream events (apply handles them, the Stream Studio's stream excepted), the user's choices (watch, leave, volume, quality, the share dialog's plan, the capture that started) and the rows and texts of the streams panel, the share card and the viewer, as plain data in streams/logic.rs with tests of their own. The Slint side (streams/bind.rs) writes the Bridge, owns the capture and the decoder, and attaches or drops them as an update says (StreamEffects). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
03d1c3bd07
commit
0d2ad3f250
17 files changed
+2125
-1143
No files matched your search
@@ -6,11 +6,10 @@
|
||||
//! the state the same way.
|
||||
//!
|
||||
//! In [`Update::rest`] come back the events whose state is not in the
|
||||
//! [`AppState`] yet: a stream we share or watch (`Share` and `Watch` hold
|
||||
//! the capture and the decoder), the Stream Studio's stream, a setting that
|
||||
//! changed (the settings service), and the friends, pokes and offline
|
||||
//! messages that `social.rs` of the Slint client keeps. They move here with
|
||||
//! their areas (docs/ui.md, "Controllers still to split").
|
||||
//! [`AppState`]: the Stream Studio's stream (`Host::studio_streams_to`), a
|
||||
//! setting that changed (the settings service), and the friends, pokes and
|
||||
//! offline messages that `social.rs` of the Slint client keeps. They move
|
||||
//! here with their areas (docs/ui.md, "Controllers still to split").
|
||||
|
||||
mod gateway;
|
||||
|
||||
@@ -27,6 +26,7 @@ use crate::previews::fetch_previews;
|
||||
use crate::servers::{AfterConnect, JoinStep, after_connect, join_password};
|
||||
use crate::settings::LastVoice;
|
||||
use crate::state::{AppState, Lines, SessionView};
|
||||
use crate::streams::logic as streams;
|
||||
|
||||
/// Apply an event to the state; see the [module](self).
|
||||
pub fn apply<L: Lines>(state: &mut AppState<L>, host: &dyn Host, event: Event) -> Update {
|
||||
@@ -39,6 +39,13 @@ pub fn apply<L: Lines>(state: &mut AppState<L>, host: &dyn Host, event: Event) -
|
||||
}
|
||||
|
||||
fn dispatch<L: Lines>(state: &mut AppState<L>, cx: &mut Cx<'_>, event: Event) {
|
||||
// The Stream Studio's stream is the studio's.
|
||||
if let Event::StreamState { session, .. } | Event::StreamViewers { session, .. } = &event
|
||||
&& cx.host.studio_streams_to(*session as i64)
|
||||
{
|
||||
cx.update.rest = Some(event);
|
||||
return;
|
||||
}
|
||||
match event {
|
||||
Event::State { session, state: now } => session_state(state, cx, session as i64, now),
|
||||
Event::ServerInfo { session, name, backend, capabilities } => {
|
||||
@@ -214,9 +221,26 @@ fn dispatch<L: Lines>(state: &mut AppState<L>, cx: &mut Cx<'_>, event: Event) {
|
||||
cx.update.watch = Some(stream);
|
||||
}
|
||||
}
|
||||
// What a stream we share or watch, the studio's stream and the
|
||||
// settings service make of the rest, the front end keeps (see the
|
||||
// module's note).
|
||||
// The streams we share and watch.
|
||||
Event::StreamState { session, state: now } => {
|
||||
streams::share_state(state, cx, session as i64, now);
|
||||
}
|
||||
Event::StreamViewerRequest { session, viewer, .. } => {
|
||||
streams::viewer_request(state, cx, session as i64, viewer);
|
||||
}
|
||||
Event::StreamViewers { session, viewers } => {
|
||||
streams::viewers(state, cx, session as i64, viewers);
|
||||
}
|
||||
Event::WatchState { session, stream_id, state: now } => {
|
||||
streams::watch_state(state, cx, session as i64, &stream_id, now);
|
||||
}
|
||||
Event::WatchLayers { session, stream_id, layers, layer } => {
|
||||
streams::watch_layers(state, cx, session as i64, &stream_id, layers, layer);
|
||||
}
|
||||
// Also flagged on the sink, which the encoder reads.
|
||||
Event::StreamKeyframeRequest { .. } | Event::StreamLayerBitrate { .. } => {}
|
||||
// What the settings service and the friends make of the rest, the
|
||||
// front end keeps (see the module's note).
|
||||
event => cx.update.rest = Some(event),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
//! Tapes of engine events replayed through [`apply`] against a fake host:
|
||||
//! the state they leave, and what each update asks of a front end.
|
||||
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::collections::HashMap;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
|
||||
use voelin_core::StreamState;
|
||||
use voelin_core::gateway::Pin;
|
||||
use voelin_core::stream::StreamInfo;
|
||||
use voelin_core::{
|
||||
@@ -21,65 +21,11 @@ use voelin_store::{Bookmark, ChatRead, ChatTarget as StoredTarget, MessageSource
|
||||
use super::*;
|
||||
use crate::bridge::ChatLine;
|
||||
use crate::host::Refresh;
|
||||
use crate::host::testing::Fake;
|
||||
use crate::settings::{ClientPlayback, ClientPlaybackMap, LastVoice, UiSettings};
|
||||
|
||||
type State = AppState<Vec<ChatLine>>;
|
||||
|
||||
/// The front end of the tests: answers what the transitions ask and keeps
|
||||
/// what they store.
|
||||
#[derive(Default)]
|
||||
struct Fake {
|
||||
demo: bool,
|
||||
shown: Cell<bool>,
|
||||
watching: bool,
|
||||
autowatch: bool,
|
||||
limit: u64,
|
||||
/// What the store has: server unique id, its chats' reads.
|
||||
reads: HashMap<String, Vec<(StoredTarget, ChatRead)>>,
|
||||
/// What was stored.
|
||||
written: RefCell<Vec<(String, StoredTarget, ChatRead)>>,
|
||||
}
|
||||
|
||||
impl Host for Fake {
|
||||
fn demo_ui(&self) -> bool {
|
||||
self.demo
|
||||
}
|
||||
|
||||
fn chat_shown(&self) -> bool {
|
||||
self.shown.get()
|
||||
}
|
||||
|
||||
fn watching(&self) -> bool {
|
||||
self.watching
|
||||
}
|
||||
|
||||
fn autowatch(&self) -> bool {
|
||||
self.autowatch
|
||||
}
|
||||
|
||||
fn preview_limit(&self) -> u64 {
|
||||
self.limit
|
||||
}
|
||||
|
||||
fn fetch_images(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn chat_reads(&self, server_uid: &str) -> Result<Vec<(StoredTarget, ChatRead)>, String> {
|
||||
Ok(self.reads.get(server_uid).cloned().unwrap_or_default())
|
||||
}
|
||||
|
||||
fn set_chat_read(
|
||||
&self,
|
||||
server_uid: &str,
|
||||
target: &StoredTarget,
|
||||
read: &ChatRead,
|
||||
) -> Result<(), String> {
|
||||
self.written.borrow_mut().push((server_uid.to_owned(), target.clone(), *read));
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn state() -> State {
|
||||
let bookmark = Bookmark {
|
||||
id: 1,
|
||||
@@ -668,7 +614,7 @@ fn talking_the_meter_and_groups() {
|
||||
/// The streams the voice connection lists: the one a lookup waited for is
|
||||
/// to be watched; the rest of the stream events are the front end's.
|
||||
#[test]
|
||||
fn streams_are_listed_and_the_rest_is_handed_back() {
|
||||
fn streams_are_listed_and_a_lookup_is_watched() {
|
||||
let mut st = state();
|
||||
let host = Fake::default();
|
||||
run(&mut st, &host, vec![Event::Presence { session: 1, presence: presence() }]);
|
||||
@@ -706,8 +652,8 @@ fn streams_are_listed_and_the_rest_is_handed_back() {
|
||||
vec![Event::StreamsChanged { session: 1, streams: vec![stream("s3", 11)] }],
|
||||
);
|
||||
assert_eq!(ups[0].watch.as_deref(), Some("s3"));
|
||||
// What watching and sharing make of the other stream events is the front
|
||||
// end's (and so is a setting that changed).
|
||||
// Keyframe requests are the encoder's, read from the sink; a setting that
|
||||
// changed is the settings service's: the front end keeps it.
|
||||
let ups = run(
|
||||
&mut st,
|
||||
&host,
|
||||
@@ -716,9 +662,73 @@ fn streams_are_listed_and_the_rest_is_handed_back() {
|
||||
Event::SettingChanged { key: "audio".into() },
|
||||
],
|
||||
);
|
||||
assert!(matches!(ups[0].rest, Some(Event::StreamKeyframeRequest { .. })));
|
||||
assert!(ups[0].rest.is_none() && ups[0].refresh.is_empty() && ups[0].commands.is_empty());
|
||||
assert!(matches!(&ups[1].rest, Some(Event::SettingChanged { key }) if key == "audio"));
|
||||
assert!(ups[0].refresh.is_empty() && ups[0].commands.is_empty());
|
||||
}
|
||||
|
||||
/// The streams of the events: the studio's stream is the studio's; ours and
|
||||
/// the one we watch change the state and say what the capture and the
|
||||
/// decoder are to do.
|
||||
#[test]
|
||||
fn the_streams_we_share_and_watch_follow_the_events() {
|
||||
use crate::streams::logic::{Sharing, Watching, demo_viewers};
|
||||
use voelin_core::WatchState;
|
||||
use voelin_core::stream::EndReason;
|
||||
|
||||
let mut st = state();
|
||||
run(&mut st, &Fake::default(), vec![Event::Presence { session: 1, presence: presence() }]);
|
||||
st.share = Some(Sharing { session: 1, live: true, viewers: Vec::new(), stopping: false });
|
||||
st.watch = Some(Watching {
|
||||
session: Some(1),
|
||||
stream_id: "s1".into(),
|
||||
title: "Speedrun".into(),
|
||||
streamer: "Alice".into(),
|
||||
status: String::new(),
|
||||
connected: true,
|
||||
ended: false,
|
||||
has_frame: true,
|
||||
shown: true,
|
||||
since: None,
|
||||
layers: Vec::new(),
|
||||
layer: None,
|
||||
});
|
||||
// The studio streams to the server: its events are handed back as they
|
||||
// are, and our share is not touched.
|
||||
let studio = Fake { studio: Some(1), ..Default::default() };
|
||||
let ups = run(
|
||||
&mut st,
|
||||
&studio,
|
||||
vec![
|
||||
Event::StreamViewers { session: 1, viewers: demo_viewers() },
|
||||
Event::StreamState { session: 1, state: StreamState::Ended(EndReason::Stopped) },
|
||||
],
|
||||
);
|
||||
assert!(matches!(ups[0].rest, Some(Event::StreamViewers { .. })));
|
||||
assert!(matches!(ups[1].rest, Some(Event::StreamState { .. })));
|
||||
assert!(st.share.as_ref().unwrap().viewers.is_empty() && st.share.as_ref().unwrap().live);
|
||||
// Elsewhere they are ours.
|
||||
let host = Fake::default();
|
||||
let ups = run(
|
||||
&mut st,
|
||||
&host,
|
||||
vec![
|
||||
Event::StreamViewers { session: 1, viewers: demo_viewers() },
|
||||
Event::StreamViewerRequest { session: 1, viewer: 11, message: "hi".into() },
|
||||
Event::WatchState {
|
||||
session: 1,
|
||||
stream_id: "s1".into(),
|
||||
state: WatchState::Ended(EndReason::Stopped),
|
||||
},
|
||||
Event::StreamState { session: 1, state: StreamState::Ended(EndReason::Local) },
|
||||
],
|
||||
);
|
||||
assert!(ups[0].refresh.streams && ups[0].rest.is_none());
|
||||
assert_eq!(ups[1].status.as_deref(), Some("Alice wants to watch your stream"));
|
||||
let watch = st.watch.as_ref().unwrap();
|
||||
assert!(watch.ended && ups[2].stream.drop_decoder);
|
||||
assert_eq!(watch.status, "The stream has ended.");
|
||||
assert!(st.share.is_none() && ups[3].stream.drop_share && ups[3].stream.mixer);
|
||||
assert_eq!(ups[3].status.as_deref(), Some("You stopped sharing"));
|
||||
}
|
||||
|
||||
/// Pictures linked in a chat are downloaded once, up to the limit.
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
use voelin_core::{Command, Event, GatewayRequest};
|
||||
use voelin_core::{Command, Event, GatewayRequest, StreamSink};
|
||||
use voelin_model::ChatTarget;
|
||||
use voelin_store::{ChatRead, ChatTarget as StoredTarget};
|
||||
|
||||
@@ -32,6 +32,10 @@ pub trait Host {
|
||||
/// that shows up.
|
||||
fn autowatch(&self) -> bool;
|
||||
|
||||
/// The Stream Studio streams to this session: the events of that stream
|
||||
/// are its own.
|
||||
fn studio_streams_to(&self, session: i64) -> bool;
|
||||
|
||||
/// The largest picture previewed in chats, in bytes (0: none), from
|
||||
/// `ui.image_preview_kb`.
|
||||
fn preview_limit(&self) -> u64;
|
||||
@@ -122,6 +126,22 @@ pub struct PasswordPrompt {
|
||||
pub wrong: bool,
|
||||
}
|
||||
|
||||
/// What the streams we share and watch need of the front end, which owns the
|
||||
/// capture and the decoder.
|
||||
#[derive(Debug, Default)]
|
||||
pub struct StreamEffects {
|
||||
/// Encode into the live stream: the sink of our stream.
|
||||
pub attach: Option<StreamSink>,
|
||||
/// Our stream is over: the capture stops.
|
||||
pub drop_share: bool,
|
||||
/// The watched stream is over, or left: its decoder stops.
|
||||
pub drop_decoder: bool,
|
||||
/// The audio mixer's rows follow the capture again.
|
||||
pub mixer: bool,
|
||||
/// The player leaves full screen.
|
||||
pub leave_fullscreen: bool,
|
||||
}
|
||||
|
||||
/// What a transition tells its front end, besides the changed state.
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Update {
|
||||
@@ -150,6 +170,8 @@ pub struct Update {
|
||||
/// A stream to watch (its id): the one a lookup was waiting for, or the
|
||||
/// development switch's.
|
||||
pub watch: Option<String>,
|
||||
/// The capture and the decoder.
|
||||
pub stream: StreamEffects,
|
||||
/// A server connected or answered: the development switch that shares
|
||||
/// the test pattern may start now.
|
||||
pub autoshare: bool,
|
||||
@@ -219,3 +241,75 @@ impl<'a> Cx<'a> {
|
||||
self.update.chats.push((id, target.clone()));
|
||||
}
|
||||
}
|
||||
|
||||
/// A front end for the tests of the transitions.
|
||||
#[cfg(test)]
|
||||
pub(crate) mod testing {
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::collections::HashMap;
|
||||
|
||||
use voelin_store::{ChatRead, ChatTarget as StoredTarget};
|
||||
|
||||
use super::Host;
|
||||
|
||||
/// The front end of the tests: answers what the transitions ask and keeps
|
||||
/// what they store.
|
||||
#[derive(Default)]
|
||||
pub(crate) struct Fake {
|
||||
pub(crate) demo: bool,
|
||||
pub(crate) shown: Cell<bool>,
|
||||
pub(crate) watching: bool,
|
||||
pub(crate) autowatch: bool,
|
||||
/// The session the Stream Studio streams to.
|
||||
pub(crate) studio: Option<i64>,
|
||||
pub(crate) limit: u64,
|
||||
/// What the store has: server unique id, its chats' reads.
|
||||
pub(crate) reads: HashMap<String, Vec<(StoredTarget, ChatRead)>>,
|
||||
/// What was stored.
|
||||
pub(crate) written: RefCell<Vec<(String, StoredTarget, ChatRead)>>,
|
||||
}
|
||||
|
||||
impl Host for Fake {
|
||||
fn demo_ui(&self) -> bool {
|
||||
self.demo
|
||||
}
|
||||
|
||||
fn chat_shown(&self) -> bool {
|
||||
self.shown.get()
|
||||
}
|
||||
|
||||
fn watching(&self) -> bool {
|
||||
self.watching
|
||||
}
|
||||
|
||||
fn autowatch(&self) -> bool {
|
||||
self.autowatch
|
||||
}
|
||||
|
||||
fn studio_streams_to(&self, session: i64) -> bool {
|
||||
self.studio == Some(session)
|
||||
}
|
||||
|
||||
fn preview_limit(&self) -> u64 {
|
||||
self.limit
|
||||
}
|
||||
|
||||
fn fetch_images(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn chat_reads(&self, server_uid: &str) -> Result<Vec<(StoredTarget, ChatRead)>, String> {
|
||||
Ok(self.reads.get(server_uid).cloned().unwrap_or_default())
|
||||
}
|
||||
|
||||
fn set_chat_read(
|
||||
&self,
|
||||
server_uid: &str,
|
||||
target: &StoredTarget,
|
||||
read: &ChatRead,
|
||||
) -> Result<(), String> {
|
||||
self.written.borrow_mut().push((server_uid.to_owned(), target.clone(), *read));
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@ use crate::bridge::ChatLine;
|
||||
use crate::chat::{LineCache, Previous};
|
||||
use crate::image::ImageRef;
|
||||
use crate::settings::{ClientPlaybackMap, DeviceChoices, UiSettings};
|
||||
use crate::streams::logic::{Sharing, Watching};
|
||||
|
||||
/// The store's name of a chat.
|
||||
pub fn store_target(target: &ChatTarget) -> voelin_store::ChatTarget {
|
||||
@@ -568,6 +569,10 @@ pub struct AppState<L> {
|
||||
/// Our unique ids (TeamSpeak 3 and 6 of every identity): messages by
|
||||
/// them are ours ([`crate::social::own_message`]).
|
||||
pub own_uids: HashSet<String>,
|
||||
/// Our stream (the capture that feeds it is the front end's).
|
||||
pub share: Option<Sharing>,
|
||||
/// The stream in the viewer (its decoder is the front end's).
|
||||
pub watch: Option<Watching>,
|
||||
}
|
||||
|
||||
impl<L> AppState<L> {
|
||||
@@ -608,6 +613,8 @@ impl<L> AppState<L> {
|
||||
gateways_looked_up: HashSet::new(),
|
||||
uploads: HashMap::new(),
|
||||
own_uids: HashSet::new(),
|
||||
share: None,
|
||||
watch: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,5 +1,8 @@
|
||||
//! Streams on the voice view, the phone's Activity tab and Home: what is
|
||||
//! shared, and who shares it.
|
||||
//! shared, and who shares it; [`logic`] has the state of the streams we
|
||||
//! share and watch, and what happens to them.
|
||||
|
||||
pub mod logic;
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
@@ -30,8 +30,8 @@ use voelin_store::{Bookmark, MemorySecrets, Secrets, Store};
|
||||
use crate::bind::rows::Rows;
|
||||
use crate::hotkey::GlobalPtt;
|
||||
use crate::settings::{CLIENT_PLAYBACK, ClientPlaybackMap, UI, UiSettings, appearance_keys};
|
||||
use crate::streams::{Share, Watch};
|
||||
use crate::video::Video;
|
||||
use crate::streams::Share;
|
||||
use crate::video::{Decoder, Video};
|
||||
use crate::vm;
|
||||
|
||||
slint::include_modules!();
|
||||
@@ -228,10 +228,10 @@ pub(crate) struct App {
|
||||
pub prefs: Settings,
|
||||
pub ptt: GlobalPtt,
|
||||
pub video: Video,
|
||||
/// Our stream.
|
||||
/// The capture of our stream (`state.share` has the rest of it).
|
||||
pub share: Option<Share>,
|
||||
/// The stream in the viewer.
|
||||
pub watch: Option<Watch>,
|
||||
/// The decoder of the stream in the viewer (`state.watch` has the rest).
|
||||
pub decoder: Option<Decoder>,
|
||||
/// `VOELIN_DEMO_STREAM`: the viewer shows a local test stream.
|
||||
pub demo: bool,
|
||||
/// `VOELIN_DEMO_UI`: sample servers, channels and chat (dev.rs).
|
||||
@@ -441,7 +441,7 @@ pub fn run(options: RunOptions) -> Result<()> {
|
||||
ptt,
|
||||
video,
|
||||
share: None,
|
||||
watch: None,
|
||||
decoder: None,
|
||||
demo: switches.demo_stream,
|
||||
demo_ui: switches.demo_ui,
|
||||
autoshare: switches.autoshare,
|
||||
@@ -515,7 +515,9 @@ pub fn run(options: RunOptions) -> Result<()> {
|
||||
for id in ids {
|
||||
app.save_reads(id);
|
||||
}
|
||||
app.watch = None;
|
||||
app.state.watch = None;
|
||||
app.decoder = None;
|
||||
app.state.share = None;
|
||||
app.share = None;
|
||||
if own && !app.demo_ui {
|
||||
for id in app.state.sessions.keys() {
|
||||
|
||||
@@ -12,6 +12,7 @@ use voelin_store::{ChatRead, ChatTarget as StoredTarget, Store};
|
||||
|
||||
use crate::app::{App, AppState, Bridge, MainWindow, Nav};
|
||||
use crate::settings::UI_IMAGE_PREVIEW_KB;
|
||||
use crate::studio::StudioState;
|
||||
use crate::vm::host::{Cx, Host, PasswordPrompt, Persist, Refresh, Update};
|
||||
|
||||
/// What the transitions ask while they run: the window, the store and the
|
||||
@@ -22,6 +23,7 @@ pub(crate) struct SlintHost<'a> {
|
||||
pub ui: &'a slint::Weak<MainWindow>,
|
||||
pub store: &'a Store,
|
||||
pub prefs: &'a Settings,
|
||||
pub studio: &'a StudioState,
|
||||
}
|
||||
|
||||
impl Host for SlintHost<'_> {
|
||||
@@ -41,6 +43,10 @@ impl Host for SlintHost<'_> {
|
||||
std::env::var("VOELIN_AUTOWATCH").is_ok_and(|v| v == "1")
|
||||
}
|
||||
|
||||
fn studio_streams_to(&self, session: i64) -> bool {
|
||||
self.studio.streams_to(session)
|
||||
}
|
||||
|
||||
fn preview_limit(&self) -> u64 {
|
||||
u64::from(self.prefs.get(&UI_IMAGE_PREVIEW_KB)) * 1024
|
||||
}
|
||||
@@ -65,13 +71,14 @@ impl Host for SlintHost<'_> {
|
||||
|
||||
impl App {
|
||||
/// Run `f` with the state and the host, and return what it returns.
|
||||
fn with_host<R>(&mut self, f: impl FnOnce(&mut AppState, &SlintHost<'_>) -> R) -> R {
|
||||
pub(crate) fn with_host<R>(&mut self, f: impl FnOnce(&mut AppState, &SlintHost<'_>) -> R) -> R {
|
||||
let host = SlintHost {
|
||||
demo_ui: self.demo_ui,
|
||||
watching: self.watch.is_some(),
|
||||
watching: self.state.watch.is_some(),
|
||||
ui: &self.ui,
|
||||
store: &self.store,
|
||||
prefs: &self.prefs,
|
||||
studio: &self.studio,
|
||||
};
|
||||
f(&mut self.state, &host)
|
||||
}
|
||||
@@ -111,6 +118,7 @@ impl App {
|
||||
warnings,
|
||||
chats,
|
||||
watch,
|
||||
stream,
|
||||
autoshare,
|
||||
first_client,
|
||||
rest,
|
||||
@@ -122,12 +130,30 @@ impl App {
|
||||
for path in &reloaded {
|
||||
crate::images::reloaded(path);
|
||||
}
|
||||
if let Some(text) = status {
|
||||
self.set_status(text);
|
||||
}
|
||||
for command in commands {
|
||||
self.engine.send(command);
|
||||
}
|
||||
// The capture and the decoder.
|
||||
if let Some(sink) = stream.attach
|
||||
&& let Some(share) = &self.share
|
||||
{
|
||||
share.capture.attach(sink);
|
||||
}
|
||||
if stream.drop_share {
|
||||
self.share = None;
|
||||
}
|
||||
if stream.drop_decoder {
|
||||
self.decoder = None;
|
||||
}
|
||||
if stream.leave_fullscreen {
|
||||
self.set_fullscreen(false);
|
||||
}
|
||||
if stream.mixer {
|
||||
self.mixer_refresh();
|
||||
}
|
||||
if let Some(text) = status {
|
||||
self.set_status(text);
|
||||
}
|
||||
for what in persist {
|
||||
self.keep(what);
|
||||
}
|
||||
@@ -224,9 +250,8 @@ impl App {
|
||||
}
|
||||
}
|
||||
|
||||
/// The events whose state the view model does not hold yet: a setting
|
||||
/// that changed, the studio's stream, and the streams we share and
|
||||
/// watch.
|
||||
/// The events whose state the view model does not hold: a setting that
|
||||
/// changed, and the studio's stream.
|
||||
fn event_rest(&mut self, event: Event) {
|
||||
match event {
|
||||
Event::SettingChanged { key } => self.setting_changed(&key),
|
||||
@@ -237,7 +262,9 @@ impl App {
|
||||
Event::StreamViewers { session, viewers } if self.studio_streams_to(session as i64) => {
|
||||
self.studio_viewers(viewers);
|
||||
}
|
||||
event => self.stream_event(event),
|
||||
// The rest (friends, pokes, offline messages) is looked at by
|
||||
// social.rs, before and after.
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,8 @@ impl App {
|
||||
/// The player into a window of its own.
|
||||
pub(crate) fn viewer_pop_out(&mut self) {
|
||||
// One window on Android.
|
||||
if cfg!(target_os = "android") || self.popout.window.is_some() || self.watch.is_none() {
|
||||
if cfg!(target_os = "android") || self.popout.window.is_some() || self.state.watch.is_none()
|
||||
{
|
||||
return;
|
||||
}
|
||||
// The main window's full screen was the player's.
|
||||
@@ -86,7 +87,7 @@ impl App {
|
||||
/// The player back into the main window, on the stream's server page.
|
||||
pub(crate) fn viewer_dock(&mut self) {
|
||||
let Some(window) = self.close_popout() else { return };
|
||||
if let Some(watch) = &mut self.watch {
|
||||
if let Some(watch) = &mut self.state.watch {
|
||||
watch.shown = true;
|
||||
}
|
||||
if let Some(ui) = self.ui.upgrade() {
|
||||
@@ -95,6 +96,7 @@ impl App {
|
||||
// The main window may have gone to another server meanwhile: else
|
||||
// the stream would play on, unseen.
|
||||
let session = self
|
||||
.state
|
||||
.watch
|
||||
.as_ref()
|
||||
.and_then(|w| w.session)
|
||||
|
||||
@@ -526,7 +526,8 @@ impl App {
|
||||
self.models.members.sync(&members);
|
||||
// The people in our channel first while their view is shown (not
|
||||
// while the stream plays in a window of its own).
|
||||
let watching = self.watch.as_ref().is_some_and(|w| w.shown) && self.popout.window.is_none();
|
||||
let watching =
|
||||
self.state.watch.as_ref().is_some_and(|w| w.shown) && self.popout.window.is_none();
|
||||
let voice_first = connected && (self.state.voice_view || watching);
|
||||
let everyone = vm::tree::server_members(&input, voice_first);
|
||||
let filter = self.state.member_filter.trim().to_lowercase();
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,425 @@
|
||||
//! The Slint side of the streams: the Bridge writes of the streams panel,
|
||||
//! the share dialog and the viewer, the capture and the decoder, the
|
||||
//! viewer's window. The state and its transitions are in
|
||||
//! `voelin_ui_vm::streams::logic`.
|
||||
|
||||
use std::time::Duration;
|
||||
|
||||
use slint::{ComponentHandle, Model};
|
||||
use tracing::warn;
|
||||
use voelin_core::media::{Streamer, audio_source_specs};
|
||||
use voelin_core::settings::{STREAM_AUDIO_SOURCES, STREAM_BITRATE_KBPS, STREAM_FPS};
|
||||
use voelin_core::stream::StreamSetup;
|
||||
|
||||
use super::Share;
|
||||
use crate::app::{App, Bridge, later, with_app};
|
||||
use crate::bind::convert;
|
||||
use crate::video::{self, Capture, Decoder};
|
||||
use crate::vm::bridge::{ShareForm, SourceItem};
|
||||
use crate::vm::streams::logic::{
|
||||
self as logic, CaptureFacts, CaptureStarted, SharePlan, StreamsFacts, viewer_view,
|
||||
};
|
||||
|
||||
/// Show or hide the pointer over `window`. In full screen the player hides
|
||||
/// it with its controls: Slint applies a TouchArea's cursor only when the
|
||||
/// pointer moves, so the window is told directly. (No pointer on Android.)
|
||||
pub(crate) fn show_cursor(window: &slint::Window, shown: bool) {
|
||||
#[cfg(not(target_os = "android"))]
|
||||
{
|
||||
use slint::winit_030::WinitWindowAccessor;
|
||||
window.with_winit_window(|w| w.set_cursor_visible(shown));
|
||||
}
|
||||
#[cfg(target_os = "android")]
|
||||
let _ = (window, shown);
|
||||
}
|
||||
|
||||
impl App {
|
||||
/// The streams panel, the voice card's streams and the share card.
|
||||
pub(crate) fn refresh_streams(&self) {
|
||||
let Some(ui) = self.ui.upgrade() else { return };
|
||||
let bridge = ui.global::<Bridge>();
|
||||
let current = self.state.current;
|
||||
let capture = self.share.as_ref().map(|s| CaptureFacts {
|
||||
status: s.capture.status(),
|
||||
source_name: s.capture.source_name().to_owned(),
|
||||
has_audio: s.capture.has_audio(),
|
||||
});
|
||||
let facts = StreamsFacts {
|
||||
demo: self.demo,
|
||||
studio_live_here: current.is_some_and(|c| self.studio_streams_to(c)),
|
||||
capture: capture.as_ref(),
|
||||
};
|
||||
let view = logic::streams_view(&self.state, &facts);
|
||||
bridge.set_streams_available(view.available);
|
||||
self.models.streams.sync(&view.items);
|
||||
bridge.set_can_share(video::AVAILABLE);
|
||||
let share = view.share;
|
||||
bridge.set_share_state(share.state.into());
|
||||
bridge.set_share_busy(share.busy);
|
||||
bridge.set_share_error(share.error.into());
|
||||
bridge.set_share_audio(share.audio);
|
||||
bridge.set_share_requests(share.requests);
|
||||
self.models.viewers.sync(&share.viewers);
|
||||
bridge.set_share_status(share.status.into());
|
||||
}
|
||||
|
||||
/// The viewer in the main window and in its own: the same facts, but
|
||||
/// the main window's player only while the stream is not popped out.
|
||||
pub(crate) fn refresh_viewer(&self) {
|
||||
let popped = self.popout.window.is_some();
|
||||
let Some(watch) = &self.state.watch else {
|
||||
self.viewer_each(|bridge| {
|
||||
bridge.set_viewer_open(false);
|
||||
bridge.set_viewer_popped(popped);
|
||||
bridge.set_viewer_has_frame(false);
|
||||
bridge.set_viewer_frame(slint::Image::default());
|
||||
});
|
||||
return;
|
||||
};
|
||||
if let Some(ui) = self.ui.upgrade() {
|
||||
let bridge = ui.global::<Bridge>();
|
||||
let open = watch.shown && !popped && self.watch_here();
|
||||
if !open && bridge.get_viewer_open() && bridge.get_viewer_fullscreen() {
|
||||
// The player goes, still in full screen: it may have hidden the cursor.
|
||||
show_cursor(ui.window(), true);
|
||||
}
|
||||
bridge.set_viewer_open(open);
|
||||
}
|
||||
if let Some(window) = &self.popout.window {
|
||||
window.global::<Bridge>().set_viewer_open(true);
|
||||
}
|
||||
let decoded = self.decoder.as_ref().map(Decoder::info).unwrap_or_default();
|
||||
let view = viewer_view(&self.state, watch, &decoded);
|
||||
// The members are the current server's.
|
||||
let admin = self.watch_here()
|
||||
&& self.models.members.rows().iter().any(|m| m.id == view.streamer_id && m.admin);
|
||||
self.models.qualities.sync(&view.qualities);
|
||||
let channel = slint::SharedString::from(view.channel.as_str());
|
||||
let elapsed = slint::SharedString::from(view.elapsed.as_str());
|
||||
self.viewer_each(|bridge| {
|
||||
bridge.set_viewer_popped(popped);
|
||||
bridge.set_viewer_title(view.title.as_str().into());
|
||||
bridge.set_viewer_status(view.status.as_str().into());
|
||||
bridge.set_viewer_ended(view.ended);
|
||||
bridge.set_viewer_has_frame(view.has_frame);
|
||||
bridge.set_viewer_volume(view.volume);
|
||||
bridge.set_viewer_info(view.info.as_str().into());
|
||||
bridge.set_viewer_streamer(view.streamer.as_str().into());
|
||||
bridge.set_viewer_streamer_avatar(convert::image(&view.avatar));
|
||||
bridge.set_viewer_streamer_initials(view.initials.as_ref().into());
|
||||
bridge.set_viewer_streamer_tint(convert::color(view.tint));
|
||||
bridge.set_viewer_streamer_admin(admin);
|
||||
bridge.set_viewer_channel(channel.clone());
|
||||
bridge.set_viewer_elapsed(elapsed.clone());
|
||||
bridge.set_viewer_count(view.count);
|
||||
if bridge.get_viewer_quality() != view.quality {
|
||||
bridge.set_viewer_quality(view.quality);
|
||||
}
|
||||
bridge.set_viewer_quality_detail(view.detail.as_str().into());
|
||||
});
|
||||
}
|
||||
|
||||
/// The watched stream is on the server on screen (or is the local test
|
||||
/// stream).
|
||||
pub(crate) fn watch_here(&self) -> bool {
|
||||
self.state.watch.as_ref().is_some_and(|w| w.here(self.state.current))
|
||||
}
|
||||
|
||||
/// A simulcast layer of the watched stream (0: follow the bandwidth
|
||||
/// estimate), asked of the streamer; the engine confirms with
|
||||
/// `WatchLayers`.
|
||||
pub(crate) fn set_stream_quality(&mut self, index: i32) {
|
||||
self.transition(|state, cx| logic::set_quality(state, cx, index));
|
||||
}
|
||||
|
||||
/// Once a second: statistics, a capture that ended, decoder problems.
|
||||
pub(crate) fn tick_streams(&mut self) {
|
||||
if self.share.as_ref().is_some_and(|s| s.capture.ended()) {
|
||||
self.transition(logic::capture_ended);
|
||||
}
|
||||
if self.state.watch.as_ref().is_some_and(|w| w.connected && !w.has_frame)
|
||||
&& let Some(error) = self.decoder.as_ref().and_then(Decoder::error)
|
||||
{
|
||||
logic::decoder_failed(&mut self.state, &error);
|
||||
}
|
||||
if self.state.share.is_some() {
|
||||
self.refresh_streams();
|
||||
}
|
||||
// The share dialog's audio mixer (studio/).
|
||||
self.mixer_tick();
|
||||
if self.state.watch.is_some() {
|
||||
self.refresh_viewer();
|
||||
}
|
||||
}
|
||||
|
||||
// Sharing.
|
||||
|
||||
/// Fill the share dialog: sources and the last choices.
|
||||
pub(crate) fn open_share(&mut self) -> ShareForm {
|
||||
let test_pattern = cfg!(debug_assertions)
|
||||
|| self.demo
|
||||
|| std::env::var("VOELIN_TEST_PATTERN").is_ok_and(|v| v == "1");
|
||||
let restorable = self.state.settings.portal_restore_token.is_some();
|
||||
let sources =
|
||||
logic::sources_listed(&mut self.state, self.video.sources(test_pattern, restorable));
|
||||
if let Some(ui) = self.ui.upgrade() {
|
||||
let items: Vec<SourceItem> = sources
|
||||
.into_iter()
|
||||
.map(|(name, detail)| SourceItem { name: name.into(), detail: detail.into() })
|
||||
.collect();
|
||||
ui.global::<Bridge>().set_share_sources(convert::model(&items));
|
||||
}
|
||||
self.refresh_streams();
|
||||
// Its audio: the Stream Studio's mixer rows and picker.
|
||||
self.mixer_show();
|
||||
let (fps, bitrate) = (self.prefs.get(&STREAM_FPS), self.prefs.get(&STREAM_BITRATE_KBPS));
|
||||
logic::share_form(&self.state, fps, bitrate)
|
||||
}
|
||||
|
||||
/// The share dialog's form with the test pattern chosen.
|
||||
fn test_pattern_form(&mut self) -> Option<ShareForm> {
|
||||
let mut form = self.open_share();
|
||||
let ui = self.ui.upgrade()?;
|
||||
let sources = ui.global::<Bridge>().get_share_sources();
|
||||
let pattern = (0..sources.row_count())
|
||||
.find(|&i| sources.row_data(i).is_some_and(|s| s.name == "Test pattern"))?;
|
||||
form.source = pattern as i32;
|
||||
Some(form)
|
||||
}
|
||||
|
||||
/// Development switch `VOELIN_AUTOSHARE`: share the test pattern once.
|
||||
pub(crate) fn autoshare(&mut self) {
|
||||
if !self.autoshare || !self.view().is_some_and(|v| v.streams_available()) {
|
||||
return;
|
||||
}
|
||||
self.autoshare = false;
|
||||
if let Some(form) = self.test_pattern_form() {
|
||||
self.start_share(ShareForm { auto_accept: true, ..form });
|
||||
}
|
||||
}
|
||||
|
||||
/// `VOELIN_OPEN=share:live` with sample data: the test pattern shared
|
||||
/// with the sample mixer's sources (live at once, `capture_ready`).
|
||||
pub(crate) fn demo_share(&mut self) {
|
||||
if let Some(form) = self.test_pattern_form() {
|
||||
self.start_share(ShareForm { audio: true, ..form });
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn start_share(&mut self, form: ShareForm) {
|
||||
let Some(session) = self.state.current else { return };
|
||||
// The mixer's sources (the sample studio's with VOELIN_DEMO_UI).
|
||||
let sources = self.studio_settings().get(&STREAM_AUDIO_SOURCES);
|
||||
let studio_live_here = self.studio_streams_to(session);
|
||||
let Some(plan) = self.transition(|state, cx| {
|
||||
logic::plan_share(state, cx, &form, studio_live_here, &sources)
|
||||
}) else {
|
||||
return;
|
||||
};
|
||||
let SharePlan { session, source, fps, bitrate, request, setup, auto_accept } = plan;
|
||||
// The next share starts from these.
|
||||
for result in
|
||||
[self.prefs.set(&STREAM_FPS, fps), self.prefs.set(&STREAM_BITRATE_KBPS, bitrate)]
|
||||
{
|
||||
if let Err(e) = result {
|
||||
warn!(%e, "could not store the share settings");
|
||||
}
|
||||
}
|
||||
let runtime = self.engine.runtime().clone();
|
||||
self.video.start_capture(&runtime, source, request, move |result| {
|
||||
later(move |app| app.capture_ready(session, setup, auto_accept, result));
|
||||
});
|
||||
}
|
||||
|
||||
/// The capture started (or not): go live.
|
||||
fn capture_ready(
|
||||
&mut self,
|
||||
session: i64,
|
||||
setup: StreamSetup,
|
||||
auto_accept: bool,
|
||||
result: Result<Capture, String>,
|
||||
) {
|
||||
let started = result.as_ref().map(started).map_err(Clone::clone);
|
||||
let (keep, update) = self.with_host(|state, host| {
|
||||
let mut cx = crate::vm::host::Cx::new(host);
|
||||
let keep = logic::capture_ready(state, &mut cx, session, setup, auto_accept, started);
|
||||
(keep, cx.update)
|
||||
});
|
||||
// The capture is kept before the update is carried out: the mixer's
|
||||
// rows it asks for follow it.
|
||||
if let (true, Ok(capture)) = (keep, result) {
|
||||
let meters = slint::Timer::default();
|
||||
meters.start(slint::TimerMode::Repeated, Duration::from_millis(66), || {
|
||||
with_app(|app| app.studio_meters());
|
||||
});
|
||||
self.share = Some(Share { capture, _meters: meters });
|
||||
}
|
||||
self.perform(update);
|
||||
}
|
||||
|
||||
pub(crate) fn stop_share(&mut self) {
|
||||
self.transition(logic::stop_share);
|
||||
}
|
||||
|
||||
/// The running share's streamer (the mixer's rows, studio/).
|
||||
pub(crate) fn share_streamer(&self) -> Option<&Streamer> {
|
||||
self.share.as_ref().map(|s| s.capture.streamer())
|
||||
}
|
||||
|
||||
/// `stream.audio_sources` changed (the mixer, the settings, another
|
||||
/// window): a running share mixes the new sources.
|
||||
pub(crate) fn share_audio_changed(&mut self) {
|
||||
if self.share.is_none() {
|
||||
return;
|
||||
}
|
||||
let sources = audio_source_specs(&self.studio_settings().get(&STREAM_AUDIO_SOURCES));
|
||||
let codecs = self.video.codecs();
|
||||
let Some(share) = &self.share else { return };
|
||||
if let Err(e) = share.capture.follow_audio(&codecs, sources) {
|
||||
self.set_status(format!("Stream audio: {e}"));
|
||||
}
|
||||
self.mixer_refresh();
|
||||
}
|
||||
|
||||
pub(crate) fn respond_viewer(&mut self, viewer: u16, accept: bool) {
|
||||
self.transition(|state, cx| logic::respond_viewer(state, cx, viewer, accept));
|
||||
}
|
||||
|
||||
pub(crate) fn kick_viewer(&mut self, viewer: u16) {
|
||||
self.transition(|state, cx| logic::kick_viewer(state, cx, viewer));
|
||||
}
|
||||
|
||||
// Watching.
|
||||
|
||||
pub(crate) fn watch_stream(&mut self, stream_id: String) {
|
||||
if stream_id == "demo" && self.demo {
|
||||
self.start_demo();
|
||||
return;
|
||||
}
|
||||
let Some(session) = self.transition(|state, cx| logic::watch_stream(state, cx, &stream_id))
|
||||
else {
|
||||
return;
|
||||
};
|
||||
let wake = || later(|app| app.show_picture());
|
||||
self.decoder = Some(self.video.watch(&self.engine, session as u64, &stream_id, wake));
|
||||
self.refresh_viewer();
|
||||
}
|
||||
|
||||
/// 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) {
|
||||
if let Some(id) = self.transition(|state, cx| logic::watch_client(state, cx, client)) {
|
||||
self.watch_stream(id);
|
||||
}
|
||||
}
|
||||
|
||||
/// `VOELIN_OPEN=watch`: watch the first stream of our channel.
|
||||
pub(crate) fn watch_first_stream(&mut self) {
|
||||
if let Some(id) = logic::first_stream(&self.state) {
|
||||
self.watch_stream(id);
|
||||
}
|
||||
}
|
||||
|
||||
/// The local test stream in the viewer (`VOELIN_DEMO_STREAM`).
|
||||
pub(crate) fn start_demo(&mut self) {
|
||||
self.transition(logic::start_demo);
|
||||
let runtime = self.engine.runtime().clone();
|
||||
let wake = || later(|app| app.show_picture());
|
||||
self.video.demo(&runtime, wake, |result| {
|
||||
later(move |app| {
|
||||
let Some(watch) = app.state.watch.as_mut().filter(|w| w.session.is_none()) else {
|
||||
return;
|
||||
};
|
||||
match result {
|
||||
Ok(decoder) => app.decoder = Some(decoder),
|
||||
Err(e) => watch.status = format!("The preview failed: {e}"),
|
||||
}
|
||||
app.refresh_viewer();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/// `VOELIN_OPEN=watch` with sample data: the local test pattern in the
|
||||
/// viewer, dressed as the first stream of our channel.
|
||||
pub(crate) fn demo_watch(&mut self) {
|
||||
let sample = logic::demo_sample(&self.state);
|
||||
self.start_demo();
|
||||
if let (Some(watch), Some((id, title, streamer))) = (&mut self.state.watch, sample) {
|
||||
(watch.stream_id, watch.title, watch.streamer) = (id, title, streamer);
|
||||
}
|
||||
self.refresh_viewer();
|
||||
// Its card shows it as watched.
|
||||
self.refresh_streams();
|
||||
}
|
||||
|
||||
/// A decoded picture is waiting.
|
||||
fn show_picture(&mut self) {
|
||||
if self.state.watch.is_none() {
|
||||
return;
|
||||
}
|
||||
let Some(image) = self.decoder.as_ref().and_then(Decoder::take_picture) else { return };
|
||||
let first = logic::picture_shown(&mut self.state);
|
||||
// Only the window with the player: each would scale it again.
|
||||
self.with_player(|bridge, _| bridge.set_viewer_frame(image));
|
||||
if first {
|
||||
self.refresh_viewer();
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn show_viewer(&mut self, shown: bool) {
|
||||
// Shown in the main window: from a window of its own, it comes back.
|
||||
if shown && self.popout.window.is_some() {
|
||||
self.viewer_dock();
|
||||
return;
|
||||
}
|
||||
self.transition(|state, cx| logic::show_viewer(state, cx, shown));
|
||||
}
|
||||
|
||||
/// Stop watching and close the viewer, its own window too.
|
||||
pub(crate) fn leave_stream(&mut self) {
|
||||
self.close_popout();
|
||||
self.stop_watching();
|
||||
}
|
||||
|
||||
/// Stop watching; a window of its own stays (for the next stream).
|
||||
fn stop_watching(&mut self) {
|
||||
self.transition(logic::stop_watching);
|
||||
}
|
||||
|
||||
pub(crate) fn set_stream_volume(&mut self, percent: f32) {
|
||||
self.transition(|state, cx| logic::set_volume(state, cx, percent));
|
||||
}
|
||||
|
||||
pub(crate) fn toggle_fullscreen(&mut self) {
|
||||
let mut full = false;
|
||||
self.with_player(|bridge, _| full = !bridge.get_viewer_fullscreen());
|
||||
self.set_fullscreen(full);
|
||||
}
|
||||
|
||||
/// The window with the player in full screen, or back.
|
||||
pub(crate) fn set_fullscreen(&self, full: bool) {
|
||||
self.with_player(|bridge, window| {
|
||||
if bridge.get_viewer_fullscreen() == full {
|
||||
return;
|
||||
}
|
||||
bridge.set_viewer_fullscreen(full);
|
||||
window.set_fullscreen(full);
|
||||
if !full {
|
||||
// The player that hid the cursor may be gone already.
|
||||
show_cursor(window, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// What the state needs to know of a capture that started.
|
||||
fn started(capture: &Capture) -> CaptureStarted {
|
||||
CaptureStarted {
|
||||
restore_token: capture.restore_token(),
|
||||
automatic_bitrate: capture.streamer().bitrate_kbps(),
|
||||
has_audio: capture.has_audio(),
|
||||
audio_error: capture.audio_error(),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
//! Streams (TeamSpeak 6): the streams panel, sharing our screen and the
|
||||
//! viewer. The engine runs the stream sessions; `video.rs` captures,
|
||||
//! encodes and decodes. What is state of the streams (what we share, what we
|
||||
//! watch, the rows and texts) is in `voelin_ui_vm::streams::logic`; `bind`
|
||||
//! has the Bridge writes, the capture and the decoder.
|
||||
|
||||
mod bind;
|
||||
|
||||
use crate::video::Capture;
|
||||
|
||||
pub(crate) use bind::show_cursor;
|
||||
|
||||
/// The capture that feeds our stream, while we share (`AppState::share` has
|
||||
/// the rest): it stops when dropped.
|
||||
pub(crate) struct Share {
|
||||
pub capture: Capture,
|
||||
/// The audio mixer's meters (the studio's rows), about 15 times a second.
|
||||
_meters: slint::Timer,
|
||||
}
|
||||
@@ -490,7 +490,7 @@ impl App {
|
||||
if self.studio.run.is_some() {
|
||||
return;
|
||||
}
|
||||
if self.share.is_some() {
|
||||
if self.state.share.is_some() {
|
||||
self.mixer_refresh();
|
||||
}
|
||||
if !self.ui.upgrade().is_some_and(|ui| ui.global::<Nav>().get_share_open()) {
|
||||
@@ -596,7 +596,7 @@ impl App {
|
||||
let sharing = st
|
||||
.data
|
||||
.destination
|
||||
.is_some_and(|d| self.share.as_ref().is_some_and(|s| s.session == d));
|
||||
.is_some_and(|d| self.state.share.as_ref().is_some_and(|s| s.session == d));
|
||||
let session = st.data.stream.as_ref().map(|s| s.session);
|
||||
let viewer_name = |v: &ViewerInfo| logic::viewer_name(&self.state, session, v.client);
|
||||
let cx = logic::StatusContext {
|
||||
@@ -1068,7 +1068,7 @@ impl App {
|
||||
if self.studio.data.stream.is_some() || self.studio_streamer().is_none() {
|
||||
return;
|
||||
}
|
||||
if self.share.as_ref().is_some_and(|s| s.session == session) {
|
||||
if self.state.share.as_ref().is_some_and(|s| s.session == session) {
|
||||
self.set_status("Stop sharing your screen first.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -101,3 +101,11 @@ pub(crate) struct StudioState {
|
||||
meters: Vec<Option<SourceHandle>>,
|
||||
has_preview: bool,
|
||||
}
|
||||
|
||||
impl StudioState {
|
||||
/// The Stream Studio streams to `session`: the events of that stream
|
||||
/// are its own.
|
||||
pub(crate) fn streams_to(&self, session: i64) -> bool {
|
||||
self.data.streams_to(session)
|
||||
}
|
||||
}
|
||||
@@ -509,14 +509,7 @@ fn share_rows(
|
||||
}
|
||||
|
||||
/// Share settings from the dialog.
|
||||
pub(crate) struct CaptureRequest {
|
||||
pub fps: u32,
|
||||
pub bitrate_kbps: u32,
|
||||
pub audio: bool,
|
||||
/// Mixed into the stream's audio (`stream.audio_sources`).
|
||||
pub audio_sources: Vec<AudioSourceSpec>,
|
||||
pub restore_token: Option<String>,
|
||||
}
|
||||
pub(crate) use crate::vm::streams::logic::CaptureRequest;
|
||||
|
||||
/// A running capture for our stream. Stops when dropped.
|
||||
pub(crate) struct Capture {
|
||||
|
||||
+23
-17
@@ -27,9 +27,12 @@ crates/voelin-ui-vm/ view models and state, no UI toolkit
|
||||
events/ events::apply: what an engine event does to the AppState
|
||||
(mod.rs; gateway.rs: the gateway's events and directory)
|
||||
previews.rs pictures linked in chat: which to fetch, the transfers
|
||||
servers.rs tree.rs chat/mod.rs social.rs home.rs streams.rs avatar.rs studio/mod.rs
|
||||
servers.rs tree.rs chat/mod.rs social.rs home.rs streams/mod.rs avatar.rs studio/mod.rs
|
||||
pure view models (engine state → bridge structs), unit-tested
|
||||
chat/logic.rs chat tabs, messages and what is read, pins and topics, files
|
||||
streams/logic.rs the streams we share and watch: their state, the events and the
|
||||
user's choices, the streams panel's, the share card's and the
|
||||
viewer's rows and texts
|
||||
settings.rs the UI's settings keys, the audio form
|
||||
settings_pages/logic.rs, studio/logic.rs
|
||||
the decisions of the settings pages and of the Stream Studio
|
||||
@@ -63,12 +66,14 @@ crates/voelin-ui/ the Slint front end
|
||||
a `voelin_ui_vm::state::AppState` and the window
|
||||
host.rs SlintHost (the answers the transitions ask for), `App::apply_event`,
|
||||
`transition` and `perform`: doing what an `Update` says
|
||||
servers.rs chat.rs members.rs streams.rs settings_page.rs appearance.rs
|
||||
servers.rs chat.rs members.rs settings_page.rs appearance.rs
|
||||
home.rs social.rs messages.rs events.rs previews.rs popout.rs
|
||||
the Slint side of each area (social.rs: contacts, the bell and the
|
||||
search; previews.rs: pictures in chat; popout.rs: the stream's own
|
||||
window)
|
||||
settings_pages/ mod.rs (Pages), bind.rs: the settings pages on the Bridge
|
||||
streams/ mod.rs (Share: the capture), bind.rs: the streams panel, the share
|
||||
dialog and the viewer on the Bridge, the capture and the decoder
|
||||
studio/ mod.rs (StudioState), bind.rs: the Stream Studio's windows and engine
|
||||
bind/ callbacks of each area, wired once; convert.rs, convert/items.rs
|
||||
(plain values → Slint values), rows.rs (a Slint model kept in step
|
||||
@@ -128,22 +133,22 @@ this file is `voelin_ui_vm::chat`. The boundary:
|
||||
update out in `host.rs`) and `social_refresh`; a GPUI client calls `apply`
|
||||
and draws what `Update::refresh` names. The vm tests replay tapes of events
|
||||
against a fake `Host` (`events/tests.rs`). `Update::rest` hands back the
|
||||
events whose state is not in the `AppState` yet: the stream we share and
|
||||
watch and the studio's (`StreamState`, `StreamViewerRequest`,
|
||||
`StreamViewers`, `WatchState`, `WatchLayers`, `StreamKeyframeRequest`,
|
||||
`StreamLayerBitrate`), `SettingChanged`, and the rest that no screen looks
|
||||
at. The friends, pokes, offline messages and notices that `social.rs` keeps
|
||||
events whose state is not in the `AppState`: the Stream Studio's stream
|
||||
(`StreamState` and `StreamViewers` while `Host::studio_streams_to`),
|
||||
`SettingChanged`, and the rest that no screen looks at. The streams we
|
||||
share and watch are in the `AppState` (`share`, `watch`; the capture and
|
||||
the decoder are the front end's, and an update says when to attach or drop
|
||||
them). The friends, pokes, offline messages and notices that `social.rs` keeps
|
||||
(`Poke`, `FriendPresence`, `OfflineMessages`, `OfflineMessage`,
|
||||
`RequestDone`, and the notices of `Chat`, `ChatHistory`, `Presence`,
|
||||
`State`, `ServerInfo`, `ContactsChanged`, `AvatarReady`) are looked at by
|
||||
`social.rs` before and after `apply`. They move with `streams.rs` and
|
||||
`social.rs`.
|
||||
`social.rs` before and after `apply`. They move with `social.rs`.
|
||||
- **Logic and bind.** An area that interleaves decisions with Bridge writes
|
||||
is split into `<area>/logic.rs` in `voelin-ui-vm` (functions over the
|
||||
settings service, the `AppState` and plain rows; they return rows,
|
||||
commands or messages for the status line, and write no Bridge) and
|
||||
`<area>/bind.rs` in `voelin-ui` (the Bridge and model writes, windows,
|
||||
timers, threads, engine commands). Done: `settings_pages` and `studio`.
|
||||
timers, threads, engine commands). Done: `settings_pages`, `studio` and `streams`.
|
||||
|
||||
The pure code is tested in `voelin-ui-vm` (`cargo test -p voelin-ui-vm`,
|
||||
no display); the Slint crate's tests are what needs the window types.
|
||||
@@ -164,7 +169,6 @@ the same shape as `settings_pages` and `studio`: move the decisions into
|
||||
|
||||
| File | `.set_` calls | What it mixes |
|
||||
|---|---|---|
|
||||
| `streams.rs` | 45 | the streams panel, viewer and share dialog: what the voice card, the viewer header and the share form say, with the watch and share bookkeeping |
|
||||
| `chat.rs` | 33 | the chat view: lines, the unread divider, pins, topics and downloads (the engine's history batches, the reads and the gateway's pins and topics are in `chat/logic.rs`) |
|
||||
| `app.rs` | 31 | setup, the status line, the toolbar and tree refreshes (the event dispatch is `vm::events::apply`) |
|
||||
| `servers.rs` | 32 | the rail, the server dialog and the channel tree's refresh (the server's name, icon and gateway, joining again and the password are in `events`) |
|
||||
@@ -180,17 +184,19 @@ the same shape as `settings_pages` and `studio`: move the decisions into
|
||||
Before the work on `voelin-ui-vm` began, `studio.rs` had 64 `.set_` calls
|
||||
and `settings_pages.rs` 52 (the two with the most, then `streams.rs` with 45;
|
||||
62 was `studio.rs` once the view models had moved, two setters having
|
||||
gone with them). Their `bind.rs` files still show 58 and 51: the Bridge and model writes
|
||||
stay where the toolkit is, and what each write says now comes from
|
||||
`logic.rs`, which has tests of its own.
|
||||
gone with them). Their `bind.rs` files still show 58 and 51 (and
|
||||
`streams/bind.rs`, split from the 45 of `streams.rs`, 38): the Bridge and
|
||||
model writes stay where the toolkit is, and what each write says now comes
|
||||
from `logic.rs`, which has tests of its own.
|
||||
|
||||
Why the studio went before `streams.rs`: it had the most calls, and it is
|
||||
self-contained. It has its own state (`StudioState`), windows and bridge
|
||||
(`studio-bridge.slint`), so its decisions moved without touching the event
|
||||
dispatch of `app.rs`. `streams.rs`, `chat.rs` and the rest of the list are
|
||||
driven by that dispatch (the watch, share and history events of `events.rs`
|
||||
and `app.rs`), so they follow it: the state transition of every engine event
|
||||
comes first, then the controllers that show the result.
|
||||
driven by that dispatch (the watch, share and history events), so they
|
||||
followed it: the state transition of every engine event came first
|
||||
(`events::apply`), then the controllers that show the result, `streams` first
|
||||
as the one whose events were still the front end's.
|
||||
|
||||
## Theme tokens
|
||||
|
||||
|
||||
Reference in new issue
Block a user