@fifthbell/brokaw 0.1.70 → 0.1.73

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/README.md +112 -0
  2. package/dist/captured-catalog-browser.d.ts +26 -0
  3. package/dist/captured-catalog-browser.js +42 -0
  4. package/dist/captured-catalog-reader.d.ts +16 -0
  5. package/dist/captured-catalog-reader.js +113 -0
  6. package/dist/captured-catalog.d.ts +28 -0
  7. package/dist/captured-catalog.js +124 -0
  8. package/dist/components/live-program/LiveProgram.js +119 -311
  9. package/dist/components/live-program/components/WorldClocks.js +2 -1
  10. package/dist/components/live-program/components/slides/LiveEventSlide.js +2 -4
  11. package/dist/components/live-program/events.d.ts +7 -0
  12. package/dist/components/live-program/events.js +28 -5
  13. package/dist/components/live-program/hooks/useSSE.js +1 -2
  14. package/dist/components/live-program/i18n.js +1 -1
  15. package/dist/components/live-program/live-program-config.d.ts +70 -0
  16. package/dist/components/live-program/live-program-config.js +228 -0
  17. package/dist/components/live-program/program-data.d.ts +22 -0
  18. package/dist/components/live-program/program-data.js +23 -0
  19. package/dist/components/live-program/program-reload.d.ts +11 -0
  20. package/dist/components/live-program/program-reload.js +21 -0
  21. package/dist/components/live-program/segments/ArticlesSegment.d.ts +5 -0
  22. package/dist/components/live-program/segments/ArticlesSegment.js +15 -11
  23. package/dist/components/live-program/segments/EarthquakeSegment.d.ts +4 -0
  24. package/dist/components/live-program/segments/EarthquakeSegment.js +13 -10
  25. package/dist/components/live-program/segments/MarketsSegment.js +7 -2
  26. package/dist/components/live-program/segments/WeatherSegment.d.ts +5 -0
  27. package/dist/components/live-program/segments/WeatherSegment.js +7 -2
  28. package/dist/components/live-program/segments/fetchLiveEvents.d.ts +6 -0
  29. package/dist/components/live-program/segments/fetchLiveEvents.js +42 -27
  30. package/dist/components/live-program/source-retention.d.ts +14 -0
  31. package/dist/components/live-program/source-retention.js +26 -0
  32. package/dist/cronkite-manifest.d.ts +35 -0
  33. package/dist/cronkite-manifest.js +5 -26
  34. package/dist/cronkite-manifest.json +48 -1
  35. package/dist/layouts.d.ts +1 -1
  36. package/dist/live-program-page/index.html +2 -2
  37. package/dist/live-program-page/live-program-manifest.json +8 -8
  38. package/dist/live-program-page/live-program.v0.1.73.css +3 -0
  39. package/dist/live-program-page/live-program.v0.1.73.js +76 -0
  40. package/dist/manifest-validation.js +3 -1
  41. package/dist/renderer.browser.js +2 -0
  42. package/dist/renderer.core.js +3 -7
  43. package/dist/schemas/canonical-document.schema.json +69 -1
  44. package/dist/system-pages.d.ts +66 -0
  45. package/dist/system-pages.js +35 -0
  46. package/dist/types/canonical-article.js +3 -2
  47. package/dist/types/canonical-document-schema.generated.d.ts +132 -0
  48. package/dist/types/canonical-document-schema.generated.js +146 -0
  49. package/dist/types/canonical-document.generated.d.ts +34 -0
  50. package/package.json +10 -4
  51. package/src/partial-deps.json +9 -0
  52. package/src/styles/compiled.css +1 -1
  53. package/src/templates/partials/components/article-main.hbs +6 -5
  54. package/src/templates/partials/components/media/main.hbs +4 -3
  55. package/src/templates/partials/components/search/main.hbs +3 -3
  56. package/src/templates/partials/headers/header-main.hbs +11 -19
  57. package/src/templates/partials/shell/captured-catalog.hbs +1 -0
  58. package/dist/live-program-page/live-program.v0.1.70.css +0 -3
  59. package/dist/live-program-page/live-program.v0.1.70.js +0 -76
@@ -6,236 +6,14 @@ import { isProgramStateEvent, parseProgramEvent, reconcileProgramEvent, reconcil
6
6
  import { FIFTHBELL_ASSETS } from './assets.js';
7
7
  import { MarqueeCurtain } from './components/MarqueeCurtain.js';
8
8
  import Marquee from './components/Marquee.js';
9
- import { WorldClocks, DEFAULT_WORLD_CLOCK_CITIES } from './components/WorldClocks.js';
9
+ import { WorldClocks } from './components/WorldClocks.js';
10
10
  import { CallsignSlide } from './components/slides/CallsignSlide.js';
11
11
  import { slideStyles } from './components/slides/slideStyles.js';
12
- import { fetchEvents, getCachedEvents, hasEventChanges } from './events.js';
13
- import { createArticlesSegment, createEarthquakeSegment, createLiveEventSegment, createMarketsSegment, createWeatherSegment, fetchArticles, fetchEarthquakes, fetchLiveEvent, fetchMarketData, fetchWeatherData, usePlaylistEngine } from './segments/index.js';
14
- const DEFAULT_LANGUAGE_ROTATION = ['en', 'es', 'en', 'it'];
15
- const DEFAULT_CALLSIGN_PRELAUNCH_UNTIL_NYC = '2026-01-02T21:30:00';
16
- const FIFTHBELL_COMPONENT_TYPE_CONTENT = 'fifthbell-content';
17
- const FIFTHBELL_COMPONENT_TYPE_MARQUEE = 'fifthbell-marquee';
18
- const FIFTHBELL_COMPONENT_TYPE_TONI_CLOCK = 'toni-clock';
19
- const FIFTHBELL_COMPONENT_TYPE_CORNER = 'fifthbell-corner';
20
- const FIFTHBELL_COMPONENT_TYPE_LEGACY = 'fifthbell';
21
- const DEFAULT_FIFTHBELL_CONFIG = {
22
- showArticles: true,
23
- showWeather: true,
24
- showEarthquakes: true,
25
- showMarkets: true,
26
- showLiveEvents: true,
27
- showMarquee: false,
28
- showCallsignTake: true,
29
- weatherCities: [],
30
- languageRotation: DEFAULT_LANGUAGE_ROTATION,
31
- dataLoadTimeoutMs: 15000,
32
- playlistDefaultDurationMs: 10000,
33
- playlistUpdateIntervalMs: 100,
34
- articlesDurationMs: 10000,
35
- weatherDurationMs: 5000,
36
- earthquakesDurationMs: 10000,
37
- marketsDurationMs: 10000,
38
- showWorldClocks: true,
39
- showBellIcon: true,
40
- worldClockRotateIntervalMs: 7000,
41
- worldClockTransitionMs: 300,
42
- worldClockShuffle: true,
43
- worldClockWidthPx: 200,
44
- worldClockCities: [...DEFAULT_WORLD_CLOCK_CITIES],
45
- audioCueEnabled: true,
46
- audioCueMinute: 59,
47
- audioCueSecond: 55,
48
- callsignPrelaunchUntilNyc: DEFAULT_CALLSIGN_PRELAUNCH_UNTIL_NYC,
49
- callsignWindowStartSecond: 50,
50
- callsignWindowEndSecond: 3,
51
- marqueeMinPostsCount: 4,
52
- marqueeMinAverageRelevance: 0,
53
- marqueeMinMedianRelevance: 0,
54
- marqueePixelsPerSecond: 150,
55
- marqueeMinDurationSeconds: 10,
56
- marqueeHeightPx: 72
57
- };
58
- function clampNumber(value, fallback, min, max) {
59
- const numeric = typeof value === 'number' ? value : Number(value);
60
- if (!Number.isFinite(numeric)) {
61
- return fallback;
62
- }
63
- return Math.min(max, Math.max(min, numeric));
64
- }
65
- function normalizeBoolean(value, fallback) {
66
- if (typeof value === 'boolean') {
67
- return value;
68
- }
69
- if (typeof value === 'number') {
70
- return value !== 0;
71
- }
72
- if (typeof value === 'string') {
73
- const normalized = value.trim().toLowerCase();
74
- if (['true', '1', 'yes', 'on'].includes(normalized)) {
75
- return true;
76
- }
77
- if (['false', '0', 'no', 'off', ''].includes(normalized)) {
78
- return false;
79
- }
80
- }
81
- return fallback;
82
- }
83
- function normalizeStringArray(value) {
84
- if (!Array.isArray(value)) {
85
- return [];
86
- }
87
- const deduped = new Set();
88
- for (const item of value) {
89
- if (typeof item !== 'string') {
90
- continue;
91
- }
92
- const trimmed = item.trim();
93
- if (!trimmed) {
94
- continue;
95
- }
96
- deduped.add(trimmed);
97
- }
98
- return [...deduped];
99
- }
100
- function normalizeLanguageRotation(value) {
101
- if (!Array.isArray(value)) {
102
- return [...DEFAULT_LANGUAGE_ROTATION];
103
- }
104
- const allowed = new Set(['en', 'es', 'it']);
105
- const filtered = value.filter((item) => typeof item === 'string' && allowed.has(item));
106
- return filtered.length > 0 ? filtered : [...DEFAULT_LANGUAGE_ROTATION];
107
- }
108
- function normalizeWorldClockCities(value) {
109
- if (!Array.isArray(value)) {
110
- return [...DEFAULT_WORLD_CLOCK_CITIES];
111
- }
112
- const normalized = value
113
- .map((item) => {
114
- if (!item || typeof item !== 'object' || Array.isArray(item)) {
115
- return null;
116
- }
117
- const city = typeof item.city === 'string' ? item.city.trim() : '';
118
- const timezone = typeof item.timezone === 'string' ? item.timezone.trim() : '';
119
- if (!city || !timezone) {
120
- return null;
121
- }
122
- return { city, timezone };
123
- })
124
- .filter((item) => item !== null);
125
- return normalized.length > 0 ? normalized : [...DEFAULT_WORLD_CLOCK_CITIES];
126
- }
127
- function normalizeCityKey(value) {
128
- return value
129
- .normalize('NFD')
130
- .replace(/[\u0300-\u036f]/g, '')
131
- .trim()
132
- .toLowerCase();
133
- }
134
- function toRecord(value) {
135
- if (value && typeof value === 'object' && !Array.isArray(value)) {
136
- return value;
137
- }
138
- return {};
139
- }
140
- function parseSceneMetadata(scene) {
141
- if (!scene || !scene.metadata) {
142
- return {};
143
- }
144
- try {
145
- const parsed = JSON.parse(scene.metadata);
146
- return toRecord(parsed);
147
- }
148
- catch {
149
- return {};
150
- }
151
- }
152
- function resolveFifthBellLayerAvailability(activeComponents) {
153
- const defaultAvailability = {
154
- content: true,
155
- marquee: true
156
- };
157
- if (!activeComponents || activeComponents.length === 0) {
158
- return defaultAvailability;
159
- }
160
- if (activeComponents.includes(FIFTHBELL_COMPONENT_TYPE_LEGACY)) {
161
- return defaultAvailability;
162
- }
163
- return {
164
- content: activeComponents.includes(FIFTHBELL_COMPONENT_TYPE_CONTENT),
165
- marquee: activeComponents.includes(FIFTHBELL_COMPONENT_TYPE_MARQUEE)
166
- };
167
- }
168
- function extractConfigFromMetadata(metadataInput) {
169
- const metadata = toRecord(metadataInput);
170
- const legacyProps = toRecord(metadata[FIFTHBELL_COMPONENT_TYPE_LEGACY]);
171
- const contentProps = {
172
- ...legacyProps,
173
- ...toRecord(metadata[FIFTHBELL_COMPONENT_TYPE_CONTENT])
174
- };
175
- const marqueeProps = {
176
- ...legacyProps,
177
- ...toRecord(metadata[FIFTHBELL_COMPONENT_TYPE_MARQUEE])
178
- };
179
- const cornerProps = {
180
- ...legacyProps,
181
- ...toRecord(metadata[FIFTHBELL_COMPONENT_TYPE_TONI_CLOCK]),
182
- ...toRecord(metadata[FIFTHBELL_COMPONENT_TYPE_CORNER])
183
- };
184
- const parsedMarqueeMinPostsCount = clampNumber(marqueeProps.marqueeMinPostsCount, DEFAULT_FIFTHBELL_CONFIG.marqueeMinPostsCount, 0, 50);
185
- let parsedMarqueeMinAverageRelevance = clampNumber(marqueeProps.marqueeMinAverageRelevance, DEFAULT_FIFTHBELL_CONFIG.marqueeMinAverageRelevance, 0, 100);
186
- let parsedMarqueeMinMedianRelevance = clampNumber(marqueeProps.marqueeMinMedianRelevance, DEFAULT_FIFTHBELL_CONFIG.marqueeMinMedianRelevance, 0, 100);
187
- // Compatibility: prior defaults were tuned for OR logic. Under threshold logic, treat that trio as legacy.
188
- if (parsedMarqueeMinPostsCount === 4 && parsedMarqueeMinAverageRelevance === 5 && parsedMarqueeMinMedianRelevance === 7) {
189
- parsedMarqueeMinAverageRelevance = 0;
190
- parsedMarqueeMinMedianRelevance = 0;
191
- }
192
- return {
193
- showArticles: normalizeBoolean(contentProps.showArticles, DEFAULT_FIFTHBELL_CONFIG.showArticles),
194
- showWeather: normalizeBoolean(contentProps.showWeather, DEFAULT_FIFTHBELL_CONFIG.showWeather),
195
- showEarthquakes: normalizeBoolean(contentProps.showEarthquakes, DEFAULT_FIFTHBELL_CONFIG.showEarthquakes),
196
- showMarkets: normalizeBoolean(contentProps.showMarkets, DEFAULT_FIFTHBELL_CONFIG.showMarkets),
197
- showLiveEvents: normalizeBoolean(contentProps.showLiveEvents, DEFAULT_FIFTHBELL_CONFIG.showLiveEvents),
198
- showMarquee: normalizeBoolean(marqueeProps.showMarquee, DEFAULT_FIFTHBELL_CONFIG.showMarquee),
199
- showCallsignTake: normalizeBoolean(contentProps.showCallsignTake, DEFAULT_FIFTHBELL_CONFIG.showCallsignTake),
200
- weatherCities: normalizeStringArray(contentProps.weatherCities),
201
- languageRotation: normalizeLanguageRotation(contentProps.languageRotation),
202
- dataLoadTimeoutMs: clampNumber(contentProps.dataLoadTimeoutMs, DEFAULT_FIFTHBELL_CONFIG.dataLoadTimeoutMs, 1000, 120000),
203
- playlistDefaultDurationMs: clampNumber(contentProps.playlistDefaultDurationMs, DEFAULT_FIFTHBELL_CONFIG.playlistDefaultDurationMs, 1000, 120000),
204
- playlistUpdateIntervalMs: clampNumber(contentProps.playlistUpdateIntervalMs, DEFAULT_FIFTHBELL_CONFIG.playlistUpdateIntervalMs, 16, 5000),
205
- articlesDurationMs: clampNumber(contentProps.articlesDurationMs, DEFAULT_FIFTHBELL_CONFIG.articlesDurationMs, 1000, 120000),
206
- weatherDurationMs: clampNumber(contentProps.weatherDurationMs, DEFAULT_FIFTHBELL_CONFIG.weatherDurationMs, 1000, 120000),
207
- earthquakesDurationMs: clampNumber(contentProps.earthquakesDurationMs, DEFAULT_FIFTHBELL_CONFIG.earthquakesDurationMs, 1000, 120000),
208
- marketsDurationMs: clampNumber(contentProps.marketsDurationMs, DEFAULT_FIFTHBELL_CONFIG.marketsDurationMs, 1000, 120000),
209
- showWorldClocks: normalizeBoolean(cornerProps.showWorldClocks, DEFAULT_FIFTHBELL_CONFIG.showWorldClocks),
210
- showBellIcon: true,
211
- worldClockRotateIntervalMs: clampNumber(cornerProps.worldClockRotateIntervalMs, DEFAULT_FIFTHBELL_CONFIG.worldClockRotateIntervalMs, 500, 120000),
212
- worldClockTransitionMs: clampNumber(cornerProps.worldClockTransitionMs, DEFAULT_FIFTHBELL_CONFIG.worldClockTransitionMs, 0, 10000),
213
- worldClockShuffle: normalizeBoolean(cornerProps.worldClockShuffle, DEFAULT_FIFTHBELL_CONFIG.worldClockShuffle),
214
- worldClockWidthPx: clampNumber(cornerProps.worldClockWidthPx, DEFAULT_FIFTHBELL_CONFIG.worldClockWidthPx, 120, 600),
215
- worldClockCities: normalizeWorldClockCities(cornerProps.worldClockCities),
216
- audioCueEnabled: normalizeBoolean(contentProps.audioCueEnabled, DEFAULT_FIFTHBELL_CONFIG.audioCueEnabled),
217
- audioCueMinute: clampNumber(contentProps.audioCueMinute, DEFAULT_FIFTHBELL_CONFIG.audioCueMinute, 0, 59),
218
- audioCueSecond: clampNumber(contentProps.audioCueSecond, DEFAULT_FIFTHBELL_CONFIG.audioCueSecond, 0, 59),
219
- callsignPrelaunchUntilNyc: typeof contentProps.callsignPrelaunchUntilNyc === 'string' && contentProps.callsignPrelaunchUntilNyc.trim()
220
- ? contentProps.callsignPrelaunchUntilNyc.trim()
221
- : DEFAULT_FIFTHBELL_CONFIG.callsignPrelaunchUntilNyc,
222
- callsignWindowStartSecond: clampNumber(contentProps.callsignWindowStartSecond, DEFAULT_FIFTHBELL_CONFIG.callsignWindowStartSecond, 0, 59),
223
- callsignWindowEndSecond: clampNumber(contentProps.callsignWindowEndSecond, DEFAULT_FIFTHBELL_CONFIG.callsignWindowEndSecond, 0, 59),
224
- marqueeMinPostsCount: parsedMarqueeMinPostsCount,
225
- marqueeMinAverageRelevance: parsedMarqueeMinAverageRelevance,
226
- marqueeMinMedianRelevance: parsedMarqueeMinMedianRelevance,
227
- marqueePixelsPerSecond: clampNumber(marqueeProps.marqueePixelsPerSecond, DEFAULT_FIFTHBELL_CONFIG.marqueePixelsPerSecond, 10, 1000),
228
- marqueeMinDurationSeconds: clampNumber(marqueeProps.marqueeMinDurationSeconds, DEFAULT_FIFTHBELL_CONFIG.marqueeMinDurationSeconds, 1, 120),
229
- marqueeHeightPx: clampNumber(marqueeProps.marqueeHeightPx, DEFAULT_FIFTHBELL_CONFIG.marqueeHeightPx, 72, 200)
230
- };
231
- }
232
- function normalizeLaunchDate(rawDate) {
233
- const parsed = new Date(rawDate);
234
- if (Number.isNaN(parsed.getTime())) {
235
- return new Date(DEFAULT_CALLSIGN_PRELAUNCH_UNTIL_NYC);
236
- }
237
- return parsed;
238
- }
12
+ import { fetchEventsRetained, hasEventChanges } from './events.js';
13
+ import { loadProgramData } from './program-data.js';
14
+ import { clearCachesAndReload } from './program-reload.js';
15
+ import { createArticlesSegment, createEarthquakeSegment, createLiveEventSegment, createMarketsSegment, createWeatherSegment, usePlaylistEngine } from './segments/index.js';
16
+ import { normalizeCityKey, toRecord, parseSceneMetadata, resolveFifthBellLayerAvailability, extractConfigFromMetadata, normalizeLaunchDate, } from './live-program-config.js';
239
17
  export default function LiveProgram({ programId = 'fifthbell', embedded = false, sceneMetadata, activeComponents, apiBaseUrl }) {
240
18
  const [state, setState] = useState(null);
241
19
  const stateRef = useRef(null);
@@ -243,7 +21,6 @@ export default function LiveProgram({ programId = 'fifthbell', embedded = false,
243
21
  const [showLogoSlide, setShowLogoSlide] = useState(false);
244
22
  const [callsignTime, setCallsignTime] = useState(new Date());
245
23
  const audioRef = useRef(null);
246
- const audioInitialized = useRef(false);
247
24
  const [languageIndex, setLanguageIndex] = useState(0);
248
25
  const [articles, setArticles] = useState([]);
249
26
  const [weatherData, setWeatherData] = useState([]);
@@ -258,8 +35,12 @@ export default function LiveProgram({ programId = 'fifthbell', embedded = false,
258
35
  const [dataLoaded, setDataLoaded] = useState(false);
259
36
  const lastFetchedItemRef = useRef(-1);
260
37
  const activeInstantAudioRef = useRef(null);
261
- const activeInstantAudiosRef = useRef(new Set());
38
+ const sceneInstantBaseVolumeRef = useRef(1);
39
+ const activeInstantAudiosRef = useRef(new Map());
262
40
  const sceneInstantTakeSequenceRef = useRef(0);
41
+ const sceneInstantAudiosRef = useRef(new Set());
42
+ const sceneInstantFadeFramesRef = useRef(new Set());
43
+ const sceneInstantPlayTimersRef = useRef(new Set());
263
44
  const mixerSettingsRef = useRef({});
264
45
  const songAudioRef = useRef(null);
265
46
  const controlledBySceneRenderer = sceneMetadata !== undefined;
@@ -272,7 +53,8 @@ export default function LiveProgram({ programId = 'fifthbell', embedded = false,
272
53
  const config = useMemo(() => extractConfigFromMetadata(effectiveSceneMetadata), [effectiveSceneMetadata]);
273
54
  const layerAvailability = useMemo(() => resolveFifthBellLayerAvailability(activeComponents), [activeComponents]);
274
55
  const languageRotation = config.languageRotation;
275
- const currentLanguage = languageRotation[languageIndex] ?? languageRotation[0] ?? 'en';
56
+ // The rotation is never empty; the index can briefly exceed a shortened rotation.
57
+ const currentLanguage = languageRotation[languageIndex] ?? languageRotation[0];
276
58
  const normalizedProgramId = programId.trim() || 'fifthbell';
277
59
  const programEndpoint = resolveProgramEndpoint(apiBaseUrl, normalizedProgramId);
278
60
  const reportProgramDiagnostic = useCallback((diagnostic, payload) => {
@@ -296,7 +78,8 @@ export default function LiveProgram({ programId = 'fifthbell', embedded = false,
296
78
  stateRef.current = result.state;
297
79
  setState(result.state);
298
80
  }
299
- else if (result.diagnostic) {
81
+ else {
82
+ // Every rejected snapshot carries its diagnostic.
300
83
  reportProgramDiagnostic(result.diagnostic);
301
84
  }
302
85
  }
@@ -319,27 +102,15 @@ export default function LiveProgram({ programId = 'fifthbell', embedded = false,
319
102
  void refreshProgramState();
320
103
  }, [controlledBySceneRenderer, refreshProgramState]);
321
104
  const refreshAllData = useCallback(async () => {
322
- const [articlesData, weatherDataResult, earthquakesData, marketsData, liveEventData] = await Promise.all([
323
- fetchArticles(currentLanguage),
324
- fetchWeatherData(),
325
- fetchEarthquakes(currentLanguage),
326
- fetchMarketData(),
327
- fetchLiveEvent(currentLanguage),
328
- fetchEvents({
329
- language: currentLanguage,
330
- allowedLanguages: [currentLanguage]
331
- })
332
- ]);
333
- setArticles(articlesData);
334
- setWeatherData(weatherDataResult);
335
- setEarthquakes(earthquakesData);
336
- setMarkets(marketsData);
337
- setLiveEvent(liveEventData);
338
- const cachedEvents = getCachedEvents();
339
- if (cachedEvents) {
340
- setStageEvents(cachedEvents);
341
- setProgramEvents(cachedEvents);
342
- }
105
+ // No source holds the program back: each answers with its own fallback (fifthbell/brokaw#35).
106
+ const data = await loadProgramData(currentLanguage);
107
+ setArticles(data.articles);
108
+ setWeatherData(data.weather);
109
+ setEarthquakes(data.earthquakes);
110
+ setMarkets(data.markets);
111
+ setLiveEvent(data.liveEvent);
112
+ setStageEvents(data.events);
113
+ setProgramEvents(data.events);
343
114
  setDataLoaded(true);
344
115
  }, [currentLanguage]);
345
116
  useEffect(() => {
@@ -352,6 +123,13 @@ export default function LiveProgram({ programId = 'fifthbell', embedded = false,
352
123
  if (fadeMs > 0) {
353
124
  const initialVolume = audio.volume;
354
125
  const startTime = performance.now();
126
+ const queueFadeStep = () => {
127
+ const frame = requestAnimationFrame((timestamp) => {
128
+ sceneInstantFadeFramesRef.current.delete(frame);
129
+ fadeStep(timestamp);
130
+ });
131
+ sceneInstantFadeFramesRef.current.add(frame);
132
+ };
355
133
  const fadeStep = (timestamp) => {
356
134
  const elapsed = timestamp - startTime;
357
135
  if (elapsed >= fadeMs) {
@@ -363,13 +141,17 @@ export default function LiveProgram({ programId = 'fifthbell', embedded = false,
363
141
  catch { /* no-op */ }
364
142
  audio.onended = null;
365
143
  audio.onerror = null;
366
- activeInstantAudioRef.current = null;
144
+ sceneInstantAudiosRef.current.delete(audio);
145
+ if (activeInstantAudioRef.current === audio) {
146
+ activeInstantAudioRef.current = null;
147
+ }
367
148
  return;
368
149
  }
369
- audio.volume = Math.max(0, initialVolume * (1 - elapsed / fadeMs));
370
- requestAnimationFrame(fadeStep);
150
+ // A queued frame's timestamp can precede the time the fade was requested.
151
+ audio.volume = initialVolume * (1 - Math.min(1, Math.max(0, elapsed / fadeMs)));
152
+ queueFadeStep();
371
153
  };
372
- requestAnimationFrame(fadeStep);
154
+ queueFadeStep();
373
155
  return;
374
156
  }
375
157
  audio.pause();
@@ -379,8 +161,37 @@ export default function LiveProgram({ programId = 'fifthbell', embedded = false,
379
161
  catch { /* no-op */ }
380
162
  audio.onended = null;
381
163
  audio.onerror = null;
164
+ sceneInstantAudiosRef.current.delete(audio);
382
165
  activeInstantAudioRef.current = null;
383
166
  }, []);
167
+ useEffect(() => () => {
168
+ sceneInstantTakeSequenceRef.current += 1;
169
+ for (const frame of sceneInstantFadeFramesRef.current)
170
+ cancelAnimationFrame(frame);
171
+ sceneInstantFadeFramesRef.current.clear();
172
+ for (const timer of sceneInstantPlayTimersRef.current)
173
+ window.clearTimeout(timer);
174
+ sceneInstantPlayTimersRef.current.clear();
175
+ const stopOwnedAudio = (audio) => {
176
+ audio.pause();
177
+ try {
178
+ audio.currentTime = 0;
179
+ }
180
+ catch { /* no-op */ }
181
+ audio.onended = null;
182
+ audio.onerror = null;
183
+ };
184
+ for (const audio of sceneInstantAudiosRef.current)
185
+ stopOwnedAudio(audio);
186
+ sceneInstantAudiosRef.current.clear();
187
+ for (const audio of activeInstantAudiosRef.current.keys())
188
+ stopOwnedAudio(audio);
189
+ activeInstantAudiosRef.current.clear();
190
+ if (songAudioRef.current)
191
+ stopOwnedAudio(songAudioRef.current);
192
+ activeInstantAudioRef.current = null;
193
+ songAudioRef.current = null;
194
+ }, []);
384
195
  useSSE({
385
196
  url: `${programEndpoint}/events`,
386
197
  enabled: !controlledBySceneRenderer,
@@ -389,8 +200,8 @@ export default function LiveProgram({ programId = 'fifthbell', embedded = false,
389
200
  onMessage: (payload) => {
390
201
  const parsed = parseProgramEvent(payload, normalizedProgramId);
391
202
  if (!parsed.event) {
392
- if (parsed.diagnostic)
393
- reportProgramDiagnostic(parsed.diagnostic);
203
+ // An event the contract refuses always carries its diagnostic.
204
+ reportProgramDiagnostic(parsed.diagnostic);
394
205
  return;
395
206
  }
396
207
  const data = parsed.event;
@@ -411,7 +222,7 @@ export default function LiveProgram({ programId = 'fifthbell', embedded = false,
411
222
  console.log('[scene_instant_take]', data.instant.name, data.instant.audioUrl);
412
223
  sceneInstantTakeSequenceRef.current += 1;
413
224
  const takeSequence = sceneInstantTakeSequenceRef.current;
414
- const ms = (mixerSettingsRef.current || {});
225
+ const ms = mixerSettingsRef.current;
415
226
  const masterVol = ms.sceneInstantMasterVolume ?? 1;
416
227
  const muted = ms.sceneInstantMuted === true;
417
228
  const baseVol = typeof data.instant.volume === 'number' ? Math.max(0, Math.min(1, data.instant.volume)) : 1;
@@ -421,20 +232,31 @@ export default function LiveProgram({ programId = 'fifthbell', embedded = false,
421
232
  audio.preload = 'auto';
422
233
  audio.loop = data.loop !== false;
423
234
  audio.volume = finalVol;
424
- audio.onended = () => { activeInstantAudioRef.current = null; };
425
- audio.onerror = () => { console.error('[scene_instant] audio error'); activeInstantAudioRef.current = null; };
235
+ sceneInstantBaseVolumeRef.current = baseVol;
236
+ sceneInstantAudiosRef.current.add(audio);
237
+ audio.onended = () => { sceneInstantAudiosRef.current.delete(audio); if (activeInstantAudioRef.current === audio)
238
+ activeInstantAudioRef.current = null; };
239
+ audio.onerror = () => { console.error('[scene_instant] audio error'); sceneInstantAudiosRef.current.delete(audio); if (activeInstantAudioRef.current === audio)
240
+ activeInstantAudioRef.current = null; };
426
241
  activeInstantAudioRef.current = audio;
427
- audio.play().catch((err) => { console.error('[scene_instant] play failed:', err); activeInstantAudioRef.current = null; });
242
+ audio.play().catch((err) => {
243
+ console.error('[scene_instant] play failed:', err);
244
+ sceneInstantAudiosRef.current.delete(audio);
245
+ if (activeInstantAudioRef.current === audio)
246
+ activeInstantAudioRef.current = null;
247
+ });
428
248
  };
429
249
  const currentlyPlaying = activeInstantAudioRef.current;
430
250
  if (currentlyPlaying && !currentlyPlaying.paused && !currentlyPlaying.ended) {
431
251
  const switchFadeMs = 1500;
432
252
  stopSceneInstantAudio(switchFadeMs);
433
- window.setTimeout(() => {
253
+ const timer = window.setTimeout(() => {
254
+ sceneInstantPlayTimersRef.current.delete(timer);
434
255
  if (sceneInstantTakeSequenceRef.current !== takeSequence)
435
256
  return;
436
257
  playAudio();
437
258
  }, switchFadeMs);
259
+ sceneInstantPlayTimersRef.current.add(timer);
438
260
  return;
439
261
  }
440
262
  stopSceneInstantAudio();
@@ -452,16 +274,27 @@ export default function LiveProgram({ programId = 'fifthbell', embedded = false,
452
274
  return;
453
275
  }
454
276
  stopSceneInstantAudio(1500);
455
- window.setTimeout(() => {
277
+ const timer = window.setTimeout(() => {
278
+ sceneInstantPlayTimersRef.current.delete(timer);
456
279
  const audio = new Audio(playback.instant.audioUrl);
457
280
  audio.preload = 'auto';
458
281
  audio.loop = true;
459
282
  audio.volume = typeof playback.instant.volume === 'number' ? Math.max(0, Math.min(1, playback.instant.volume)) : 1;
460
- audio.onended = () => { activeInstantAudioRef.current = null; };
461
- audio.onerror = () => { console.error('[scene_instant] audio error'); activeInstantAudioRef.current = null; };
283
+ sceneInstantBaseVolumeRef.current = audio.volume;
284
+ sceneInstantAudiosRef.current.add(audio);
285
+ audio.onended = () => { sceneInstantAudiosRef.current.delete(audio); if (activeInstantAudioRef.current === audio)
286
+ activeInstantAudioRef.current = null; };
287
+ audio.onerror = () => { console.error('[scene_instant] audio error'); sceneInstantAudiosRef.current.delete(audio); if (activeInstantAudioRef.current === audio)
288
+ activeInstantAudioRef.current = null; };
462
289
  activeInstantAudioRef.current = audio;
463
- audio.play().catch((err) => { console.error('[scene_instant] play failed:', err); activeInstantAudioRef.current = null; });
290
+ audio.play().catch((err) => {
291
+ console.error('[scene_instant] play failed:', err);
292
+ sceneInstantAudiosRef.current.delete(audio);
293
+ if (activeInstantAudioRef.current === audio)
294
+ activeInstantAudioRef.current = null;
295
+ });
464
296
  }, 1500);
297
+ sceneInstantPlayTimersRef.current.add(timer);
465
298
  }
466
299
  else {
467
300
  stopSceneInstantAudio();
@@ -469,7 +302,7 @@ export default function LiveProgram({ programId = 'fifthbell', embedded = false,
469
302
  }
470
303
  else if (data.type === 'instant_play' && data.instant?.audioUrl) {
471
304
  console.log('[instant_play]', data.instant.name, data.instant.audioUrl);
472
- const ms = (mixerSettingsRef.current || {});
305
+ const ms = mixerSettingsRef.current;
473
306
  const masterVol = ms.instantMasterVolume ?? 1;
474
307
  const muted = ms.instantMuted === true;
475
308
  const baseVol = typeof data.instant.volume === 'number' ? Math.max(0, Math.min(1, data.instant.volume)) : 1;
@@ -482,12 +315,12 @@ export default function LiveProgram({ programId = 'fifthbell', embedded = false,
482
315
  };
483
316
  audio.onended = cleanup;
484
317
  audio.onerror = () => { console.error('[instant_play] error'); cleanup(); };
485
- activeInstantAudiosRef.current.add(audio);
318
+ activeInstantAudiosRef.current.set(audio, baseVol);
486
319
  audio.play().catch((err) => { console.error('[instant_play] play failed:', err); cleanup(); });
487
320
  }
488
321
  else if (data.type === 'instant_stop_all') {
489
322
  stopSceneInstantAudio();
490
- for (const audio of activeInstantAudiosRef.current) {
323
+ for (const audio of activeInstantAudiosRef.current.keys()) {
491
324
  audio.pause();
492
325
  try {
493
326
  audio.currentTime = 0;
@@ -507,14 +340,14 @@ export default function LiveProgram({ programId = 'fifthbell', embedded = false,
507
340
  const ms = mixerSettingsRef.current;
508
341
  const vol = ms.sceneInstantMasterVolume ?? 1;
509
342
  const muted = ms.sceneInstantMuted === true;
510
- current.volume = muted ? 0 : Math.max(0, Math.min(1, vol));
343
+ current.volume = muted ? 0 : Math.max(0, Math.min(1, sceneInstantBaseVolumeRef.current * vol));
511
344
  }
512
345
  // Update instant play volumes
513
- const ms = (mixerSettingsRef.current || {});
346
+ const ms = mixerSettingsRef.current;
514
347
  const instantVol = ms.instantMasterVolume ?? 1;
515
348
  const instantMuted = ms.instantMuted === true;
516
- for (const audio of activeInstantAudiosRef.current) {
517
- audio.volume = instantMuted ? 0 : Math.max(0, Math.min(1, instantVol));
349
+ for (const [audio, baseVol] of activeInstantAudiosRef.current) {
350
+ audio.volume = instantMuted ? 0 : Math.max(0, Math.min(1, baseVol * instantVol));
518
351
  }
519
352
  // Handle song sequence playback
520
353
  const songSeq = settings.songSequence;
@@ -524,6 +357,9 @@ export default function LiveProgram({ programId = 'fifthbell', embedded = false,
524
357
  const activeItem = songSeq.items.find((item) => item.id === songSeq.activeItemId) || songSeq.items[0];
525
358
  const songUrl = activeItem?.audioUrl;
526
359
  if (songUrl) {
360
+ const songMuted = ms.songMuted === true;
361
+ const songVol = ms.songMasterVolume ?? 1;
362
+ const finalSongVolume = songMuted ? 0 : Math.max(0, Math.min(1, songVol));
527
363
  if (!currentSong || currentSong.src !== songUrl) {
528
364
  if (currentSong) {
529
365
  currentSong.pause();
@@ -533,14 +369,14 @@ export default function LiveProgram({ programId = 'fifthbell', embedded = false,
533
369
  const audio = new Audio(songUrl);
534
370
  audio.preload = 'auto';
535
371
  audio.loop = songSeq.loop !== false;
536
- const ms2 = (mixerSettingsRef.current || {});
537
- const songMuted = ms2.songMuted === true;
538
- const songVol = ms2.songMasterVolume ?? 1;
539
- audio.volume = songMuted ? 0 : Math.max(0, Math.min(1, songVol));
372
+ audio.volume = finalSongVolume;
540
373
  audio.onerror = () => { console.error('[song] playback error'); };
541
374
  songAudioRef.current = audio;
542
375
  audio.play().catch((err) => { console.error('[song] play failed:', err); });
543
376
  }
377
+ else {
378
+ currentSong.volume = finalSongVolume;
379
+ }
544
380
  }
545
381
  }
546
382
  else if (currentSong) {
@@ -560,40 +396,19 @@ export default function LiveProgram({ programId = 'fifthbell', embedded = false,
560
396
  }
561
397
  }
562
398
  else if (data.type === 'program_reload') {
563
- if (typeof window === 'undefined')
564
- return;
565
- const reloadWithCacheBust = () => {
566
- const nextUrl = new URL(window.location.href);
567
- nextUrl.searchParams.set('_reload', Date.now().toString());
568
- window.location.replace(nextUrl.toString());
569
- };
570
- if (!('caches' in window)) {
571
- reloadWithCacheBust();
572
- return;
573
- }
574
- void window.caches.keys()
575
- .then((keys) => Promise.all(keys.map((key) => window.caches.delete(key))))
576
- .catch((err) => { console.warn('[program_reload] cache clear failed:', err); })
577
- .finally(() => { reloadWithCacheBust(); });
578
- }
579
- else if (data.type === 'program_stingers_changed') {
580
- // stinger video URLs for scene transitions — stored for transition system
399
+ clearCachesAndReload(window);
581
400
  }
582
401
  }
583
402
  });
584
403
  const refreshEvents = useCallback(async () => {
585
- await fetchEvents({
404
+ const events = await fetchEventsRetained({
586
405
  language: currentLanguage,
587
406
  allowedLanguages: [currentLanguage]
588
407
  });
589
- const cachedEvents = getCachedEvents();
590
- if (!cachedEvents) {
591
- return;
592
- }
593
408
  setStageEvents((prevStage) => {
594
409
  const prevJson = JSON.stringify(prevStage);
595
- const nextJson = JSON.stringify(cachedEvents);
596
- return prevJson === nextJson ? prevStage : cachedEvents;
410
+ const nextJson = JSON.stringify(events);
411
+ return prevJson === nextJson ? prevStage : events;
597
412
  });
598
413
  }, [currentLanguage]);
599
414
  useEffect(() => {
@@ -684,13 +499,6 @@ export default function LiveProgram({ programId = 'fifthbell', embedded = false,
684
499
  updateIntervalMs: config.playlistUpdateIntervalMs,
685
500
  onPlaylistLoop: handlePlaylistLoop
686
501
  });
687
- useEffect(() => {
688
- if (!audioRef.current || audioInitialized.current) {
689
- return;
690
- }
691
- audioRef.current.load();
692
- audioInitialized.current = true;
693
- }, []);
694
502
  useEffect(() => {
695
503
  if (!config.audioCueEnabled) {
696
504
  return;
@@ -81,7 +81,8 @@ export function WorldClocks({ currentTime, timeOverride = null, language = 'en',
81
81
  }
82
82
  };
83
83
  }, [cityPool, rotateIntervalMs, transitionDurationMs, shuffleCities, activeCities]);
84
- const currentCity = cityPool[currentCityIndex] ?? activeCities[0];
84
+ // The index only advances within the pool and the pool is never empty.
85
+ const currentCity = cityPool[currentCityIndex];
85
86
  const formatTime = (timezone) => {
86
87
  if (timeOverride) {
87
88
  const parts = getOverrideClockParts(timeOverride, time);
@@ -39,10 +39,8 @@ function ScrollingTimeline({ updates, language }) {
39
39
  cycleRef.current = setInterval(() => {
40
40
  setVisibleStart((prev) => (prev + 1) % updates.length);
41
41
  }, 5000);
42
- return () => {
43
- if (cycleRef.current)
44
- clearInterval(cycleRef.current);
45
- };
42
+ // The cleanup exists only once the interval is set.
43
+ return () => clearInterval(cycleRef.current);
46
44
  }, [updates.length]);
47
45
  const visibleUpdates = useMemo(() => {
48
46
  if (updates.length <= displayCount)
@@ -27,6 +27,13 @@ interface FetchEventsOptions {
27
27
  allowedLanguages?: SupportedLanguage[];
28
28
  }
29
29
  export declare function fetchEvents(options?: FetchEventsOptions): Promise<Event[]>;
30
+ /**
31
+ * fetchEvents that never throws (fifthbell/brokaw#35). When the events service
32
+ * fails, the last good events for the same options stay for up to
33
+ * SOURCE_RETENTION_MS after their fetch; older ones are dropped, and an empty
34
+ * list is returned so the program runs without event segments.
35
+ */
36
+ export declare function fetchEventsRetained(options?: FetchEventsOptions): Promise<Event[]>;
30
37
  export declare function getCachedEvents(): Event[] | null;
31
38
  export declare function getLastFetchTime(): Date | null;
32
39
  export declare function clearCachedEvents(): void;