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:
2026-11-17 19:40:35 +02:00
co-authored by Claude Opus 5.5
parent 0d766d3c86
commit e612e2436c
13 changed files with 666 additions and 6 deletions
+75
View File
@@ -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 }), [])
})
+3 -3
View File
@@ -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
})