@fifthbell/brokaw 0.1.39
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.
- package/LICENSE +21 -0
- package/README.md +45 -0
- package/dist/carousels.d.ts +1 -0
- package/dist/carousels.js +65 -0
- package/dist/components/live-program/LiveProgram.d.ts +8 -0
- package/dist/components/live-program/LiveProgram.js +526 -0
- package/dist/components/live-program/assets.d.ts +14 -0
- package/dist/components/live-program/assets.js +14 -0
- package/dist/components/live-program/components/Marquee.d.ts +16 -0
- package/dist/components/live-program/components/Marquee.js +88 -0
- package/dist/components/live-program/components/MarqueeCurtain.d.ts +5 -0
- package/dist/components/live-program/components/MarqueeCurtain.js +30 -0
- package/dist/components/live-program/components/WorldClocks.d.ts +19 -0
- package/dist/components/live-program/components/WorldClocks.js +101 -0
- package/dist/components/live-program/components/slides/ArticleSlide.d.ts +14 -0
- package/dist/components/live-program/components/slides/ArticleSlide.js +22 -0
- package/dist/components/live-program/components/slides/CallsignSlide.d.ts +6 -0
- package/dist/components/live-program/components/slides/CallsignSlide.js +49 -0
- package/dist/components/live-program/components/slides/slideStyles.d.ts +1 -0
- package/dist/components/live-program/components/slides/slideStyles.js +64 -0
- package/dist/components/live-program/events.d.ts +34 -0
- package/dist/components/live-program/events.js +167 -0
- package/dist/components/live-program/hooks/useSSE.d.ts +11 -0
- package/dist/components/live-program/hooks/useSSE.js +67 -0
- package/dist/components/live-program/i18n.d.ts +4 -0
- package/dist/components/live-program/i18n.js +290 -0
- package/dist/components/live-program/segments/ArticlesSegment.d.ts +6 -0
- package/dist/components/live-program/segments/ArticlesSegment.js +160 -0
- package/dist/components/live-program/segments/EarthquakeSegment.d.ts +16 -0
- package/dist/components/live-program/segments/EarthquakeSegment.js +130 -0
- package/dist/components/live-program/segments/MarketsSegment.d.ts +12 -0
- package/dist/components/live-program/segments/MarketsSegment.js +87 -0
- package/dist/components/live-program/segments/WeatherSegment.d.ts +15 -0
- package/dist/components/live-program/segments/WeatherSegment.js +184 -0
- package/dist/components/live-program/segments/index.d.ts +6 -0
- package/dist/components/live-program/segments/index.js +6 -0
- package/dist/components/live-program/segments/types.d.ts +23 -0
- package/dist/components/live-program/segments/types.js +1 -0
- package/dist/components/live-program/segments/usePlaylistEngine.d.ts +9 -0
- package/dist/components/live-program/segments/usePlaylistEngine.js +108 -0
- package/dist/components/live-program/utils/broadcastTime.d.ts +12 -0
- package/dist/components/live-program/utils/broadcastTime.js +33 -0
- package/dist/homepage-distributor.d.ts +55 -0
- package/dist/homepage-distributor.js +68 -0
- package/dist/instagram-image-template.d.ts +8 -0
- package/dist/instagram-image-template.js +200 -0
- package/dist/outlet-config.d.ts +23 -0
- package/dist/outlet-config.js +23 -0
- package/dist/renderer.browser.d.ts +2 -0
- package/dist/renderer.browser.js +128 -0
- package/dist/renderer.core.d.ts +9 -0
- package/dist/renderer.core.js +353 -0
- package/dist/renderer.d.ts +3 -0
- package/dist/renderer.js +3 -0
- package/dist/renderer.node.d.ts +2 -0
- package/dist/renderer.node.js +71 -0
- package/dist/types/canonical-article.d.ts +247 -0
- package/dist/types/canonical-article.js +235 -0
- package/dist/utils/sofascore.d.ts +3 -0
- package/dist/utils/sofascore.js +31 -0
- package/package.json +78 -0
- package/src/partial-deps.json +52 -0
- package/src/styles/compiled.css +2 -0
- package/src/templates/layouts/404.hbs +5 -0
- package/src/templates/layouts/article-page.hbs +5 -0
- package/src/templates/layouts/category-page.hbs +5 -0
- package/src/templates/layouts/homepage.hbs +5 -0
- package/src/templates/layouts/link-in-bio.hbs +228 -0
- package/src/templates/layouts/live-story.hbs +5 -0
- package/src/templates/layouts/search-page.hbs +5 -0
- package/src/templates/partials/blocks/audio.hbs +12 -0
- package/src/templates/partials/blocks/data-table.hbs +23 -0
- package/src/templates/partials/blocks/divider.hbs +1 -0
- package/src/templates/partials/blocks/heading.hbs +9 -0
- package/src/templates/partials/blocks/image.hbs +6 -0
- package/src/templates/partials/blocks/info-box.hbs +8 -0
- package/src/templates/partials/blocks/instagram.hbs +28 -0
- package/src/templates/partials/blocks/key-points.hbs +8 -0
- package/src/templates/partials/blocks/list.hbs +13 -0
- package/src/templates/partials/blocks/live-update.hbs +24 -0
- package/src/templates/partials/blocks/pull-quote.hbs +6 -0
- package/src/templates/partials/blocks/rich-text.hbs +1 -0
- package/src/templates/partials/blocks/tiktok.hbs +15 -0
- package/src/templates/partials/blocks/x.hbs +74 -0
- package/src/templates/partials/blocks/youtube.hbs +12 -0
- package/src/templates/partials/components/article-main.hbs +159 -0
- package/src/templates/partials/components/breaking-news/live-updates-column.hbs +29 -0
- package/src/templates/partials/components/breaking-news.hbs +56 -0
- package/src/templates/partials/components/category/header.hbs +5 -0
- package/src/templates/partials/components/category/main-grid.hbs +55 -0
- package/src/templates/partials/components/category/main.hbs +7 -0
- package/src/templates/partials/components/category/more-grid.hbs +26 -0
- package/src/templates/partials/components/editorial-hero.hbs +73 -0
- package/src/templates/partials/components/headline.hbs +15 -0
- package/src/templates/partials/components/hero-editorial.hbs +1 -0
- package/src/templates/partials/components/hero.hbs +1 -0
- package/src/templates/partials/components/home/landing.hbs +111 -0
- package/src/templates/partials/components/home/main.hbs +63 -0
- package/src/templates/partials/components/home/more-stories.hbs +23 -0
- package/src/templates/partials/components/home/must-read.hbs +77 -0
- package/src/templates/partials/components/live-story/main.hbs +229 -0
- package/src/templates/partials/components/not-found/main.hbs +28 -0
- package/src/templates/partials/components/search/main.hbs +420 -0
- package/src/templates/partials/components/snack.hbs +92 -0
- package/src/templates/partials/components/spotlight-hero.hbs +59 -0
- package/src/templates/partials/components/trending.hbs +14 -0
- package/src/templates/partials/components/ui/accordion.hbs +30 -0
- package/src/templates/partials/components/ui/breadcrumb.hbs +16 -0
- package/src/templates/partials/components/ui/icon-button.hbs +19 -0
- package/src/templates/partials/components/ui/loading-spinner.hbs +27 -0
- package/src/templates/partials/components/ui/pagination.hbs +56 -0
- package/src/templates/partials/components/ui/scroll-area.hbs +12 -0
- package/src/templates/partials/components/ui/status-badge.hbs +21 -0
- package/src/templates/partials/footers/footer-full.hbs +79 -0
- package/src/templates/partials/footers/footer-minimal.hbs +5 -0
- package/src/templates/partials/headers/header-main.hbs +397 -0
- package/src/templates/partials/headers/header-minimal.hbs +16 -0
- package/src/templates/partials/nav/nav-categories.hbs +5 -0
- package/src/templates/partials/shell/doc-end.hbs +282 -0
- package/src/templates/partials/shell/doc-start-404.hbs +28 -0
- package/src/templates/partials/shell/doc-start-standard.hbs +68 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Fifth Bell
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# @fifthbell/brokaw
|
|
2
|
+
|
|
3
|
+
Server-side renderer and Handlebars template bundle for Fifth Bell pages.
|
|
4
|
+
|
|
5
|
+
## What it does
|
|
6
|
+
|
|
7
|
+
- Renders canonical content documents into HTML
|
|
8
|
+
- Supports `article-page`, `homepage`, `category-page`, `live-story`, and `404` layouts
|
|
9
|
+
- Ships reusable Handlebars templates, partial dependency metadata, and compiled CSS
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @fifthbell/brokaw
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Basic usage
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { render } from '@fifthbell/brokaw';
|
|
21
|
+
|
|
22
|
+
const html = render(doc);
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
`doc` must match the canonical schema used by the renderer (see [src/types/canonical-article.ts](src/types/canonical-article.ts)).
|
|
26
|
+
|
|
27
|
+
## Exports
|
|
28
|
+
|
|
29
|
+
- `@fifthbell/brokaw` -> renderer entrypoint
|
|
30
|
+
- `@fifthbell/brokaw/partial-deps.json` -> partial-to-layout dependency map
|
|
31
|
+
|
|
32
|
+
## Development
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
npm install
|
|
36
|
+
npm run typecheck
|
|
37
|
+
npm run test:unit
|
|
38
|
+
npm run build
|
|
39
|
+
npm run storybook
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Publish flow
|
|
43
|
+
|
|
44
|
+
- CI validates typecheck, unit tests, and package build on pull requests and `main` pushes.
|
|
45
|
+
- Package publish is triggered by pushing a `v*` tag.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function initCarousels(root?: ParentNode): void;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
function setSlideState(slides, dots, index) {
|
|
2
|
+
slides.forEach((slide, slideIndex) => {
|
|
3
|
+
const active = slideIndex === index;
|
|
4
|
+
slide.classList.toggle('hidden', !active);
|
|
5
|
+
slide.classList.toggle('opacity-0', !active);
|
|
6
|
+
slide.classList.toggle('opacity-100', active);
|
|
7
|
+
slide.classList.toggle('active', active);
|
|
8
|
+
});
|
|
9
|
+
dots.forEach((dot, dotIndex) => {
|
|
10
|
+
dot.classList.toggle('active', dotIndex === index);
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
export function initCarousels(root = document) {
|
|
14
|
+
const scopes = root.querySelectorAll('[data-carousel]');
|
|
15
|
+
scopes.forEach((scope) => {
|
|
16
|
+
if (scope.dataset.carouselBound === 'true')
|
|
17
|
+
return;
|
|
18
|
+
const slides = Array.from(scope.querySelectorAll('.carousel-slide'));
|
|
19
|
+
if (slides.length === 0) {
|
|
20
|
+
scope.dataset.carouselBound = 'true';
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const dots = Array.from(scope.querySelectorAll('.carousel-dot'));
|
|
24
|
+
const nextButton = scope.querySelector('.carousel-next');
|
|
25
|
+
const activeIndex = slides.findIndex((slide) => slide.classList.contains('active'));
|
|
26
|
+
let currentIndex = activeIndex >= 0 ? activeIndex : 0;
|
|
27
|
+
const clearTimer = () => {
|
|
28
|
+
if (!scope.__brokawCarouselTimer)
|
|
29
|
+
return;
|
|
30
|
+
window.clearInterval(scope.__brokawCarouselTimer);
|
|
31
|
+
delete scope.__brokawCarouselTimer;
|
|
32
|
+
};
|
|
33
|
+
const startTimer = () => {
|
|
34
|
+
clearTimer();
|
|
35
|
+
if (slides.length < 2)
|
|
36
|
+
return;
|
|
37
|
+
scope.__brokawCarouselTimer = window.setInterval(() => {
|
|
38
|
+
if (!document.contains(scope)) {
|
|
39
|
+
clearTimer();
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
currentIndex = (currentIndex + 1) % slides.length;
|
|
43
|
+
setSlideState(slides, dots, currentIndex);
|
|
44
|
+
}, 6000);
|
|
45
|
+
};
|
|
46
|
+
const goToSlide = (nextIndex) => {
|
|
47
|
+
currentIndex = nextIndex;
|
|
48
|
+
setSlideState(slides, dots, currentIndex);
|
|
49
|
+
startTimer();
|
|
50
|
+
};
|
|
51
|
+
dots.forEach((dot, dotIndex) => {
|
|
52
|
+
dot.addEventListener('click', () => goToSlide(dotIndex));
|
|
53
|
+
});
|
|
54
|
+
if (nextButton) {
|
|
55
|
+
nextButton.addEventListener('click', () => {
|
|
56
|
+
goToSlide((currentIndex + 1) % slides.length);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
scope.addEventListener('mouseenter', clearTimer);
|
|
60
|
+
scope.addEventListener('mouseleave', startTimer);
|
|
61
|
+
setSlideState(slides, dots, currentIndex);
|
|
62
|
+
startTimer();
|
|
63
|
+
scope.dataset.carouselBound = 'true';
|
|
64
|
+
});
|
|
65
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
interface LiveProgramProps {
|
|
2
|
+
programId?: string;
|
|
3
|
+
embedded?: boolean;
|
|
4
|
+
sceneMetadata?: Record<string, unknown> | null;
|
|
5
|
+
activeComponents?: string[];
|
|
6
|
+
}
|
|
7
|
+
export default function LiveProgram({ programId, embedded, sceneMetadata, activeComponents }: LiveProgramProps): import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,526 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
3
|
+
import { useSSE } from './hooks/useSSE.js';
|
|
4
|
+
// Hardcoded API Base URL for Fifthbell
|
|
5
|
+
function getApiBaseUrl() {
|
|
6
|
+
if (typeof window === 'undefined')
|
|
7
|
+
return 'http://127.0.0.1:3000';
|
|
8
|
+
// Use the current host to dynamically target however they're accessing it
|
|
9
|
+
const hostname = window.location.hostname;
|
|
10
|
+
return `http://${hostname.includes(':') ? `[${hostname}]` : hostname}:3000`;
|
|
11
|
+
}
|
|
12
|
+
function apiUrl(path) {
|
|
13
|
+
const normalizedPath = path.startsWith('/') ? path : `/${path}`;
|
|
14
|
+
return `${getApiBaseUrl()}${normalizedPath}`;
|
|
15
|
+
}
|
|
16
|
+
import { FIFTHBELL_ASSETS } from './assets.js';
|
|
17
|
+
import { MarqueeCurtain } from './components/MarqueeCurtain.js';
|
|
18
|
+
import Marquee from './components/Marquee.js';
|
|
19
|
+
import { DEFAULT_WORLD_CLOCK_CITIES } from './components/WorldClocks.js';
|
|
20
|
+
import { CallsignSlide } from './components/slides/CallsignSlide.js';
|
|
21
|
+
import { slideStyles } from './components/slides/slideStyles.js';
|
|
22
|
+
import { fetchEvents, getCachedEvents, hasEventChanges } from './events.js';
|
|
23
|
+
import { createArticlesSegment, createEarthquakeSegment, createMarketsSegment, createWeatherSegment, fetchArticles, fetchEarthquakes, fetchMarketData, fetchWeatherData, usePlaylistEngine } from './segments/index.js';
|
|
24
|
+
const DEFAULT_LANGUAGE_ROTATION = ['en', 'es', 'en', 'it'];
|
|
25
|
+
const DEFAULT_CALLSIGN_PRELAUNCH_UNTIL_NYC = '2026-01-02T21:30:00';
|
|
26
|
+
const FIFTHBELL_COMPONENT_TYPE_CONTENT = 'fifthbell-content';
|
|
27
|
+
const FIFTHBELL_COMPONENT_TYPE_MARQUEE = 'fifthbell-marquee';
|
|
28
|
+
const FIFTHBELL_COMPONENT_TYPE_TONI_CLOCK = 'toni-clock';
|
|
29
|
+
const FIFTHBELL_COMPONENT_TYPE_CORNER = 'fifthbell-corner';
|
|
30
|
+
const FIFTHBELL_COMPONENT_TYPE_LEGACY = 'fifthbell';
|
|
31
|
+
const DEFAULT_FIFTHBELL_CONFIG = {
|
|
32
|
+
showArticles: true,
|
|
33
|
+
showWeather: true,
|
|
34
|
+
showEarthquakes: true,
|
|
35
|
+
showMarkets: true,
|
|
36
|
+
showMarquee: false,
|
|
37
|
+
showCallsignTake: true,
|
|
38
|
+
weatherCities: [],
|
|
39
|
+
languageRotation: DEFAULT_LANGUAGE_ROTATION,
|
|
40
|
+
dataLoadTimeoutMs: 15000,
|
|
41
|
+
playlistDefaultDurationMs: 10000,
|
|
42
|
+
playlistUpdateIntervalMs: 100,
|
|
43
|
+
articlesDurationMs: 10000,
|
|
44
|
+
weatherDurationMs: 5000,
|
|
45
|
+
earthquakesDurationMs: 10000,
|
|
46
|
+
marketsDurationMs: 10000,
|
|
47
|
+
showWorldClocks: true,
|
|
48
|
+
showBellIcon: true,
|
|
49
|
+
worldClockRotateIntervalMs: 7000,
|
|
50
|
+
worldClockTransitionMs: 300,
|
|
51
|
+
worldClockShuffle: true,
|
|
52
|
+
worldClockWidthPx: 200,
|
|
53
|
+
worldClockCities: [...DEFAULT_WORLD_CLOCK_CITIES],
|
|
54
|
+
audioCueEnabled: true,
|
|
55
|
+
audioCueMinute: 59,
|
|
56
|
+
audioCueSecond: 55,
|
|
57
|
+
callsignPrelaunchUntilNyc: DEFAULT_CALLSIGN_PRELAUNCH_UNTIL_NYC,
|
|
58
|
+
callsignWindowStartSecond: 50,
|
|
59
|
+
callsignWindowEndSecond: 3,
|
|
60
|
+
marqueeMinPostsCount: 4,
|
|
61
|
+
marqueeMinAverageRelevance: 0,
|
|
62
|
+
marqueeMinMedianRelevance: 0,
|
|
63
|
+
marqueePixelsPerSecond: 150,
|
|
64
|
+
marqueeMinDurationSeconds: 10,
|
|
65
|
+
marqueeHeightPx: 72
|
|
66
|
+
};
|
|
67
|
+
function clampNumber(value, fallback, min, max) {
|
|
68
|
+
const numeric = typeof value === 'number' ? value : Number(value);
|
|
69
|
+
if (!Number.isFinite(numeric)) {
|
|
70
|
+
return fallback;
|
|
71
|
+
}
|
|
72
|
+
return Math.min(max, Math.max(min, numeric));
|
|
73
|
+
}
|
|
74
|
+
function normalizeBoolean(value, fallback) {
|
|
75
|
+
if (typeof value === 'boolean') {
|
|
76
|
+
return value;
|
|
77
|
+
}
|
|
78
|
+
if (typeof value === 'number') {
|
|
79
|
+
return value !== 0;
|
|
80
|
+
}
|
|
81
|
+
if (typeof value === 'string') {
|
|
82
|
+
const normalized = value.trim().toLowerCase();
|
|
83
|
+
if (['true', '1', 'yes', 'on'].includes(normalized)) {
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
if (['false', '0', 'no', 'off', ''].includes(normalized)) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return fallback;
|
|
91
|
+
}
|
|
92
|
+
function normalizeStringArray(value) {
|
|
93
|
+
if (!Array.isArray(value)) {
|
|
94
|
+
return [];
|
|
95
|
+
}
|
|
96
|
+
const deduped = new Set();
|
|
97
|
+
for (const item of value) {
|
|
98
|
+
if (typeof item !== 'string') {
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
const trimmed = item.trim();
|
|
102
|
+
if (!trimmed) {
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
deduped.add(trimmed);
|
|
106
|
+
}
|
|
107
|
+
return [...deduped];
|
|
108
|
+
}
|
|
109
|
+
function normalizeLanguageRotation(value) {
|
|
110
|
+
if (!Array.isArray(value)) {
|
|
111
|
+
return [...DEFAULT_LANGUAGE_ROTATION];
|
|
112
|
+
}
|
|
113
|
+
const allowed = new Set(['en', 'es', 'it']);
|
|
114
|
+
const filtered = value.filter((item) => typeof item === 'string' && allowed.has(item));
|
|
115
|
+
return filtered.length > 0 ? filtered : [...DEFAULT_LANGUAGE_ROTATION];
|
|
116
|
+
}
|
|
117
|
+
function normalizeWorldClockCities(value) {
|
|
118
|
+
if (!Array.isArray(value)) {
|
|
119
|
+
return [...DEFAULT_WORLD_CLOCK_CITIES];
|
|
120
|
+
}
|
|
121
|
+
const normalized = value
|
|
122
|
+
.map((item) => {
|
|
123
|
+
if (!item || typeof item !== 'object' || Array.isArray(item)) {
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
const city = typeof item.city === 'string' ? item.city.trim() : '';
|
|
127
|
+
const timezone = typeof item.timezone === 'string' ? item.timezone.trim() : '';
|
|
128
|
+
if (!city || !timezone) {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
return { city, timezone };
|
|
132
|
+
})
|
|
133
|
+
.filter((item) => item !== null);
|
|
134
|
+
return normalized.length > 0 ? normalized : [...DEFAULT_WORLD_CLOCK_CITIES];
|
|
135
|
+
}
|
|
136
|
+
function normalizeCityKey(value) {
|
|
137
|
+
return value
|
|
138
|
+
.normalize('NFD')
|
|
139
|
+
.replace(/[\u0300-\u036f]/g, '')
|
|
140
|
+
.trim()
|
|
141
|
+
.toLowerCase();
|
|
142
|
+
}
|
|
143
|
+
function toRecord(value) {
|
|
144
|
+
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
145
|
+
return value;
|
|
146
|
+
}
|
|
147
|
+
return {};
|
|
148
|
+
}
|
|
149
|
+
function parseSceneMetadata(scene) {
|
|
150
|
+
if (!scene || !scene.metadata) {
|
|
151
|
+
return {};
|
|
152
|
+
}
|
|
153
|
+
try {
|
|
154
|
+
const parsed = JSON.parse(scene.metadata);
|
|
155
|
+
return toRecord(parsed);
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
return {};
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
function resolveFifthBellLayerAvailability(activeComponents) {
|
|
162
|
+
const defaultAvailability = {
|
|
163
|
+
content: true,
|
|
164
|
+
marquee: true
|
|
165
|
+
};
|
|
166
|
+
if (!activeComponents || activeComponents.length === 0) {
|
|
167
|
+
return defaultAvailability;
|
|
168
|
+
}
|
|
169
|
+
if (activeComponents.includes(FIFTHBELL_COMPONENT_TYPE_LEGACY)) {
|
|
170
|
+
return defaultAvailability;
|
|
171
|
+
}
|
|
172
|
+
return {
|
|
173
|
+
content: activeComponents.includes(FIFTHBELL_COMPONENT_TYPE_CONTENT),
|
|
174
|
+
marquee: activeComponents.includes(FIFTHBELL_COMPONENT_TYPE_MARQUEE)
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
function extractConfigFromMetadata(metadataInput) {
|
|
178
|
+
const metadata = toRecord(metadataInput);
|
|
179
|
+
const legacyProps = toRecord(metadata[FIFTHBELL_COMPONENT_TYPE_LEGACY]);
|
|
180
|
+
const contentProps = {
|
|
181
|
+
...legacyProps,
|
|
182
|
+
...toRecord(metadata[FIFTHBELL_COMPONENT_TYPE_CONTENT])
|
|
183
|
+
};
|
|
184
|
+
const marqueeProps = {
|
|
185
|
+
...legacyProps,
|
|
186
|
+
...toRecord(metadata[FIFTHBELL_COMPONENT_TYPE_MARQUEE])
|
|
187
|
+
};
|
|
188
|
+
const cornerProps = {
|
|
189
|
+
...legacyProps,
|
|
190
|
+
...toRecord(metadata[FIFTHBELL_COMPONENT_TYPE_TONI_CLOCK]),
|
|
191
|
+
...toRecord(metadata[FIFTHBELL_COMPONENT_TYPE_CORNER])
|
|
192
|
+
};
|
|
193
|
+
const parsedMarqueeMinPostsCount = clampNumber(marqueeProps.marqueeMinPostsCount, DEFAULT_FIFTHBELL_CONFIG.marqueeMinPostsCount, 0, 50);
|
|
194
|
+
let parsedMarqueeMinAverageRelevance = clampNumber(marqueeProps.marqueeMinAverageRelevance, DEFAULT_FIFTHBELL_CONFIG.marqueeMinAverageRelevance, 0, 100);
|
|
195
|
+
let parsedMarqueeMinMedianRelevance = clampNumber(marqueeProps.marqueeMinMedianRelevance, DEFAULT_FIFTHBELL_CONFIG.marqueeMinMedianRelevance, 0, 100);
|
|
196
|
+
// Compatibility: prior defaults were tuned for OR logic. Under threshold logic, treat that trio as legacy.
|
|
197
|
+
if (parsedMarqueeMinPostsCount === 4 && parsedMarqueeMinAverageRelevance === 5 && parsedMarqueeMinMedianRelevance === 7) {
|
|
198
|
+
parsedMarqueeMinAverageRelevance = 0;
|
|
199
|
+
parsedMarqueeMinMedianRelevance = 0;
|
|
200
|
+
}
|
|
201
|
+
return {
|
|
202
|
+
showArticles: normalizeBoolean(contentProps.showArticles, DEFAULT_FIFTHBELL_CONFIG.showArticles),
|
|
203
|
+
showWeather: normalizeBoolean(contentProps.showWeather, DEFAULT_FIFTHBELL_CONFIG.showWeather),
|
|
204
|
+
showEarthquakes: normalizeBoolean(contentProps.showEarthquakes, DEFAULT_FIFTHBELL_CONFIG.showEarthquakes),
|
|
205
|
+
showMarkets: normalizeBoolean(contentProps.showMarkets, DEFAULT_FIFTHBELL_CONFIG.showMarkets),
|
|
206
|
+
showMarquee: normalizeBoolean(marqueeProps.showMarquee, DEFAULT_FIFTHBELL_CONFIG.showMarquee),
|
|
207
|
+
showCallsignTake: normalizeBoolean(contentProps.showCallsignTake, DEFAULT_FIFTHBELL_CONFIG.showCallsignTake),
|
|
208
|
+
weatherCities: normalizeStringArray(contentProps.weatherCities),
|
|
209
|
+
languageRotation: normalizeLanguageRotation(contentProps.languageRotation),
|
|
210
|
+
dataLoadTimeoutMs: clampNumber(contentProps.dataLoadTimeoutMs, DEFAULT_FIFTHBELL_CONFIG.dataLoadTimeoutMs, 1000, 120000),
|
|
211
|
+
playlistDefaultDurationMs: clampNumber(contentProps.playlistDefaultDurationMs, DEFAULT_FIFTHBELL_CONFIG.playlistDefaultDurationMs, 1000, 120000),
|
|
212
|
+
playlistUpdateIntervalMs: clampNumber(contentProps.playlistUpdateIntervalMs, DEFAULT_FIFTHBELL_CONFIG.playlistUpdateIntervalMs, 16, 5000),
|
|
213
|
+
articlesDurationMs: clampNumber(contentProps.articlesDurationMs, DEFAULT_FIFTHBELL_CONFIG.articlesDurationMs, 1000, 120000),
|
|
214
|
+
weatherDurationMs: clampNumber(contentProps.weatherDurationMs, DEFAULT_FIFTHBELL_CONFIG.weatherDurationMs, 1000, 120000),
|
|
215
|
+
earthquakesDurationMs: clampNumber(contentProps.earthquakesDurationMs, DEFAULT_FIFTHBELL_CONFIG.earthquakesDurationMs, 1000, 120000),
|
|
216
|
+
marketsDurationMs: clampNumber(contentProps.marketsDurationMs, DEFAULT_FIFTHBELL_CONFIG.marketsDurationMs, 1000, 120000),
|
|
217
|
+
showWorldClocks: normalizeBoolean(cornerProps.showWorldClocks, DEFAULT_FIFTHBELL_CONFIG.showWorldClocks),
|
|
218
|
+
showBellIcon: true,
|
|
219
|
+
worldClockRotateIntervalMs: clampNumber(cornerProps.worldClockRotateIntervalMs, DEFAULT_FIFTHBELL_CONFIG.worldClockRotateIntervalMs, 500, 120000),
|
|
220
|
+
worldClockTransitionMs: clampNumber(cornerProps.worldClockTransitionMs, DEFAULT_FIFTHBELL_CONFIG.worldClockTransitionMs, 0, 10000),
|
|
221
|
+
worldClockShuffle: normalizeBoolean(cornerProps.worldClockShuffle, DEFAULT_FIFTHBELL_CONFIG.worldClockShuffle),
|
|
222
|
+
worldClockWidthPx: clampNumber(cornerProps.worldClockWidthPx, DEFAULT_FIFTHBELL_CONFIG.worldClockWidthPx, 120, 600),
|
|
223
|
+
worldClockCities: normalizeWorldClockCities(cornerProps.worldClockCities),
|
|
224
|
+
audioCueEnabled: normalizeBoolean(contentProps.audioCueEnabled, DEFAULT_FIFTHBELL_CONFIG.audioCueEnabled),
|
|
225
|
+
audioCueMinute: clampNumber(contentProps.audioCueMinute, DEFAULT_FIFTHBELL_CONFIG.audioCueMinute, 0, 59),
|
|
226
|
+
audioCueSecond: clampNumber(contentProps.audioCueSecond, DEFAULT_FIFTHBELL_CONFIG.audioCueSecond, 0, 59),
|
|
227
|
+
callsignPrelaunchUntilNyc: typeof contentProps.callsignPrelaunchUntilNyc === 'string' && contentProps.callsignPrelaunchUntilNyc.trim()
|
|
228
|
+
? contentProps.callsignPrelaunchUntilNyc.trim()
|
|
229
|
+
: DEFAULT_FIFTHBELL_CONFIG.callsignPrelaunchUntilNyc,
|
|
230
|
+
callsignWindowStartSecond: clampNumber(contentProps.callsignWindowStartSecond, DEFAULT_FIFTHBELL_CONFIG.callsignWindowStartSecond, 0, 59),
|
|
231
|
+
callsignWindowEndSecond: clampNumber(contentProps.callsignWindowEndSecond, DEFAULT_FIFTHBELL_CONFIG.callsignWindowEndSecond, 0, 59),
|
|
232
|
+
marqueeMinPostsCount: parsedMarqueeMinPostsCount,
|
|
233
|
+
marqueeMinAverageRelevance: parsedMarqueeMinAverageRelevance,
|
|
234
|
+
marqueeMinMedianRelevance: parsedMarqueeMinMedianRelevance,
|
|
235
|
+
marqueePixelsPerSecond: clampNumber(marqueeProps.marqueePixelsPerSecond, DEFAULT_FIFTHBELL_CONFIG.marqueePixelsPerSecond, 10, 1000),
|
|
236
|
+
marqueeMinDurationSeconds: clampNumber(marqueeProps.marqueeMinDurationSeconds, DEFAULT_FIFTHBELL_CONFIG.marqueeMinDurationSeconds, 1, 120),
|
|
237
|
+
marqueeHeightPx: clampNumber(marqueeProps.marqueeHeightPx, DEFAULT_FIFTHBELL_CONFIG.marqueeHeightPx, 72, 200)
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
function normalizeLaunchDate(rawDate) {
|
|
241
|
+
const parsed = new Date(rawDate);
|
|
242
|
+
if (Number.isNaN(parsed.getTime())) {
|
|
243
|
+
return new Date(DEFAULT_CALLSIGN_PRELAUNCH_UNTIL_NYC);
|
|
244
|
+
}
|
|
245
|
+
return parsed;
|
|
246
|
+
}
|
|
247
|
+
export default function LiveProgram({ programId = 'fifthbell', embedded = false, sceneMetadata, activeComponents }) {
|
|
248
|
+
const encodedProgramId = encodeURIComponent(programId);
|
|
249
|
+
const [state, setState] = useState(null);
|
|
250
|
+
const [showLogoSlide, setShowLogoSlide] = useState(false);
|
|
251
|
+
const [callsignTime, setCallsignTime] = useState(new Date());
|
|
252
|
+
const audioRef = useRef(null);
|
|
253
|
+
const audioInitialized = useRef(false);
|
|
254
|
+
const [languageIndex, setLanguageIndex] = useState(0);
|
|
255
|
+
const [articles, setArticles] = useState([]);
|
|
256
|
+
const [weatherData, setWeatherData] = useState([]);
|
|
257
|
+
const [earthquakes, setEarthquakes] = useState([]);
|
|
258
|
+
const [markets, setMarkets] = useState([]);
|
|
259
|
+
const [stageEvents, setStageEvents] = useState([]);
|
|
260
|
+
const [programEvents, setProgramEvents] = useState([]);
|
|
261
|
+
const [showCurtain, setShowCurtain] = useState(false);
|
|
262
|
+
const [updatePending, setUpdatePending] = useState(false);
|
|
263
|
+
const updatePendingRef = useRef(false);
|
|
264
|
+
const [dataLoaded, setDataLoaded] = useState(false);
|
|
265
|
+
const lastFetchedItemRef = useRef(-1);
|
|
266
|
+
const controlledBySceneRenderer = sceneMetadata !== undefined;
|
|
267
|
+
const effectiveSceneMetadata = useMemo(() => {
|
|
268
|
+
if (sceneMetadata !== undefined) {
|
|
269
|
+
return toRecord(sceneMetadata);
|
|
270
|
+
}
|
|
271
|
+
return parseSceneMetadata(state?.activeScene ?? null);
|
|
272
|
+
}, [sceneMetadata, state?.activeScene]);
|
|
273
|
+
const config = useMemo(() => extractConfigFromMetadata(effectiveSceneMetadata), [effectiveSceneMetadata]);
|
|
274
|
+
const layerAvailability = useMemo(() => resolveFifthBellLayerAvailability(activeComponents), [activeComponents]);
|
|
275
|
+
const languageRotation = config.languageRotation;
|
|
276
|
+
const currentLanguage = languageRotation[languageIndex] ?? languageRotation[0] ?? 'en';
|
|
277
|
+
useEffect(() => {
|
|
278
|
+
if (languageIndex >= languageRotation.length) {
|
|
279
|
+
setLanguageIndex(0);
|
|
280
|
+
}
|
|
281
|
+
}, [languageIndex, languageRotation.length]);
|
|
282
|
+
useEffect(() => {
|
|
283
|
+
updatePendingRef.current = updatePending;
|
|
284
|
+
}, [updatePending]);
|
|
285
|
+
useEffect(() => {
|
|
286
|
+
if (controlledBySceneRenderer) {
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
fetch(apiUrl(`/program/${encodedProgramId}/state`))
|
|
290
|
+
.then((res) => res.json())
|
|
291
|
+
.then((data) => setState(data))
|
|
292
|
+
.catch((err) => console.error('Failed to fetch FifthBell program state:', err));
|
|
293
|
+
}, [controlledBySceneRenderer, encodedProgramId]);
|
|
294
|
+
const refreshAllData = useCallback(async () => {
|
|
295
|
+
const [articlesData, weatherDataResult, earthquakesData, marketsData] = await Promise.all([
|
|
296
|
+
fetchArticles(currentLanguage),
|
|
297
|
+
fetchWeatherData(),
|
|
298
|
+
fetchEarthquakes(currentLanguage),
|
|
299
|
+
fetchMarketData(),
|
|
300
|
+
fetchEvents({
|
|
301
|
+
language: currentLanguage,
|
|
302
|
+
allowedLanguages: [currentLanguage]
|
|
303
|
+
})
|
|
304
|
+
]);
|
|
305
|
+
setArticles(articlesData);
|
|
306
|
+
setWeatherData(weatherDataResult);
|
|
307
|
+
setEarthquakes(earthquakesData);
|
|
308
|
+
setMarkets(marketsData);
|
|
309
|
+
const cachedEvents = getCachedEvents();
|
|
310
|
+
if (cachedEvents) {
|
|
311
|
+
setStageEvents(cachedEvents);
|
|
312
|
+
setProgramEvents(cachedEvents);
|
|
313
|
+
}
|
|
314
|
+
setDataLoaded(true);
|
|
315
|
+
}, [currentLanguage]);
|
|
316
|
+
useEffect(() => {
|
|
317
|
+
void refreshAllData();
|
|
318
|
+
}, [refreshAllData]);
|
|
319
|
+
useSSE({
|
|
320
|
+
url: apiUrl(`/program/${encodedProgramId}/events`),
|
|
321
|
+
enabled: !controlledBySceneRenderer,
|
|
322
|
+
onMessage: (data) => {
|
|
323
|
+
if ((data.type === 'scene_change' || data.type === 'program_scenes_changed') && data.state) {
|
|
324
|
+
setState(data.state);
|
|
325
|
+
}
|
|
326
|
+
else if (data.type === 'scene_update') {
|
|
327
|
+
setState((prev) => {
|
|
328
|
+
if (!prev)
|
|
329
|
+
return prev;
|
|
330
|
+
return {
|
|
331
|
+
...prev,
|
|
332
|
+
activeScene: data.scene ?? prev.activeScene
|
|
333
|
+
};
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
else if (data.type === 'scene_cleared') {
|
|
337
|
+
setState((prev) => {
|
|
338
|
+
if (!prev)
|
|
339
|
+
return prev;
|
|
340
|
+
return {
|
|
341
|
+
...prev,
|
|
342
|
+
activeSceneId: null,
|
|
343
|
+
activeScene: null
|
|
344
|
+
};
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
useEffect(() => {
|
|
350
|
+
if (dataLoaded || config.dataLoadTimeoutMs <= 0) {
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
const timeoutId = window.setTimeout(() => {
|
|
354
|
+
window.location.reload();
|
|
355
|
+
}, config.dataLoadTimeoutMs);
|
|
356
|
+
return () => window.clearTimeout(timeoutId);
|
|
357
|
+
}, [dataLoaded, config.dataLoadTimeoutMs]);
|
|
358
|
+
const refreshEvents = useCallback(async () => {
|
|
359
|
+
await fetchEvents({
|
|
360
|
+
language: currentLanguage,
|
|
361
|
+
allowedLanguages: [currentLanguage]
|
|
362
|
+
});
|
|
363
|
+
const cachedEvents = getCachedEvents();
|
|
364
|
+
if (!cachedEvents) {
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
setStageEvents((prevStage) => {
|
|
368
|
+
const prevJson = JSON.stringify(prevStage);
|
|
369
|
+
const nextJson = JSON.stringify(cachedEvents);
|
|
370
|
+
return prevJson === nextJson ? prevStage : cachedEvents;
|
|
371
|
+
});
|
|
372
|
+
}, [currentLanguage]);
|
|
373
|
+
useEffect(() => {
|
|
374
|
+
if (stageEvents.length > 0 && programEvents.length > 0 && hasEventChanges(programEvents, stageEvents) && !showCurtain && !updatePending) {
|
|
375
|
+
setUpdatePending(true);
|
|
376
|
+
}
|
|
377
|
+
}, [programEvents, showCurtain, stageEvents, updatePending]);
|
|
378
|
+
const handleMarqueeCycleComplete = useCallback(() => {
|
|
379
|
+
if (updatePendingRef.current) {
|
|
380
|
+
setShowCurtain(true);
|
|
381
|
+
setUpdatePending(false);
|
|
382
|
+
}
|
|
383
|
+
}, []);
|
|
384
|
+
const handleCurtainComplete = useCallback(() => {
|
|
385
|
+
setProgramEvents(stageEvents);
|
|
386
|
+
setShowCurtain(false);
|
|
387
|
+
}, [stageEvents]);
|
|
388
|
+
const handlePlaylistLoop = useCallback(() => {
|
|
389
|
+
setLanguageIndex((prev) => (prev + 1) % Math.max(1, languageRotation.length));
|
|
390
|
+
}, [languageRotation.length]);
|
|
391
|
+
const articlesSegment = useMemo(() => {
|
|
392
|
+
const segment = createArticlesSegment(articles, setArticles, currentLanguage);
|
|
393
|
+
segment.durationMsPerItem = config.articlesDurationMs;
|
|
394
|
+
const originalRender = segment.render;
|
|
395
|
+
const originalOnEnter = segment.onEnter;
|
|
396
|
+
segment.onEnter = () => {
|
|
397
|
+
originalOnEnter?.();
|
|
398
|
+
lastFetchedItemRef.current = -1;
|
|
399
|
+
};
|
|
400
|
+
segment.render = (itemIndex, progress) => {
|
|
401
|
+
if (lastFetchedItemRef.current !== itemIndex) {
|
|
402
|
+
lastFetchedItemRef.current = itemIndex;
|
|
403
|
+
void refreshEvents();
|
|
404
|
+
}
|
|
405
|
+
return originalRender(itemIndex, progress);
|
|
406
|
+
};
|
|
407
|
+
return segment;
|
|
408
|
+
}, [articles, currentLanguage, refreshEvents, config.articlesDurationMs]);
|
|
409
|
+
const filteredWeatherData = useMemo(() => {
|
|
410
|
+
if (!config.weatherCities || config.weatherCities.length === 0) {
|
|
411
|
+
return weatherData;
|
|
412
|
+
}
|
|
413
|
+
const allowed = new Set(config.weatherCities.map(normalizeCityKey));
|
|
414
|
+
return weatherData
|
|
415
|
+
.map((region) => ({
|
|
416
|
+
...region,
|
|
417
|
+
cities: region.cities.filter((city) => allowed.has(normalizeCityKey(city.name)))
|
|
418
|
+
}))
|
|
419
|
+
.filter((region) => region.cities.length > 0);
|
|
420
|
+
}, [config.weatherCities, weatherData]);
|
|
421
|
+
const weatherSegment = useMemo(() => {
|
|
422
|
+
const segment = createWeatherSegment(filteredWeatherData, setWeatherData, currentLanguage);
|
|
423
|
+
segment.durationMsPerItem = config.weatherDurationMs;
|
|
424
|
+
return segment;
|
|
425
|
+
}, [filteredWeatherData, setWeatherData, currentLanguage, config.weatherDurationMs]);
|
|
426
|
+
const earthquakeSegment = useMemo(() => {
|
|
427
|
+
const segment = createEarthquakeSegment(earthquakes, setEarthquakes, currentLanguage);
|
|
428
|
+
segment.durationMsPerItem = config.earthquakesDurationMs;
|
|
429
|
+
return segment;
|
|
430
|
+
}, [earthquakes, setEarthquakes, currentLanguage, config.earthquakesDurationMs]);
|
|
431
|
+
const marketsSegment = useMemo(() => {
|
|
432
|
+
const segment = createMarketsSegment(markets, setMarkets, currentLanguage);
|
|
433
|
+
segment.durationMsPerItem = config.marketsDurationMs;
|
|
434
|
+
return segment;
|
|
435
|
+
}, [markets, setMarkets, currentLanguage, config.marketsDurationMs]);
|
|
436
|
+
const segments = useMemo(() => {
|
|
437
|
+
const nextSegments = [];
|
|
438
|
+
if (config.showArticles)
|
|
439
|
+
nextSegments.push(articlesSegment);
|
|
440
|
+
if (config.showWeather)
|
|
441
|
+
nextSegments.push(weatherSegment);
|
|
442
|
+
if (config.showEarthquakes)
|
|
443
|
+
nextSegments.push(earthquakeSegment);
|
|
444
|
+
if (config.showMarkets)
|
|
445
|
+
nextSegments.push(marketsSegment);
|
|
446
|
+
return nextSegments;
|
|
447
|
+
}, [articlesSegment, weatherSegment, earthquakeSegment, marketsSegment, config.showArticles, config.showWeather, config.showEarthquakes, config.showMarkets]);
|
|
448
|
+
const { state: playlistState, currentSegment, pause, resume, reset } = usePlaylistEngine({
|
|
449
|
+
segments,
|
|
450
|
+
defaultDurationMs: config.playlistDefaultDurationMs,
|
|
451
|
+
updateIntervalMs: config.playlistUpdateIntervalMs,
|
|
452
|
+
onPlaylistLoop: handlePlaylistLoop
|
|
453
|
+
});
|
|
454
|
+
useEffect(() => {
|
|
455
|
+
if (!audioRef.current || audioInitialized.current) {
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
audioRef.current.load();
|
|
459
|
+
audioInitialized.current = true;
|
|
460
|
+
}, []);
|
|
461
|
+
useEffect(() => {
|
|
462
|
+
if (!config.audioCueEnabled) {
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
const interval = window.setInterval(() => {
|
|
466
|
+
const now = new Date();
|
|
467
|
+
if (now.getMinutes() === config.audioCueMinute && now.getSeconds() === config.audioCueSecond && audioRef.current) {
|
|
468
|
+
audioRef.current.currentTime = 0;
|
|
469
|
+
void audioRef.current.play().catch((error) => {
|
|
470
|
+
console.log('Audio playback prevented:', error);
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
}, 1000);
|
|
474
|
+
return () => window.clearInterval(interval);
|
|
475
|
+
}, [config.audioCueEnabled, config.audioCueMinute, config.audioCueSecond]);
|
|
476
|
+
useEffect(() => {
|
|
477
|
+
const checkTime = () => {
|
|
478
|
+
const now = new Date();
|
|
479
|
+
const minutes = now.getMinutes();
|
|
480
|
+
const seconds = now.getSeconds();
|
|
481
|
+
const nycTime = new Date(now.toLocaleString('en-US', { timeZone: 'America/New_York' }));
|
|
482
|
+
const launchDateNyc = new Date(normalizeLaunchDate(config.callsignPrelaunchUntilNyc).toLocaleString('en-US', { timeZone: 'America/New_York' }));
|
|
483
|
+
const isBeforeLaunch = nycTime < launchDateNyc;
|
|
484
|
+
const withinScheduleWindow = (minutes === 59 && seconds >= config.callsignWindowStartSecond) || (minutes === 0 && seconds <= config.callsignWindowEndSecond);
|
|
485
|
+
const shouldShow = config.showCallsignTake && (isBeforeLaunch || withinScheduleWindow);
|
|
486
|
+
if (shouldShow && !showLogoSlide) {
|
|
487
|
+
reset();
|
|
488
|
+
}
|
|
489
|
+
setShowLogoSlide(shouldShow);
|
|
490
|
+
if (shouldShow) {
|
|
491
|
+
setCallsignTime(now);
|
|
492
|
+
}
|
|
493
|
+
};
|
|
494
|
+
checkTime();
|
|
495
|
+
const timer = window.setInterval(checkTime, 1000);
|
|
496
|
+
return () => window.clearInterval(timer);
|
|
497
|
+
}, [reset, config.showCallsignTake, config.callsignPrelaunchUntilNyc, config.callsignWindowStartSecond, config.callsignWindowEndSecond, showLogoSlide]);
|
|
498
|
+
useEffect(() => {
|
|
499
|
+
if (showLogoSlide) {
|
|
500
|
+
pause();
|
|
501
|
+
}
|
|
502
|
+
else if (playlistState.isPaused) {
|
|
503
|
+
resume();
|
|
504
|
+
}
|
|
505
|
+
}, [pause, resume, showLogoSlide, playlistState.isPaused]);
|
|
506
|
+
const marqueeEnabled = layerAvailability.marquee && config.showMarquee;
|
|
507
|
+
const isMarqueeVisible = useMemo(() => {
|
|
508
|
+
if (!marqueeEnabled || showLogoSlide || segments.length === 0) {
|
|
509
|
+
return false;
|
|
510
|
+
}
|
|
511
|
+
return true;
|
|
512
|
+
}, [marqueeEnabled, showLogoSlide, segments.length]);
|
|
513
|
+
const stageContainerStyle = embedded
|
|
514
|
+
? { width: '100%', height: '100%' }
|
|
515
|
+
: { width: '1920px', height: '1080px', transform: 'scale(min(1, min(100vw / 1920, 100vh / 1080)))', transformOrigin: 'center center' };
|
|
516
|
+
const stageContainerClass = embedded
|
|
517
|
+
? 'relative bg-black text-white overflow-hidden w-full h-full'
|
|
518
|
+
: 'relative bg-black text-white overflow-hidden shadow-2xl';
|
|
519
|
+
const loadingStage = (_jsx("div", { className: stageContainerClass, style: stageContainerStyle, children: layerAvailability.content ? _jsx(CallsignSlide, { currentTime: callsignTime, audioRef: audioRef }) : _jsx("div", { className: 'absolute inset-0 bg-black' }) }));
|
|
520
|
+
if (!dataLoaded) {
|
|
521
|
+
return embedded ? (_jsx("div", { className: 'w-full h-full bg-black overflow-hidden', children: loadingStage })) : (_jsx("div", { className: 'min-h-screen bg-black flex items-center justify-center overflow-hidden', children: loadingStage }));
|
|
522
|
+
}
|
|
523
|
+
const liveStage = (_jsxs("div", { className: stageContainerClass, style: stageContainerStyle, children: [layerAvailability.content ? (showLogoSlide ? (_jsx(CallsignSlide, { currentTime: callsignTime, audioRef: audioRef })) : currentSegment ? (currentSegment.render(playlistState.currentItemIndex, playlistState.progress)) : (_jsx("div", { className: 'absolute inset-0 bg-black' }))) : (_jsx("div", { className: 'absolute inset-0 bg-black' })), isMarqueeVisible && (_jsx("div", { className: 'absolute bottom-0 left-0 right-0 z-100 transition-transform duration-1000 ease-in-out translate-y-0', children: !showLogoSlide &&
|
|
524
|
+
(showCurtain ? (_jsx(MarqueeCurtain, { onComplete: handleCurtainComplete })) : (_jsx(Marquee, { events: programEvents, onCycleComplete: handleMarqueeCycleComplete, minPostsCount: config.marqueeMinPostsCount, minAverageRelevance: config.marqueeMinAverageRelevance, minMedianRelevance: config.marqueeMinMedianRelevance, pixelsPerSecond: config.marqueePixelsPerSecond, minDurationSeconds: config.marqueeMinDurationSeconds, heightPx: config.marqueeHeightPx }))) }))] }));
|
|
525
|
+
return (_jsxs("div", { className: embedded ? 'w-full h-full bg-black overflow-hidden' : 'min-h-screen bg-black flex items-center justify-center overflow-hidden', children: [liveStage, _jsx("audio", { ref: audioRef, preload: 'auto', children: _jsx("source", { src: FIFTHBELL_ASSETS.audio.pipes, type: 'audio/ogg' }) }), _jsx("style", { children: slideStyles })] }));
|
|
526
|
+
}
|