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>
74 lines
2.2 KiB
Rust
74 lines
2.2 KiB
Rust
//! Streams on the voice view, the phone's Activity tab and Home: what is
|
|
//! 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;
|
|
|
|
use voelin_core::stream::StreamKind;
|
|
|
|
use crate::avatar;
|
|
use crate::bridge::StreamItem;
|
|
|
|
/// "Screen", "Window", "Camera"; "" for a kind we do not know.
|
|
pub fn kind_label(kind: &StreamKind) -> &'static str {
|
|
match kind {
|
|
StreamKind::Screen => "Screen",
|
|
StreamKind::Window => "Window",
|
|
StreamKind::Camera => "Camera",
|
|
StreamKind::Other(_) => "",
|
|
}
|
|
}
|
|
|
|
/// A gateway directory's kind as a label: "screen" → "Screen".
|
|
pub fn directory_kind_label(kind: &str) -> String {
|
|
let mut chars = kind.chars();
|
|
chars.next().map(|c| c.to_uppercase().chain(chars).collect()).unwrap_or_default()
|
|
}
|
|
|
|
/// A stream with its streamer: the name, and the avatar as the members
|
|
/// show it (the picture from the engine's cache, else the initials on the
|
|
/// name's colour). The caller fills in the rest.
|
|
pub fn streamer(name: &str, picture: Option<&PathBuf>) -> StreamItem {
|
|
StreamItem {
|
|
streamer: name.into(),
|
|
initials: avatar::initials(name).into(),
|
|
tint: avatar::tint(name),
|
|
avatar: avatar::image(picture),
|
|
..StreamItem::default()
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
use crate::Size;
|
|
|
|
#[test]
|
|
fn kinds_have_labels() {
|
|
assert_eq!(kind_label(&StreamKind::Screen), "Screen");
|
|
assert_eq!(kind_label(&StreamKind::Window), "Window");
|
|
assert_eq!(kind_label(&StreamKind::Camera), "Camera");
|
|
assert_eq!(kind_label(&StreamKind::Other(9)), "");
|
|
assert_eq!(kind_label(&StreamKind::from_u8(2)), "Camera");
|
|
}
|
|
|
|
#[test]
|
|
fn directory_kinds_are_capitalised() {
|
|
assert_eq!(directory_kind_label("screen"), "Screen");
|
|
assert_eq!(directory_kind_label("Camera"), "Camera");
|
|
assert_eq!(directory_kind_label(""), "");
|
|
}
|
|
|
|
#[test]
|
|
fn streamers_look_as_in_the_members() {
|
|
let item = streamer("Nova Star", None);
|
|
assert_eq!(&*item.streamer, "Nova Star");
|
|
assert_eq!(&*item.initials, "NS");
|
|
assert_eq!(item.tint, avatar::tint("Nova Star"));
|
|
assert_eq!(item.avatar.size(), Size::default());
|
|
assert!(item.id.is_empty() && !item.own && !item.studio);
|
|
}
|
|
}
|