//! Websocket messages exchanged between the server and both browser views. //! //! Navigation state is authoritative on the server. Neither view tracks a slide //! index of its own: they send an intent, the server decides, and both learn the //! result from the same broadcast. That is what keeps the cast display and the //! presenter console from ever disagreeing -- particularly about whether the next //! keypress starts a video or advances the slide. use serde::{Deserialize, Serialize}; use crate::deck::{Deck, Diagnostic}; /// Server to client. #[derive(Debug, Clone, Serialize)] #[serde(tag = "type", rename_all = "camelCase")] pub enum ServerMessage { /// Full deck metadata. Sent on connect and after every successful recompile. Deck { deck: Deck, /// Current position, so a client that connects mid-talk lands correctly. page: usize, blank: bool, /// The video filling the screen right now, if any — so a view that joins /// mid-clip comes up enlarged rather than snapping back to the slide. fullscreen: Option, }, /// The current page changed. Nav { page: usize }, /// Act on a video overlay. Video { page: usize, id: String, action: VideoAction, /// Where to put the playhead, in seconds. Carried on `Play`, `Pause` and /// `Seek` so the display lands exactly where the presenter scrubbed to /// rather than approximately, or worse, back at the start. #[serde(skip_serializing_if = "Option::is_none")] time: Option, }, /// A video's media file became available, or failed to. MediaStatus { /// Media key, matching `Video::id` occurrences that share a source. src: String, state: MediaState, /// The URL to load once `state` is `ready`. url: Option, /// Why it failed, when `state` is `failed`. message: Option, }, /// Blank the display (a `b` press, so the audience looks at the speaker). Blank { blank: bool }, /// The deck failed to compile. The previous deck stays on screen underneath, /// so a typo mid-talk costs nothing. CompileError { diagnostics: Vec }, /// A previously failing deck compiles again. CompileOk, } /// Client to server. #[derive(Debug, Clone, Deserialize)] #[serde(tag = "type", rename_all = "camelCase")] pub enum ClientMessage { /// Advance. On a page with an unplayed video this starts the video instead -- /// see [`crate::state::Session::next`]. Next, Prev, Goto { page: usize }, First, Last, /// Start or resume a video, regardless of the overlay-step rule. `time` comes /// from a view driving its own player, so the others follow it exactly. PlayVideo { id: String, time: Option }, /// Hold a video where it is. PauseVideo { id: String, time: Option }, /// Move a video's playhead, leaving it playing or paused as it was. SeekVideo { id: String, time: f64 }, /// Stop a video and rewind it, without leaving the slide. StopVideo { id: String }, /// Blow a video up to fill the screen, or put it back on its slide. The server /// holds which video is enlarged, so a view can ask to flip it without /// tracking that itself and risking a disagreement with the other view. ToggleVideoFullscreen { id: String }, SetBlank { blank: bool }, } #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)] #[serde(rename_all = "lowercase")] pub enum VideoAction { /// Play, from `time` when given and from the clip's start otherwise. Play, /// Hold the playhead where it is. Distinct from `Stop`: pausing to talk over /// a still frame should not throw away the position. Pause, /// Move the playhead without changing whether it is playing. Seek, /// Pause and rewind to the clip's start. Stop, /// Fill the screen with this video. Enlarge, /// Put it back in its place on the slide. Restore, } #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)] #[serde(rename_all = "lowercase")] pub enum MediaState { Downloading, Ready, Failed, }