feat(terminal): the signage player: playlists on a TV, offline, transitions, rotation (platform-v2 step 5.5a)
- terminal/src/apps/signage: plays the screen's playlist (or the one its schedule picks now, switching by itself) full screen: slides in order with their time, a video to its end (a 15 min safety limit), only in their days / hours / dates; transitions fade / slide / zoom / none (CSS, reduced motion respected); the frame turned 90/180/270 for a TV mounted sideways. Picture, video and text slides drawn; a first menu board (5.5b lays it out fully). - Offline: the last GET /api/signage/screen kept in localStorage, every picture and video (up to 120 MB) as an in-memory copy; reads again on signage.changed / device.updated / reconnect / every 5 min. - logic.js: the server's schedule pick ported (same test cases), slide windows, next slide, frame; tests/signage.test.mjs (6). - Signage screens get no offline banner over the slides, a small mark instead (registry QUIET_OFFLINE). - e2e signage.mjs (in run-all): a paired TV plays picture → text → video → menu in order, the text's slide transition, rotation, keeps playing with the server stopped (mark, no banner), catches up when it is back. terminal.mjs passed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
// The apps a paired screen can run (plan step 3.1b, APPS_PLATFORM D-2): the device's
|
||||
// app_key (GET /api/devices/me) picks one. Each app is its own lazily loaded chunk, so a
|
||||
// kitchen screen never downloads the POS. Signage and the menu tablet arrive in phase 5.
|
||||
// kitchen screen never downloads the POS. The menu tablet arrives in step 5.7.
|
||||
|
||||
export const APPS = {
|
||||
kds: () => import('./kds/KdsApp.jsx'),
|
||||
pos_counter: () => import('./pos/PosApp.jsx'),
|
||||
customer_display: () => import('./customer-display/CustomerDisplayApp.jsx'),
|
||||
signage: () => import('./signage/SignageApp.jsx'),
|
||||
}
|
||||
|
||||
/** The loader of an app, or null when this terminal version doesn't have it. */
|
||||
@@ -21,3 +22,7 @@ export const APP_THEMES = { kds: 'dark' }
|
||||
export function appTheme(appKey) {
|
||||
return Object.hasOwn(APP_THEMES, appKey) ? APP_THEMES[appKey] : null
|
||||
}
|
||||
|
||||
// Screens nobody works at (a TV with signage): no "server unreachable" banner over what guests
|
||||
// see, only a small mark in a corner; the app keeps playing what it has (5.5a).
|
||||
export const QUIET_OFFLINE = new Set(['signage'])
|
||||
|
||||
@@ -0,0 +1,204 @@
|
||||
// The signage player (plan step 5.5a): a TV paired as a signage screen, no sign-in. It plays its
|
||||
// playlist (or the playlist its schedule picks now) full screen: slides in order, each for its
|
||||
// time (a video to its end), with its transition, only on its days / hours / dates; turned for a
|
||||
// TV mounted sideways. Everything it needs is kept on the device: the last answer of
|
||||
// GET /api/signage/screen in localStorage and every picture and video as an in-memory copy, so it
|
||||
// keeps playing (and switching by its schedule) while the server is down, and catches up on
|
||||
// `signage.changed`, a reconnect, or every few minutes (prices that change by time alone).
|
||||
// Menu boards and widgets are drawn in 5.5b.
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
import client from '../../api/client'
|
||||
import { useDevice, useLiveEvent, useLiveEvents } from '../../device/context'
|
||||
import { frameStyle, localNow, mediaUrls, nextSlide, playlistNow, slideMs } from './logic'
|
||||
import { MenuSlide, TextSlide } from './Slides'
|
||||
|
||||
const quiet = { xenia: { noOverride: true } }
|
||||
const CACHE_KEY = 'xenia:signage:screen'
|
||||
const REFRESH_MS = 5 * 60_000
|
||||
const VIDEO_MAX_MS = 15 * 60_000 // a video "to its end" that never ends moves on after this
|
||||
const KEEP_VIDEO_BYTES = 120 * 1024 * 1024 // bigger videos stream from the server (not kept offline)
|
||||
const TRANSITION_MS = 800
|
||||
|
||||
function readCache() {
|
||||
try { return JSON.parse(localStorage.getItem(CACHE_KEY) || 'null') } catch { return null }
|
||||
}
|
||||
function writeCache(data) {
|
||||
try { localStorage.setItem(CACHE_KEY, JSON.stringify(data)) } catch { /* full or blocked: the memory copy still plays */ }
|
||||
}
|
||||
|
||||
/** url → an in-memory copy (object URL) of every file the playlists need; old copies are let go. */
|
||||
function useKeptMedia(urls) {
|
||||
const [kept, setKept] = useState({})
|
||||
const keptRef = useRef({})
|
||||
const key = urls.slice().sort().join('|')
|
||||
useEffect(() => {
|
||||
let live = true
|
||||
const wanted = key ? key.split('|') : []
|
||||
;(async () => {
|
||||
for (const url of wanted) {
|
||||
if (keptRef.current[url]) continue
|
||||
try {
|
||||
const res = await fetch(url)
|
||||
if (!res.ok) continue
|
||||
const size = Number(res.headers.get('content-length') || 0)
|
||||
if (size > KEEP_VIDEO_BYTES) continue
|
||||
const blob = await res.blob()
|
||||
if (!live) return
|
||||
keptRef.current = { ...keptRef.current, [url]: URL.createObjectURL(blob) }
|
||||
setKept(keptRef.current)
|
||||
} catch { /* offline: the next answer tries again; the address still works while online */ }
|
||||
}
|
||||
const gone = Object.keys(keptRef.current).filter(u => !wanted.includes(u))
|
||||
if (gone.length) {
|
||||
const next = { ...keptRef.current }
|
||||
for (const u of gone) { URL.revokeObjectURL(next[u]); delete next[u] }
|
||||
keptRef.current = next
|
||||
if (live) setKept(next)
|
||||
}
|
||||
})()
|
||||
return () => { live = false }
|
||||
}, [key])
|
||||
useEffect(() => () => Object.values(keptRef.current).forEach(u => URL.revokeObjectURL(u)), [])
|
||||
return kept
|
||||
}
|
||||
|
||||
export default function SignageApp() {
|
||||
const { t } = useTranslation('terminal')
|
||||
const { offline } = useDevice()
|
||||
const [data, setData] = useState(readCache)
|
||||
const [now, setNow] = useState(() => new Date())
|
||||
|
||||
const load = useCallback(async () => {
|
||||
try {
|
||||
const { data: d } = await client.get('/api/signage/screen', quiet)
|
||||
setData(prev => (prev?.version === d.version ? prev : d))
|
||||
writeCache(d)
|
||||
} catch { /* keep playing what we have */ }
|
||||
}, [])
|
||||
useEffect(() => { load() }, [load])
|
||||
useLiveEvent('ready', load)
|
||||
useLiveEvents(['signage.changed', 'device.updated'], load)
|
||||
useEffect(() => {
|
||||
const id = setInterval(load, REFRESH_MS)
|
||||
return () => clearInterval(id)
|
||||
}, [load])
|
||||
useEffect(() => {
|
||||
const id = setInterval(() => setNow(new Date()), 1000)
|
||||
return () => clearInterval(id)
|
||||
}, [])
|
||||
|
||||
const kept = useKeptMedia(useMemo(() => mediaUrls(data), [data]))
|
||||
const playlist = playlistNow(data, now)
|
||||
const tz = data?.schedule?.timezone
|
||||
const screen = data?.screen
|
||||
return (
|
||||
<main className="fixed inset-0 overflow-hidden select-none cursor-none" style={{ background: '#000' }}
|
||||
data-testid="app-signage" data-playlist={playlist?.id ?? ''} data-orientation={screen?.orientation ?? ''} data-offline={offline ? 'true' : 'false'}>
|
||||
<div style={frameStyle(screen?.rotation)} data-testid="signage-frame" data-rotation={screen?.rotation ?? 0}>
|
||||
{playlist?.slides?.length
|
||||
? <Player key={playlist.id} playlist={playlist} kept={kept} tz={tz} venue={data?.venue} now={now} />
|
||||
: <Empty text={data ? t('signage.nothing') : t('signage.starting')} />}
|
||||
</div>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
|
||||
function Empty({ text }) {
|
||||
return (
|
||||
<div className="absolute inset-0 flex items-end justify-end p-4" data-testid="signage-empty">
|
||||
<span style={{ color: 'rgba(255,255,255,0.25)', fontSize: '1.4vmin' }}>{text}</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/** Plays one playlist: the current slide, the next when its time is up, with the transition. */
|
||||
function Player({ playlist, kept, tz, venue, now }) {
|
||||
const local = localNow(tz, now)
|
||||
const slides = playlist.slides
|
||||
const [cur, setCur] = useState(() => ({ index: nextSlide(slides, -1, local), at: Date.now(), n: 0 }))
|
||||
const [prev, setPrev] = useState(null)
|
||||
const media = id => {
|
||||
const m = playlist.media?.[String(id)]
|
||||
return m ? { ...m, src: kept[m.url] || m.url } : null
|
||||
}
|
||||
|
||||
const curRef = useRef(cur)
|
||||
useEffect(() => { curRef.current = cur })
|
||||
const advance = useCallback(() => {
|
||||
const c = curRef.current
|
||||
const next = nextSlide(slides, c.index, localNow(tz, new Date()))
|
||||
setPrev(c.index >= 0 ? c : null)
|
||||
setCur({ index: next, at: Date.now(), n: c.n + 1 })
|
||||
}, [slides, tz])
|
||||
|
||||
// the slide list changed (an edit): keep going from a slide that still exists
|
||||
useEffect(() => {
|
||||
setCur(c => (c.index >= 0 && c.index < slides.length ? c : { index: nextSlide(slides, -1, localNow(tz, new Date())), at: Date.now(), n: c.n + 1 }))
|
||||
}, [slides, tz])
|
||||
|
||||
const slide = cur.index >= 0 ? slides[cur.index] : null
|
||||
// time's up (videos to their end call advance themselves, with a safety limit)
|
||||
useEffect(() => {
|
||||
if (!slide) return undefined
|
||||
const ms = slideMs(slide) ?? VIDEO_MAX_MS
|
||||
const id = setTimeout(advance, ms)
|
||||
return () => clearTimeout(id)
|
||||
}, [slide, cur.n, advance])
|
||||
// a slide that may no longer show (its window ended) is skipped at once; none showing → wait
|
||||
useEffect(() => {
|
||||
if (cur.index < 0 && nextSlide(slides, -1, local) >= 0) advance()
|
||||
}, [cur.index, slides, local.minutes, advance]) // eslint-disable-line react-hooks/exhaustive-deps
|
||||
useEffect(() => {
|
||||
if (!prev) return undefined
|
||||
const id = setTimeout(() => setPrev(null), TRANSITION_MS)
|
||||
return () => clearTimeout(id)
|
||||
}, [prev])
|
||||
|
||||
if (!slide) return <Empty text="" />
|
||||
const transition = slide.transition || playlist.transition || 'fade'
|
||||
return (
|
||||
<>
|
||||
{prev && slides[prev.index] && (
|
||||
<Layer key={`out-${prev.n}`} slide={slides[prev.index]} media={media} venue={venue} now={now} className={`sg-out sg-out-${transition}`} />
|
||||
)}
|
||||
<Layer key={`in-${cur.n}`} slide={slide} media={media} venue={venue} now={now} onEnded={advance}
|
||||
className={cur.n === 0 ? '' : `sg-in sg-in-${transition}`} current />
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
function Layer({ slide, media, venue, now, onEnded, className, current = false }) {
|
||||
return (
|
||||
<section className={`absolute inset-0 overflow-hidden ${className}`} style={{ animationDuration: `${TRANSITION_MS}ms` }}
|
||||
data-testid={current ? 'signage-slide' : 'signage-slide-out'} data-kind={slide.kind} data-slide={slide.id}>
|
||||
{slide.kind === 'image' && <ImageSlide content={slide.content} media={media} />}
|
||||
{slide.kind === 'video' && <VideoSlide slide={slide} media={media} onEnded={current ? onEnded : undefined} />}
|
||||
{slide.kind === 'text' && <TextSlide content={slide.content} media={media} venue={venue} now={now} />}
|
||||
{slide.kind === 'menu' && <MenuSlide slide={slide} media={media} venue={venue} now={now} />}
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
function ImageSlide({ content, media }) {
|
||||
const m = media(content.media_id)
|
||||
return (
|
||||
<div className="absolute inset-0" style={{ background: content.background_colour || '#000' }}>
|
||||
{m && <img src={m.src} alt="" className="w-full h-full" style={{ objectFit: content.fit || 'cover' }} data-testid="signage-image" />}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function VideoSlide({ slide, media, onEnded }) {
|
||||
const c = slide.content
|
||||
const m = media(c.media_id)
|
||||
const ref = useRef(null)
|
||||
useEffect(() => { ref.current?.play?.().catch(() => {}) }, [m?.src])
|
||||
return (
|
||||
<div className="absolute inset-0" style={{ background: c.background_colour || '#000' }}>
|
||||
{m && <video ref={ref} src={m.src} autoPlay muted={c.muted !== false} playsInline loop={!slide.video_to_end}
|
||||
onEnded={slide.video_to_end ? onEnded : undefined} onError={slide.video_to_end ? onEnded : undefined}
|
||||
className="w-full h-full" style={{ objectFit: c.fit || 'cover' }} data-testid="signage-video" />}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
// Text and menu slides of the signage player (plan steps 5.5a, 5.5b). Colours, fonts and sizes
|
||||
// here are the venue's own choices for its TV (slide content = data, CS-16), so they are inline
|
||||
// styles, not tokens. Sizes scale with the screen (vmin), so a slide looks the same on any TV.
|
||||
import { useFormat } from '@xenia/i18n'
|
||||
import { FONTS } from './logic'
|
||||
|
||||
|
||||
/** A slide's background: a colour, or a photo (cover / contain) with a darkening layer. */
|
||||
export function Background({ bg, media }) {
|
||||
const m = bg?.kind === 'media' ? media(bg.media_id) : null
|
||||
return (
|
||||
<div className="absolute inset-0" style={{ background: bg?.colour || '#111827' }} data-testid="signage-background">
|
||||
{m && <img src={m.src} alt="" className="absolute inset-0 w-full h-full" style={{ objectFit: bg.fit || 'cover' }} />}
|
||||
{m && bg.dim > 0 && <div className="absolute inset-0" style={{ background: `rgba(0,0,0,${bg.dim / 100})` }} />}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const JUSTIFY = { top: 'flex-start', middle: 'center', bottom: 'flex-end' }
|
||||
|
||||
export function TextSlide({ content: c, media }) {
|
||||
const scale = (c.text_size || 100) / 100
|
||||
return (
|
||||
<div className="absolute inset-0">
|
||||
<Background bg={c.background} media={media} />
|
||||
<div className="absolute inset-0 flex flex-col" style={{
|
||||
justifyContent: JUSTIFY[c.vertical] || 'center', textAlign: c.align || 'center', color: c.text_colour || '#fff',
|
||||
fontFamily: FONTS[c.font] || FONTS.sans, padding: '8vmin', gap: `${3 * scale}vmin`,
|
||||
}}>
|
||||
{c.title && <h1 style={{ fontSize: `${9 * scale}vmin`, lineHeight: 1.1, fontWeight: 800, margin: 0 }} data-testid="signage-title">{c.title}</h1>}
|
||||
{c.body && <p style={{ fontSize: `${4.5 * scale}vmin`, lineHeight: 1.35, margin: 0, whiteSpace: 'pre-line' }} data-testid="signage-body">{c.body}</p>}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/** A first menu board (5.5a): its title and every item with its price; 5.5b lays it out fully. */
|
||||
export function MenuSlide({ slide, media }) {
|
||||
const { formatMoney } = useFormat()
|
||||
const c = slide.content
|
||||
const scale = (c.text_size || 100) / 100
|
||||
const groups = slide.menu?.groups || []
|
||||
return (
|
||||
<div className="absolute inset-0">
|
||||
<Background bg={c.background} media={media} />
|
||||
<div className="absolute inset-0 flex flex-col" style={{ color: c.text_colour || '#fff', fontFamily: FONTS[c.font] || FONTS.sans, padding: '5vmin' }}
|
||||
data-testid="signage-menu">
|
||||
{c.title && <h1 style={{ fontSize: `${7 * scale}vmin`, fontWeight: 800, margin: '0 0 2vmin', color: c.accent_colour }}>{c.title}</h1>}
|
||||
<div style={{ columnCount: c.columns || 2, columnGap: '5vmin', fontSize: `${3.2 * scale}vmin` }}>
|
||||
{groups.map((g, i) => (
|
||||
<div key={g.category?.id ?? `all-${i}`} style={{ breakInside: 'avoid', marginBottom: '2vmin' }}>
|
||||
{g.category && c.category_titles !== false && <h2 style={{ fontSize: '1.2em', color: c.accent_colour, margin: '0 0 0.5vmin' }}>{g.category.name}</h2>}
|
||||
{g.items.map(it => (
|
||||
<div key={it.id} className="flex justify-between gap-4" data-testid="signage-menu-item" data-available={it.available ? 'true' : 'false'}
|
||||
style={{ textDecoration: it.available ? 'none' : 'line-through', opacity: it.available ? 1 : 0.55 }}>
|
||||
<span>{it.name}</span>
|
||||
{it.price != null && <span style={{ color: c.accent_colour, fontVariantNumeric: 'tabular-nums' }} data-testid="signage-menu-price">{formatMoney(it.price)}</span>}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
// The signage player's logic (plan step 5.5a). Pure: unit-tested in Node (tests/signage.test.mjs).
|
||||
// The schedule rules are the server's (local_backend/services/signage_schedule.py) so a screen
|
||||
// switches playlists by itself while the server is down; the same cases are tested on both sides.
|
||||
|
||||
/** The venue's local clock at `date`: { weekday (0 = Monday), minutes, date: "YYYY-MM-DD" }. */
|
||||
export function localNow(timeZone, date = new Date()) {
|
||||
const parts = Object.fromEntries(new Intl.DateTimeFormat('en-GB', {
|
||||
timeZone: timeZone || undefined, year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit',
|
||||
weekday: 'short', hourCycle: 'h23',
|
||||
}).formatToParts(date).map(p => [p.type, p.value]))
|
||||
const weekday = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'].indexOf(parts.weekday)
|
||||
return { weekday, minutes: Number(parts.hour) * 60 + Number(parts.minute), date: `${parts.year}-${parts.month}-${parts.day}` }
|
||||
}
|
||||
|
||||
/** The day before a local moment (for windows that pass midnight). */
|
||||
function yesterday(local) {
|
||||
const d = new Date(`${local.date}T12:00:00Z`)
|
||||
d.setUTCDate(d.getUTCDate() - 1)
|
||||
return { weekday: (local.weekday + 6) % 7, minutes: local.minutes, date: d.toISOString().slice(0, 10) }
|
||||
}
|
||||
|
||||
const mins = hhmm => {
|
||||
if (!hhmm) return null
|
||||
const [h, m] = hhmm.split(':').map(Number)
|
||||
return h * 60 + m
|
||||
}
|
||||
|
||||
function dayOk(w, local) {
|
||||
const days = w.days || []
|
||||
return (!days.length || days.includes(local.weekday)) &&
|
||||
(!w.date_from || local.date >= w.date_from) && (!w.date_to || local.date <= w.date_to)
|
||||
}
|
||||
|
||||
/** Does a window (days, time_from / time_to that may pass midnight, date_from / date_to) cover `local`? */
|
||||
export function matches(w, local) {
|
||||
let start = mins(w.time_from)
|
||||
let end = mins(w.time_to)
|
||||
if (start == null && end == null) return dayOk(w, local)
|
||||
start = start ?? 0
|
||||
end = end ?? 24 * 60
|
||||
if (start < end) return local.minutes >= start && local.minutes < end && dayOk(w, local)
|
||||
if (local.minutes >= start) return dayOk(w, local)
|
||||
if (local.minutes < end) return dayOk(w, yesterday(local))
|
||||
return false
|
||||
}
|
||||
|
||||
const specific = e => ((e.date_from || e.date_to) ? 4 : 0) + (e.days?.length ? 2 : 0) + ((e.time_from || e.time_to) ? 1 : 0)
|
||||
|
||||
/** The playlist a schedule plays at `local`: highest priority, then the most specific, then the later entry. */
|
||||
export function pick(entries, fallback, local) {
|
||||
let best = null
|
||||
let bestKey = null
|
||||
;(entries || []).forEach((e, i) => {
|
||||
if (e.playlist_id == null || !matches(e, local)) return
|
||||
const key = [e.priority || 0, specific(e), i]
|
||||
if (!bestKey || key[0] > bestKey[0] || (key[0] === bestKey[0] && (key[1] > bestKey[1] || (key[1] === bestKey[1] && key[2] > bestKey[2])))) {
|
||||
best = e.playlist_id
|
||||
bestKey = key
|
||||
}
|
||||
})
|
||||
return best ?? fallback ?? null
|
||||
}
|
||||
|
||||
/** The playlist to play now from the screen's answer (GET /api/signage/screen). */
|
||||
export function playlistNow(data, now = new Date()) {
|
||||
if (!data) return null
|
||||
if (!data.schedule) return data.playlist || null
|
||||
const id = pick(data.schedule.entries, data.schedule.fallback_playlist_id, localNow(data.schedule.timezone, now))
|
||||
return id != null ? data.playlists?.[String(id)] ?? null : null
|
||||
}
|
||||
|
||||
/** A slide may show now: its own window (days / hours / dates), in venue time. */
|
||||
export function slideShows(slide, local) {
|
||||
return matches({ days: slide.days, time_from: slide.time_from, time_to: slide.time_to, date_from: slide.date_from, date_to: slide.date_to }, local)
|
||||
}
|
||||
|
||||
/** The index of the next slide that may show after `current` (wrapping), or -1 when none may. */
|
||||
export function nextSlide(slides, current, local) {
|
||||
const n = slides?.length || 0
|
||||
for (let step = 1; step <= n; step++) {
|
||||
const i = (((current ?? -1) + step) % n + n) % n
|
||||
if (slideShows(slides[i], local)) return i
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
/** How long a slide stays, in ms; null = until its video ends (with a safety limit in the player). */
|
||||
export function slideMs(slide) {
|
||||
if (slide.kind === 'video' && slide.video_to_end) return null
|
||||
return Math.max(2, slide.duration_s || 10) * 1000
|
||||
}
|
||||
|
||||
/** The frame's size and turn for a screen: CSS for the box that holds the slides. */
|
||||
export function frameStyle(rotation) {
|
||||
const r = Number(rotation) || 0
|
||||
if (r === 90 || r === 270) {
|
||||
return { width: '100vh', height: '100vw', transform: `translate(-50%, -50%) rotate(${r}deg)`, top: '50%', left: '50%', position: 'absolute' }
|
||||
}
|
||||
return { width: '100vw', height: '100vh', transform: r === 180 ? 'rotate(180deg)' : undefined, top: 0, left: 0, position: 'absolute' }
|
||||
}
|
||||
|
||||
/** Every media address a playlist (or a schedule's playlists) needs, to keep on the device. */
|
||||
export function mediaUrls(data) {
|
||||
if (!data) return []
|
||||
const lists = data.schedule ? Object.values(data.playlists || {}) : (data.playlist ? [data.playlist] : [])
|
||||
const out = new Set()
|
||||
for (const p of lists) for (const m of Object.values(p.media || {})) if (m.url) out.add(m.url)
|
||||
return [...out]
|
||||
}
|
||||
|
||||
/** The fonts a slide can choose (all on the device: nothing to download, works offline). */
|
||||
export const FONTS = {
|
||||
sans: 'system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',
|
||||
serif: 'Georgia, "Times New Roman", serif',
|
||||
rounded: 'ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", system-ui, sans-serif',
|
||||
condensed: '"Arial Narrow", "Roboto Condensed", "Helvetica Neue", sans-serif',
|
||||
display: 'Impact, "Arial Black", system-ui, sans-serif',
|
||||
}
|
||||
@@ -16,3 +16,22 @@
|
||||
}
|
||||
input, textarea { -webkit-user-select: text; user-select: text; }
|
||||
}
|
||||
|
||||
/* Signage transitions (plan step 5.5a): the new slide comes in over the old one going out. */
|
||||
.sg-in, .sg-out { animation-fill-mode: both; animation-timing-function: ease-in-out; }
|
||||
.sg-out { z-index: 0; }
|
||||
.sg-in { z-index: 1; }
|
||||
.sg-in-fade { animation-name: sg-fade-in; }
|
||||
.sg-out-fade { animation-name: sg-fade-out; }
|
||||
.sg-in-slide { animation-name: sg-slide-in; }
|
||||
.sg-out-slide { animation-name: sg-slide-out; }
|
||||
.sg-in-zoom { animation-name: sg-zoom-in; }
|
||||
.sg-out-zoom { animation-name: sg-fade-out; }
|
||||
.sg-in-none, .sg-out-none { animation: none; }
|
||||
.sg-out-none { display: none; }
|
||||
@keyframes sg-fade-in { from { opacity: 0; } to { opacity: 1; } }
|
||||
@keyframes sg-fade-out { from { opacity: 1; } to { opacity: 0; } }
|
||||
@keyframes sg-slide-in { from { transform: translateX(100%); } to { transform: translateX(0); } }
|
||||
@keyframes sg-slide-out { from { transform: translateX(0); } to { transform: translateX(-100%); } }
|
||||
@keyframes sg-zoom-in { from { opacity: 0; transform: scale(1.12); } to { opacity: 1; transform: scale(1); } }
|
||||
@media (prefers-reduced-motion: reduce) { .sg-in, .sg-out { animation: none; } .sg-out { display: none; } }
|
||||
|
||||
@@ -6,6 +6,7 @@ import { useTranslation } from '@xenia/i18n'
|
||||
import { Button, Spinner } from '@xenia/ui'
|
||||
import { useDevice } from '../device/context'
|
||||
import { screenFor } from '../device/flow'
|
||||
import { QUIET_OFFLINE } from '../apps/registry'
|
||||
import AppScreen from './AppScreen'
|
||||
import BlockedScreen from './BlockedScreen'
|
||||
import PairingScreen from './PairingScreen'
|
||||
@@ -16,7 +17,9 @@ export default function Terminal() {
|
||||
const screen = screenFor(device)
|
||||
return (
|
||||
<>
|
||||
{device.offline && <OfflineBanner onRetry={device.retry} />}
|
||||
{screen === 'app' && QUIET_OFFLINE.has(device.me?.app_key)
|
||||
? (device.offline || !device.liveUp) && <OfflineMark />
|
||||
: device.offline && <OfflineBanner onRetry={device.retry} />}
|
||||
{screen === 'pairing' && <PairingScreen />}
|
||||
{screen === 'loading' && <main className="min-h-screen flex items-center justify-center" data-testid="loading-screen"><Spinner /></main>}
|
||||
{(screen === 'blocked' || screen === 'app_off') && <BlockedScreen />}
|
||||
@@ -37,3 +40,10 @@ function OfflineBanner({ onRetry }) {
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/** A screen guests look at: a small dot instead of the banner (the app keeps playing). */
|
||||
function OfflineMark() {
|
||||
const { t } = useTranslation('terminal')
|
||||
return <span role="status" aria-label={t('offline.banner')} data-testid="offline-mark"
|
||||
className="fixed bottom-2 left-2 z-50 w-2 h-2 rounded-full bg-warning opacity-60" />
|
||||
}
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
// The signage player's logic (plan step 5.5a): the same schedule cases as the server's
|
||||
// local_backend/tests/test_signage_schedule.py, slide windows, the next slide, the frame.
|
||||
import assert from 'node:assert/strict'
|
||||
import { test } from 'node:test'
|
||||
import { frameStyle, localNow, matches, mediaUrls, nextSlide, pick, playlistNow, slideMs } from '../src/apps/signage/logic.js'
|
||||
|
||||
const at = (date, hhmm) => {
|
||||
const d = new Date(`${date}T12:00:00Z`)
|
||||
const [h, m] = hhmm.split(':').map(Number)
|
||||
return { weekday: (d.getUTCDay() + 6) % 7, minutes: h * 60 + m, date }
|
||||
}
|
||||
const MON_10 = at('2026-11-16', '10:00')
|
||||
const MON_13 = at('2026-11-16', '13:00')
|
||||
const SAT_13 = at('2026-11-21', '13:00')
|
||||
const SAT_23 = at('2026-11-21', '23:30')
|
||||
const SUN_01 = at('2026-11-22', '01:00')
|
||||
const MON_01 = at('2026-11-16', '01:00')
|
||||
|
||||
test('the venue clock in its own time zone', () => {
|
||||
const l = localNow('Europe/Athens', new Date('2026-11-16T22:30:00Z')) // 00:30 on Tuesday in Athens
|
||||
assert.deepEqual(l, { weekday: 1, minutes: 30, date: '2026-11-17' })
|
||||
})
|
||||
|
||||
test('which windows match (the server\'s cases)', () => {
|
||||
const lunch = { time_from: '12:00', time_to: '15:00' }
|
||||
assert.ok(matches(lunch, MON_13) && !matches(lunch, MON_10))
|
||||
const night = { days: [5], time_from: '22:00', time_to: '02:00' }
|
||||
assert.ok(matches(night, SAT_23) && matches(night, SUN_01) && !matches(night, MON_01))
|
||||
const xmas = { date_from: '2026-12-20', date_to: '2026-12-27' }
|
||||
assert.ok(matches(xmas, at('2026-12-24', '20:00')) && !matches(xmas, at('2026-12-28', '09:00')))
|
||||
assert.ok(matches({}, MON_10))
|
||||
assert.ok(matches({ time_from: '18:00' }, at('2026-11-16', '23:59')))
|
||||
})
|
||||
|
||||
test('the schedule\'s winner (the server\'s cases)', () => {
|
||||
const entries = [{ playlist_id: 10, time_from: '12:00', time_to: '15:00' }, { playlist_id: 20, days: [5, 6] },
|
||||
{ playlist_id: 30, days: [5, 6], time_from: '12:00', time_to: '15:00' },
|
||||
{ playlist_id: 40, date_from: '2026-11-21', date_to: '2026-11-21', priority: 5 }]
|
||||
assert.equal(pick(entries, 99, MON_10), 99)
|
||||
assert.equal(pick(entries, 99, MON_13), 10)
|
||||
assert.equal(pick(entries, 99, at('2026-11-22', '13:00')), 30)
|
||||
assert.equal(pick(entries, 99, SAT_13), 40)
|
||||
assert.equal(pick(entries, null, MON_10), null)
|
||||
})
|
||||
|
||||
test('the playlist now, alone or from a schedule', () => {
|
||||
assert.equal(playlistNow({ playlist: { id: 1 } }).id, 1)
|
||||
const data = { schedule: { timezone: 'Europe/Athens', entries: [{ playlist_id: 2, time_from: '12:00', time_to: '15:00' }], fallback_playlist_id: 3 },
|
||||
playlists: { 2: { id: 2 }, 3: { id: 3 } } }
|
||||
assert.equal(playlistNow(data, new Date('2026-11-16T11:00:00Z')).id, 2) // 13:00 in Athens
|
||||
assert.equal(playlistNow(data, new Date('2026-11-16T08:00:00Z')).id, 3)
|
||||
assert.equal(playlistNow(null), null)
|
||||
})
|
||||
|
||||
test('the next slide skips the ones outside their window, and wraps', () => {
|
||||
const slides = [{ id: 1 }, { id: 2, time_from: '12:00', time_to: '15:00' }, { id: 3, days: [0] }]
|
||||
assert.equal(nextSlide(slides, -1, MON_10), 0)
|
||||
assert.equal(nextSlide(slides, 0, MON_10), 2) // 2 is a lunch slide
|
||||
assert.equal(nextSlide(slides, 2, MON_10), 0)
|
||||
assert.equal(nextSlide(slides, 0, MON_13), 1)
|
||||
assert.equal(nextSlide([{ id: 1, days: [6] }], -1, MON_10), -1)
|
||||
assert.equal(nextSlide([], -1, MON_10), -1)
|
||||
})
|
||||
|
||||
test('how long a slide stays; the frame for a turned TV; what to keep on the device', () => {
|
||||
assert.equal(slideMs({ kind: 'text', duration_s: 8 }), 8000)
|
||||
assert.equal(slideMs({ kind: 'video', video_to_end: true, duration_s: 8 }), null)
|
||||
assert.equal(slideMs({ kind: 'image' }), 10000)
|
||||
assert.equal(frameStyle(90).width, '100vh')
|
||||
assert.equal(frameStyle(0).width, '100vw')
|
||||
assert.equal(frameStyle(180).transform, 'rotate(180deg)')
|
||||
const data = { schedule: {}, playlists: { 1: { media: { 5: { url: '/a' } } }, 2: { media: { 6: { url: '/b' }, 5: { url: '/a' } } } } }
|
||||
assert.deepEqual(mediaUrls(data).sort(), ['/a', '/b'])
|
||||
assert.deepEqual(mediaUrls({ playlist: null }), [])
|
||||
})
|
||||
@@ -5,10 +5,10 @@ import { APPS, appLoader } from '../src/apps/registry.js'
|
||||
import { DEVICE_KEY, SESSION_KEY, createDeviceStore } from '../src/device/storage.js'
|
||||
import { deviceGone, formatCode, idleExpired, liveAction, pollOutcome, refusedAction, screenFor } from '../src/device/flow.js'
|
||||
|
||||
test('the apps a screen can run: KDS, counter POS, customer display (signage + menu tablet in phase 5)', () => {
|
||||
assert.deepEqual(Object.keys(APPS).sort(), ['customer_display', 'kds', 'pos_counter'])
|
||||
test('the apps a screen can run: KDS, counter POS, customer display, signage (the menu tablet in 5.7)', () => {
|
||||
assert.deepEqual(Object.keys(APPS).sort(), ['customer_display', 'kds', 'pos_counter', 'signage'])
|
||||
assert.equal(typeof appLoader('kds'), 'function')
|
||||
assert.equal(appLoader('signage'), null)
|
||||
assert.equal(appLoader('menu_tablet'), null)
|
||||
assert.equal(appLoader('toString'), null) // never a prototype member
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user