diff --git a/crates/tinyclient/src/gui/call/health.rs b/crates/tinyclient/src/gui/call/health.rs index ad2b2b9b..72fadd95 100644 --- a/crates/tinyclient/src/gui/call/health.rs +++ b/crates/tinyclient/src/gui/call/health.rs @@ -185,6 +185,7 @@ pub(in crate::gui) struct ChartSample { pub at: Instant, pub rtt_ms: u32, pub recv_kbps: u32, + pub video_kbps: Option<(u32, u32)>, } /// Append one poll to the chart, dropping the oldest past [`CHART_SECONDS`]. @@ -192,7 +193,7 @@ pub(in crate::gui) fn push_chart(samples: &mut VecDeque, stats: &Ca if samples.len() >= CHART_SECONDS { samples.pop_front(); } - samples.push_back(ChartSample { at, rtt_ms: stats.rtt_ms, recv_kbps: stats.receive_kbps }); + samples.push_back(ChartSample { at, rtt_ms: stats.rtt_ms, recv_kbps: stats.receive_kbps, video_kbps: stats.video.as_ref().map(|video| (video.send_kbps, video.receive_kbps)) }); } /// A full minute of made-up samples around `stats`, for `--shot` so the graph is not empty. @@ -207,6 +208,7 @@ pub(in crate::gui) fn seed_chart(stats: &CallStats, now: Instant) -> VecDeque>(), [None, Some((440, 800)), None]); + assert!(samples.iter().all(|sample| sample.rtt_ms == 40 && sample.recv_kbps == 900)); + } + #[test] fn a_packet_lost_now_and_then_does_not_move_the_bars() { // One packet of fifty is 20 per mille, and three in one bad second is 60: the old grade diff --git a/crates/tinyclient/src/gui/call/shot.rs b/crates/tinyclient/src/gui/call/shot.rs index 5d2aaa85..75257953 100644 --- a/crates/tinyclient/src/gui/call/shot.rs +++ b/crates/tinyclient/src/gui/call/shot.rs @@ -21,6 +21,9 @@ //! //! `tiny_sharing` is a call where I share my screen and mediad has painted the first picture of //! it for my own tile (a made-up one, the demo's schematic); `--tiny-stream` focuses my stream. +//! +//! `TINYCLIENT_SHOT_VIDEO=1` adds sample video metrics; `--tiny-menu stats-video` selects +//! the compact health card's Video tab. These are design previews, not measured call proof. use super::phone::{Sheet, Shown}; use super::security::Place; @@ -65,6 +68,11 @@ pub(super) fn stats() -> Option { let name = asked().filter(|name| name.starts_with("tiny_"))?; let poor = name == "tiny_poor"; Some(protocol::CallStats { + video: std::env::var_os("TINYCLIENT_SHOT_VIDEO").map(|_| protocol::VideoStats { + send_kbps: 440, receive_kbps: 2100, send_fps: 30, receive_fps: 60, rendered_fps: 58, + receive_expected: true, watching_ms: 30_000, width: 1920, height: 1080, frame_age_ms: Some(16), + }), + link_measured: true, rtt_ms: if poor { 184 } else { 38 }, jitter_ms: if poor { 41 } else { 4 }, loss_permille: if poor { 62 } else { 2 }, diff --git a/crates/tinyclient/src/gui/mod.rs b/crates/tinyclient/src/gui/mod.rs index 3ae24de1..19875898 100644 --- a/crates/tinyclient/src/gui/mod.rs +++ b/crates/tinyclient/src/gui/mod.rs @@ -62,6 +62,28 @@ pub(crate) fn prove_health_grade() -> Result<(), &'static str> { } } +/// The lab's compact-call-health driver. The Video tab's history holds video's own rates, and +/// holds nothing for the seconds no video ran. +pub(crate) fn prove_compact_call_health() -> Result<(), &'static str> { + let mut samples = std::collections::VecDeque::new(); + let mut stats = protocol::CallStats { rtt_ms: 40, receive_kbps: 900, ..Default::default() }; + let now = std::time::Instant::now(); + call::health::push_chart(&mut samples, &stats, now); + stats.video = Some(protocol::VideoStats { send_kbps: 440, receive_kbps: 800, ..Default::default() }); + call::health::push_chart(&mut samples, &stats, now + std::time::Duration::from_secs(1)); + stats.video = None; + call::health::push_chart(&mut samples, &stats, now + std::time::Duration::from_secs(2)); + let video: Vec<_> = samples.iter().map(|sample| sample.video_kbps).collect(); + if video != [None, Some((440, 800)), None] { + return Err("the Video tab's history did not keep video's own rates"); + } + if samples.iter().all(|sample| sample.rtt_ms == 40 && sample.recv_kbps == 900) { + Ok(()) + } else { + Err("video samples changed the Connection tab's history") + } +} + /// The lab's cancel-join driver. A leave is accepted while a join is still in flight. pub(crate) fn prove_cancel_join() -> Result<(), &'static str> { if tiny::call_accepts(true, true) && !tiny::call_accepts(true, false) { diff --git a/crates/tinyclient/src/gui/tiny/layer.rs b/crates/tinyclient/src/gui/tiny/layer.rs index aad7ccf8..69e0bf1d 100644 --- a/crates/tinyclient/src/gui/tiny/layer.rs +++ b/crates/tinyclient/src/gui/tiny/layer.rs @@ -109,7 +109,7 @@ impl Shell { } Float::Stats => { let at = anchor(RAIL_WIDTH + 8., tall - PANEL, sidebar - 16., PANEL); - let card = popover().p(px(14.)).child(self.tiny_stats_card()); + let card = popover().p(px(14.)).child(self.tiny_stats_card(cx)); out.push(placed("tiny-stats", Place::Above(at), Layer::Popover, window, fade_in("tiny-stats-fade", 120, card))); } } diff --git a/crates/tinyclient/src/gui/tiny/mod.rs b/crates/tinyclient/src/gui/tiny/mod.rs index 7cd2d4ac..c968f9c7 100644 --- a/crates/tinyclient/src/gui/tiny/mod.rs +++ b/crates/tinyclient/src/gui/tiny/mod.rs @@ -243,6 +243,7 @@ pub struct State { stats_before: Option, /// The last minute of ping and receive bitrate for Call health's time graph. stats_chart: VecDeque, + stats_tab: panel::StatsTab, /// The polls over the last several seconds: what the bars and the numbers show. steady: health::Steady, /// Why there are no numbers, when mediad said. @@ -336,6 +337,7 @@ impl State { stats: None, stats_before: None, stats_chart: VecDeque::new(), + stats_tab: panel::StatsTab::default(), steady: health::Steady::default(), stats_note: None, stats_task: None, @@ -1573,6 +1575,10 @@ impl Shell { } } match flag("--tiny-menu").as_deref() { + Some("stats-video") => { + self.tiny_state.stats_tab = panel::StatsTab::Video; + self.tiny_open_float(Float::Stats, cx); + } Some("header") => self.tiny_open_float(Float::Header, cx), Some("stats") => self.tiny_open_float(Float::Stats, cx), Some("channel") => { diff --git a/crates/tinyclient/src/gui/tiny/panel.rs b/crates/tinyclient/src/gui/tiny/panel.rs index b4e08f5f..e1d74eff 100644 --- a/crates/tinyclient/src/gui/tiny/panel.rs +++ b/crates/tinyclient/src/gui/tiny/panel.rs @@ -6,7 +6,7 @@ use super::Float; use crate::gui::call::health::{self, ChartSample, Grade, Health}; -use crate::gui::components::{glyph, tip, Avatar}; +use crate::gui::components::{glyph, segment, segmented, tip, Avatar}; use crate::gui::state::Shell; use crate::gui::theme::{self, Type}; use gpui::{ @@ -16,6 +16,13 @@ use protocol::{CallPath, CallState, Presence}; pub(super) const PANEL: f32 = 52.; +#[derive(Clone, Copy, Default, PartialEq, Eq)] +pub(super) enum StatsTab { + #[default] + Connection, + Video, +} + /// One of the panel's three buttons. `off` draws it struck through in `danger`. fn panel_button(id: &'static str, icon: &'static str, off: bool) -> Stateful
{ div() @@ -118,12 +125,22 @@ fn kpi(label: &'static str, value: String, unit: &'static str, color: Rgba) -> D ) } -/// Ping (filled) and receive bitrate over the last minute. `now_*` are the same numbers the -/// KPI strip shows (smoothed ping, current receive), so the footer does not disagree with them. -fn health_chart(samples: Vec, now_rtt: Option, now_recv: u32) -> Div { - let foot = match now_rtt { - Some(rtt) => format!("Now · {rtt} ms · {now_recv} kb/s"), - None => format!("Now · — · {now_recv} kb/s"), +/// The selected tab's measured history, with current values in the footer. Video send and +/// receive share one bitrate scale; connection RTT and receive retain their own scales. +fn health_chart(mut samples: Vec, now_rtt: Option, now_recv: u32, video: bool) -> Div { + // One chart slot, with only the selected tab's series. Video's two rates share a scale. + if video { + for sample in &mut samples { + let (sent, received) = sample.video_kbps.unwrap_or_default(); + sample.rtt_ms = sent; + sample.recv_kbps = received; + } + } + let foot = match (video, now_rtt) { + (true, Some(sent)) => format!("↑ {sent} · ↓ {now_recv} kb/s"), + (true, None) => "—".to_owned(), + (false, Some(rtt)) => format!("{rtt} ms · {now_recv} kb/s"), + (false, None) => format!("— · {now_recv} kb/s"), }; let chart = canvas( |_, _, _| (), @@ -139,19 +156,18 @@ fn health_chart(samples: Vec, now_rtt: Option, now_recv: u32) let y = origin_y + height * frac; window.paint_quad(fill(Bounds::new(point(px(origin_x), px(y)), size(px(width), px(1.))), theme::hairline())); } - let first = samples.first().map(|sample| sample.at).unwrap_or_else(std::time::Instant::now); - let last_at = samples.last().map(|sample| sample.at).unwrap_or(first); - let span = last_at.duration_since(first).as_secs_f32().max(0.001); + let last_at = samples.last().map(|sample| sample.at).unwrap_or_else(std::time::Instant::now); let max_rtt = samples.iter().map(|sample| sample.rtt_ms).max().unwrap_or(1).max(1) as f32; let max_recv = samples.iter().map(|sample| sample.recv_kbps).max().unwrap_or(1).max(1) as f32; - let x_at = |sample: &ChartSample| origin_x + width * sample.at.duration_since(first).as_secs_f32() / span; + let max_video = max_rtt.max(max_recv); + let x_at = |sample: &ChartSample| origin_x + width * (1. - last_at.saturating_duration_since(sample.at).as_secs_f32() / 60.).clamp(0., 1.); let ping_y = |rtt: u32| { - let t = (rtt as f32 / (max_rtt * 1.2)).clamp(0., 1.); - origin_y + height * (0.42 + 0.5 * (1. - t)) + let t = (rtt as f32 / (if video { max_video } else { max_rtt } * 1.2)).clamp(0., 1.); + origin_y + height * if video { 0.06 + 0.86 * (1. - t) } else { 0.42 + 0.5 * (1. - t) } }; let recv_y = |kbps: u32| { - let t = (kbps as f32 / (max_recv * 1.2)).clamp(0., 1.); - origin_y + height * (0.06 + 0.3 * (1. - t)) + let t = (kbps as f32 / (if video { max_video } else { max_recv } * 1.2)).clamp(0., 1.); + origin_y + height * if video { 0.06 + 0.86 * (1. - t) } else { 0.06 + 0.3 * (1. - t) } }; let mut area = PathBuilder::fill(); @@ -233,7 +249,7 @@ fn health_chart(samples: Vec, now_rtt: Option, now_recv: u32) .items_center() .gap(px(5.)) .child(div().size(px(7.)).rounded_full().bg(theme::positive())) - .child(div().type_micro().text_color(theme::text_soft()).child("RTT")), + .child(div().type_micro().text_color(theme::text_soft()).child(if video { "Send" } else { "RTT" })), ) .child( div() @@ -358,144 +374,105 @@ impl Shell { self.tiny_state.stats.as_ref().map(|stats| self.tiny_state.steady.applied(Health::from_polls(before, stats))) } - /// Call health, over the panel: the link graded, what to do about it in words, the last - /// minute on a graph, key numbers, then the connection's details. - pub(super) fn tiny_stats_card(&self) -> Div { - let room = self.tiny_page_facts().and_then(|page| page.mine.and_then(|id| page.community.rooms.iter().find(|room| room.id == id)).map(|room| (room.name.clone(), room.bitrate()))); + /// One compact view at a time, with the same chart area in both tabs. + pub(super) fn tiny_stats_card(&self, cx: &mut Context) -> Div { let health = self.tiny_health().unwrap_or_default(); let grade = health.grade(); let hints = health.hints(); - let mut card = div().w(px(320.)).flex().flex_col().child( - div() - .pb(px(10.)) - .flex() - .items_start() - .justify_between() - .gap(px(8.)) - .child( - div() - .min_w_0() - .flex_1() - .child( - div() - .flex() - .items_center() - .gap(px(8.)) - .child(health::bars(grade, 14.)) - .child(div().type_ui().font_weight(theme::SEMIBOLD).text_color(theme::text()).child("Call health")), - ) - .children(hints.iter().take(1).map(|hint| { - div() - .mt(px(6.)) - .flex() - .items_start() - .gap(px(6.)) - .child(div().pt(px(1.)).child(glyph(hint.level.icon(), 12., hint.level.color()))) - .child(div().flex_1().min_w_0().whitespace_normal().type_small().text_color(hint.level.color()).child(hint.words.clone())) - })), - ) - .child( - div() - .flex_none() - .px(px(8.)) - .py(px(3.)) - .rounded_full() - .bg(match grade { - Grade::Great | Grade::Good => theme::positive_soft(), - Grade::Fair => theme::warning_soft(), - Grade::Poor => theme::danger_soft(), - Grade::Unknown => theme::field(), - }) - .type_micro() - .font_weight(theme::SEMIBOLD) - .text_color(grade.color()) - .child(grade_badge(grade)), - ), - ); - - if hints.len() > 1 { - card = card.child( - div().pb(px(8.)).mb(px(4.)).border_b_1().border_color(theme::hairline()).flex().flex_col().gap(px(6.)).children(hints.into_iter().skip(1).take(2).map(|hint| { - div() - .flex() - .items_start() - .gap(px(8.)) - .child(div().pt(px(2.)).child(glyph(hint.level.icon(), 13., hint.level.color()))) - .child(div().flex_1().min_w_0().whitespace_normal().type_small().text_color(theme::text()).child(hint.words)) - })), - ); + let details = hints.iter().map(|hint| hint.words.as_str()).collect::>().join("\n"); + let video_tab = self.tiny_state.stats_tab == StatsTab::Video; + let mut card = div().w(px(320.)).flex().flex_col() + .child(div().pb(px(10.)).flex().items_center().justify_between().gap(px(8.)) + .child(div().flex().items_center().gap(px(8.)) + .child(health::bars(grade, 14.)) + .child(div().type_ui().font_weight(theme::SEMIBOLD).text_color(theme::text()).child("Call health")) + .child(div().id("call-health-info").flex().items_center() + .tooltip(tip(details, None)) + .child(glyph("icons/info.svg", 13., theme::text_faint())))) + .child(div().px(px(8.)).py(px(3.)).rounded_full() + .bg(match grade { + Grade::Great | Grade::Good => theme::positive_soft(), + Grade::Fair => theme::warning_soft(), + Grade::Poor => theme::danger_soft(), + Grade::Unknown => theme::field(), + }).type_micro().font_weight(theme::SEMIBOLD).text_color(grade.color()).child(grade_badge(grade)))) + .child(segmented().mb(px(10.)) + .child(segment("call-health-connection", "Connection", !video_tab).flex_1().justify_center() + .tab_index(0).focus_visible(|style| style.shadow(theme::focus_ring())) + .on_key_down(cx.listener(|this, event: &gpui::KeyDownEvent, _, cx| { + if !event.keystroke.modifiers.modified() && matches!(event.keystroke.key.as_str(), "enter" | "space") { + this.tiny_state.stats_tab = StatsTab::Connection; + cx.stop_propagation(); + cx.notify(); + } + })) + .on_click(cx.listener(|this, _, _, cx| { + this.tiny_state.stats_tab = StatsTab::Connection; + cx.notify(); + }))) + .child(segment("call-health-video", "Video", video_tab).flex_1().justify_center() + .tab_index(0).focus_visible(|style| style.shadow(theme::focus_ring())) + .on_key_down(cx.listener(|this, event: &gpui::KeyDownEvent, _, cx| { + if !event.keystroke.modifiers.modified() && matches!(event.keystroke.key.as_str(), "enter" | "space") { + this.tiny_state.stats_tab = StatsTab::Video; + cx.stop_propagation(); + cx.notify(); + } + })) + .on_click(cx.listener(|this, _, _, cx| { + this.tiny_state.stats_tab = StatsTab::Video; + cx.notify(); + })))); + // A real problem stays visible whichever tab is selected; its full explanation is on hover. + if let Some(hint) = hints.first().filter(|hint| hint.level == health::Level::Bad || hint.level == health::Level::Warn) { + card = card.child(div().id("call-health-warning").mb(px(8.)).truncate().type_small() + .text_color(hint.level.color()).tooltip(tip(hint.words.clone(), None)).child(hint.words.clone())); } - - match &self.tiny_state.stats { - Some(stats) => { - // The bars smooth recent readings, but the numeric details are this sample. - let rtt = (stats.rtt_ms > 0).then_some(stats.rtt_ms); - let jitter = stats.link_measured.then_some(stats.jitter_ms); - let loss = stats.link_measured.then_some(stats.loss_permille); - let samples: Vec<_> = self.tiny_state.stats_chart.iter().copied().collect(); - if !samples.is_empty() { - card = card.child(health_chart(samples, rtt, stats.receive_kbps)); - } - let known = |measured: bool| if measured { theme::positive() } else { theme::text_soft() }; - card = card - .child( - div() - .mb(px(10.)) - .flex() - .gap(px(8.)) - .child(kpi( - "RTT", - rtt.map_or_else(|| "—".to_owned(), |ms| ms.to_string()), - "ms", - known(rtt.is_some()), - )) - .child(kpi( - "Jitter", - jitter.map_or_else(|| "—".to_owned(), |ms| ms.to_string()), - "ms", - known(jitter.is_some()), - )) - .child(kpi( - "Loss", - loss.map_or_else(|| "—".to_owned(), |n| format!("{:.1}", f32::from(n) / 10.)), - "%", - known(loss.is_some()), - )), - ) - .when_some(room.as_ref(), |card, (name, kbps)| { - card.child(meta_row("Channel", name.clone())).child(meta_row("Audio target", format!("{kbps} kb/s"))) - }) - .child(meta_row("Sending", format!("{} kb/s", stats.send_kbps))) - .child(meta_row("Receiving", format!("{} kb/s", stats.receive_kbps))) - .child(meta_row( - "Path", - div() - .px(px(7.)) - .py(px(2.)) - .rounded_full() - .bg(theme::selected()) - .flex() - .items_center() - .gap(px(5.)) - .child(div().size(px(6.)).rounded_full().bg(theme::positive())) - .child(div().type_micro().font_weight(theme::SEMIBOLD).text_color(theme::text()).child(path_pill(stats.path))), - )) - .when(!stats.codec.is_empty(), |card| card.child(meta_row("Audio codec", stats.codec.clone()))) - .child(div().mt(px(6.)).whitespace_normal().type_micro().text_color(theme::text_soft()).child("RTT is the round trip to the call server, not playback delay. Sending and receiving include the whole call.")); - if let Some(video) = &stats.video { - card = card - .child(meta_row("Video sending", format!("{} kb/s · {} fps", video.send_kbps, video.send_fps))) - .child(meta_row("Video receiving", format!("{} kb/s · {} fps", video.receive_kbps, video.receive_fps))) - .child(meta_row("Video images", format!("{} fps", video.rendered_fps))) - .child(meta_row("Received size", if video.width > 0 { format!("{} × {}", video.width, video.height) } else { "Waiting for video".to_owned() })) - .child(meta_row("Last video image", video.frame_age_ms.map_or_else(|| "None yet".to_owned(), |age| format!("{age} ms ago")))) - .child(div().whitespace_normal().type_micro().text_color(theme::text_soft()).child("Video rates combine screen sharing and camera layers. Sending is measured after pacing; TCP may still buffer it. Video images counts completed images prepared for this window. Video codec: H.264.")); - } - } - None => { - let words: SharedString = self.tiny_state.stats_note.clone().unwrap_or_else(|| "Measuring…".to_owned()).into(); - card = card.child(div().pt(px(4.)).whitespace_normal().type_small().text_color(theme::text_soft()).child(words)); + let Some(stats) = &self.tiny_state.stats else { + return card.child(div().h(px(260.)).flex().items_center().justify_center().type_small() + .text_color(theme::text_soft()).child(self.tiny_state.stats_note.clone().unwrap_or_else(|| "Measuring…".to_owned()))); + }; + let samples: Vec<_> = self.tiny_state.stats_chart.iter().copied().collect(); + let row = |label, value: String, unit, measured, help| { + kpi(label, value, unit, if measured { theme::positive() } else { theme::text_soft() }) + .id(SharedString::from(format!("call-health-kpi-{label}"))).tooltip(tip(help, None)) + }; + if video_tab { + let Some(video) = &stats.video else { + return card.child(div().h(px(260.)).flex().flex_col().items_center().justify_center().gap(px(10.)) + .child(glyph("icons/monitor-up.svg", 26., theme::text_faint())) + .child(div().type_small().text_color(theme::text_soft()).child("No video active"))); + }; + let incoming = video.receive_expected; + card = card.child(health_chart(samples, Some(video.send_kbps), video.receive_kbps, true)) + .child(div().mb(px(10.)).flex().gap(px(8.)) + .child(row("Sending", video.send_fps.to_string(), "fps", true, + "Original video frames emitted after pacing, across screen sharing and camera layers. Retransmissions are not new frames; TCP may still buffer output.")) + .child(row("Receiving", if incoming { video.receive_fps.to_string() } else { "—".to_owned() }, "fps", incoming, + "Complete incoming video frames per second. No value while you are not watching.")) + .child(row("Rendered", if incoming { video.rendered_fps.to_string() } else { "—".to_owned() }, "fps", incoming, + "Completed video images prepared for this window, not monitor refreshes."))); + if incoming { + card = card.child(meta_row("Resolution", if video.width > 0 { format!("{} × {}", video.width, video.height) } else { "Waiting…".to_owned() })) + .child(meta_row("Last image", video.frame_age_ms.map_or_else(|| "None yet".to_owned(), |age| format!("{age} ms ago")))); + } else { + card = card.child(meta_row("Playback", "Not watching")).child(meta_row("Codec", "H.264")); } + } else { + let rtt = (stats.rtt_ms > 0).then_some(stats.rtt_ms); + let jitter = stats.link_measured.then_some(stats.jitter_ms); + let loss = stats.link_measured.then_some(stats.loss_permille); + card = card.child(health_chart(samples, rtt, stats.receive_kbps, false)) + .child(div().mb(px(10.)).flex().gap(px(8.)) + .child(row("RTT", rtt.map_or_else(|| "—".to_owned(), |ms| ms.to_string()), "ms", rtt.is_some(), + "Round-trip time to the call server, not one-way playback delay. Numeric values are the current sample; signal bars smooth recent measurements.")) + .child(row("Jitter", jitter.map_or_else(|| "—".to_owned(), |ms| ms.to_string()), "ms", jitter.is_some(), + "Variation in packet arrival timing. No value when traffic is insufficient to measure it.")) + .child(row("Loss", loss.map_or_else(|| "—".to_owned(), |n| format!("{:.1}", f32::from(n) / 10.)), "%", loss.is_some(), + "Measured packet loss on your connection, after repair."))) + .child(meta_row("Traffic", format!("↑ {} · ↓ {} kb/s", stats.send_kbps, stats.receive_kbps)) + .id("call-health-traffic").tooltip(tip("Total sending and receiving for the whole call, including video and transport overhead.", None))) + .child(meta_row("Transport", format!("{}{}", path_pill(stats.path), if stats.codec.is_empty() { String::new() } else { format!(" · {}", stats.codec.to_uppercase()) }))); } card } diff --git a/crates/tinyclient/src/gui/tiny/settings/voice.rs b/crates/tinyclient/src/gui/tiny/settings/voice.rs index f66cc0d7..4e032b28 100644 --- a/crates/tinyclient/src/gui/tiny/settings/voice.rs +++ b/crates/tinyclient/src/gui/tiny/settings/voice.rs @@ -46,7 +46,7 @@ fn fact(label: &'static str, value: impl Into) -> Div { } pub(in crate::gui::tiny) fn voice(shell: &Shell, facts: &Facts, window: &mut Window, cx: &mut Context) -> AnyElement { - let _ = (window, cx); + let _ = window; let community = facts.community; let mut page = div().flex().flex_col().gap(px(28.)).child(page_head("Voice & media", "How this server's audio is doing, and what it asks of a connection.")); @@ -162,7 +162,7 @@ pub(in crate::gui::tiny) fn voice(shell: &Shell, facts: &Facts, window: &mut Win // My own call. page = page.child(section("Your connection").child(if shell.tiny_call().is_some() { - card().p(px(16.)).child(shell.tiny_stats_card()) + card().p(px(16.)).child(shell.tiny_stats_card(cx)) } else { kit::note("icons/info.svg", theme::text_faint(), "Join a channel here to see your own connection: ping, jitter, loss, bitrate and the path your audio takes.") })); diff --git a/crates/tinyclient/src/main.rs b/crates/tinyclient/src/main.rs index 56934530..14569315 100644 --- a/crates/tinyclient/src/main.rs +++ b/crates/tinyclient/src/main.rs @@ -232,6 +232,15 @@ fn main() -> ExitCode { } return ExitCode::SUCCESS; } + // The lab's compact-call-health driver. A build without this opens the window below and stays up. + #[cfg(feature = "gui")] + if std::env::var("TINYCLIENT_PROVE").ok().as_deref() == Some("compact-call-health") { + if let Err(err) = gui::prove_compact_call_health() { + eprintln!("compact-call-health: {err}"); + return ExitCode::from(1); + } + return ExitCode::SUCCESS; + } // The lab's cancel-join driver. A build without this opens the window below and stays up. #[cfg(feature = "gui")] if std::env::var("TINYCLIENT_PROVE").ok().as_deref() == Some("cancel-join") { diff --git a/e2e/scenarios/compact-call-health/drive.linux.sh b/e2e/scenarios/compact-call-health/drive.linux.sh new file mode 100755 index 00000000..5df6a013 --- /dev/null +++ b/e2e/scenarios/compact-call-health/drive.linux.sh @@ -0,0 +1,9 @@ +#!/bin/bash +# compact-call-health on Linux. The lab runs this with bash while ffmpeg films the display. +set -u +HERE=$(cd "$(dirname "$0")" && pwd) +if command -v python3 >/dev/null 2>&1; then + exec python3 "$HERE/drive.py" +fi +echo "python3 is not on PATH" >&2 +exit 1 diff --git a/e2e/scenarios/compact-call-health/drive.macos.sh b/e2e/scenarios/compact-call-health/drive.macos.sh new file mode 100755 index 00000000..a5cd8f49 --- /dev/null +++ b/e2e/scenarios/compact-call-health/drive.macos.sh @@ -0,0 +1,9 @@ +#!/bin/bash +# compact-call-health on macOS. The lab runs this with bash while ffmpeg films the display. +set -u +HERE=$(cd "$(dirname "$0")" && pwd) +if command -v python3 >/dev/null 2>&1; then + exec python3 "$HERE/drive.py" +fi +echo "python3 is not on PATH" >&2 +exit 1 diff --git a/e2e/scenarios/compact-call-health/drive.py b/e2e/scenarios/compact-call-health/drive.py new file mode 100755 index 00000000..fb18d6b5 --- /dev/null +++ b/e2e/scenarios/compact-call-health/drive.py @@ -0,0 +1,83 @@ +#!/usr/bin/env python3 +"""Call health keeps a Connection tab and a Video tab, each with its own history. + +Starts this build's tinyclient with TINYCLIENT_PROVE=compact-call-health. That build exits 0 only +when the Video tab's history holds video's own rates and none for the seconds without video. A +build from before the change ignores the variable and opens the window, so this driver fails there. + +Env from the lab: E2E_OUT, E2E_T0, E2E_APP_DIR. +""" + +import os +import subprocess +import sys +import time + +OUT = os.environ.get("E2E_OUT", "") +T0 = float(os.environ.get("E2E_T0") or time.time()) +APP = os.environ.get("E2E_APP_DIR", "") + +FAILED = False +STEPS = "" + + +def now(): + return time.time() - T0 + + +def step(words, ok): + global FAILED + if not ok: + FAILED = True + line = '{"t": %s, "step": "%s", "ok": %s}' % (round(now(), 1), words.replace('"', "'"), "true" if ok else "false") + print(("[ok] " if ok else "[FAILED] ") + words, flush=True) + if STEPS: + with open(STEPS, "a", encoding="utf-8") as handle: + handle.write(line + "\n") + + +def app_bin(app_dir): + name = "tinyclient.exe" if sys.platform == "win32" else "tinyclient" + if sys.platform == "darwin" and app_dir.endswith(".app"): + return os.path.join(app_dir, "Contents", "MacOS", "tinyclient") + return os.path.join(app_dir, name) + + +def main(): + global STEPS + if not OUT or not APP: + print("E2E_OUT and E2E_APP_DIR are required", file=sys.stderr) + return 1 + os.makedirs(OUT, exist_ok=True) + STEPS = os.path.join(OUT, "steps.jsonl") + open(STEPS, "w", encoding="utf-8").close() + binary = app_bin(APP) + if not os.path.isfile(binary): + step("tinyclient is in E2E_APP_DIR", False) + return 1 + + data = os.path.join(OUT, "data") + os.makedirs(data, exist_ok=True) + env = os.environ.copy() + env["TINYCLIENT_DIR"] = data + env["TINYCLIENT_PROVE"] = "compact-call-health" + env["TINYCLIENT_LOG_LEVEL"] = "info" + kwargs = {"cwd": data, "env": env, "stdin": subprocess.DEVNULL} + if sys.platform == "win32": + kwargs["creationflags"] = 0x08000000 + with open(os.path.join(OUT, "app.out.log"), "w", encoding="utf-8") as out, open(os.path.join(OUT, "app.err.log"), "w", encoding="utf-8") as err: + kwargs["stdout"] = out + kwargs["stderr"] = err + proc = subprocess.Popen([binary], **kwargs) + try: + code = proc.wait(timeout=45) + except subprocess.TimeoutExpired: + proc.kill() + proc.wait(timeout=5) + code = None + step("the Video tab keeps its own history", code == 0) + return 1 if FAILED else 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/e2e/scenarios/compact-call-health/drive.windows.ps1 b/e2e/scenarios/compact-call-health/drive.windows.ps1 new file mode 100644 index 00000000..06d8a3b7 --- /dev/null +++ b/e2e/scenarios/compact-call-health/drive.windows.ps1 @@ -0,0 +1,17 @@ +# compact-call-health on Windows. The lab runs this in the console session it is already filming. +$ErrorActionPreference = 'Stop' +$drive = Join-Path $PSScriptRoot 'drive.py' +if (Get-Command py -ErrorAction SilentlyContinue) { + & py -3 $drive + exit $LASTEXITCODE +} +if (Get-Command python -ErrorAction SilentlyContinue) { + & python $drive + exit $LASTEXITCODE +} +if (Get-Command python3 -ErrorAction SilentlyContinue) { + & python3 $drive + exit $LASTEXITCODE +} +Write-Host 'python is not on PATH (tried py -3, python, python3)' +exit 1 diff --git a/e2e/scenarios/compact-call-health/scenario.json b/e2e/scenarios/compact-call-health/scenario.json new file mode 100644 index 00000000..57da0406 --- /dev/null +++ b/e2e/scenarios/compact-call-health/scenario.json @@ -0,0 +1,12 @@ +{ + "id": "compact-call-health", + "title": "Call health keeps a Connection tab and a Video tab, each with its own history", + "platforms": ["windows", "linux", "macos"], + "not_applicable": { + "android": "The phone proof build does not run the desktop window. The phone shows call health on its own sheet.", + "ios": "The phone proof build does not run the desktop window. The phone shows call health on its own sheet." + }, + "needs": [], + "release": false, + "max_still_seconds": 60 +}