mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-18 01:02:23 +00:00
Merge main and switch Cesium and Navara in place through Vue
Preserve the camera, map source and layer selection across engine sessions. Restore the previous engine if startup fails and retain local history navigation.
This commit is contained in:
commit
b8f4d097c4
1691 files changed
+225876
-41594
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import { MUSIC_GENRES, CATEGORY_MATCHERS } from './policy.js';
|
||||
import { t } from '../../i18n/index.js';
|
||||
|
||||
export function createCategories({
|
||||
state: layerState,
|
||||
@@ -69,23 +70,29 @@ export function createCategories({
|
||||
function buildRadioCategories(stations) {
|
||||
const rows = Array.isArray(stations) ? stations : [];
|
||||
const categories = [
|
||||
{ id: 'all', label: 'All' },
|
||||
{ id: 'news', label: 'News' },
|
||||
{ id: 'talk', label: 'Talk' },
|
||||
{ id: 'weather', label: 'Weather / Emergency' },
|
||||
{ id: 'public-safety', label: 'Public Safety' },
|
||||
{ id: 'aviation-marine', label: 'Aviation / Marine' },
|
||||
{ id: 'traffic-transit', label: 'Traffic / Transit' },
|
||||
{ id: 'music', label: 'Music' },
|
||||
{ id: 'all', label: t('All', { context: 'radio tag' }) },
|
||||
{ id: 'news', label: t('News') },
|
||||
{ id: 'talk', label: t('Talk') },
|
||||
{ id: 'weather', label: t('Weather / Emergency') },
|
||||
{ id: 'public-safety', label: t('Public Safety') },
|
||||
{
|
||||
id: 'aviation-marine',
|
||||
label: t('Aviation / Marine'),
|
||||
},
|
||||
{
|
||||
id: 'traffic-transit',
|
||||
label: t('Traffic / Transit'),
|
||||
},
|
||||
{ id: 'music', label: t('Music') },
|
||||
];
|
||||
|
||||
for (const [genre, label] of MUSIC_GENRES) {
|
||||
const id = `genre:${genre}`;
|
||||
if (rows.some((station) => stationMatchesRadioCategory(station, id))) {
|
||||
categories.push({ id, label });
|
||||
categories.push({ id, label: t(label) });
|
||||
}
|
||||
}
|
||||
categories.push({ id: 'other', label: 'Other' });
|
||||
categories.push({ id: 'other', label: t('Other') });
|
||||
return categories.map((category) => ({
|
||||
...category,
|
||||
color: parts.model.radioCategoryColor(category.id),
|
||||
|
||||
@@ -1,9 +1,24 @@
|
||||
import { msg } from '../../i18n/index.js';
|
||||
import {
|
||||
RADIO_DIRECTORY_STALE_MS,
|
||||
RADIO_DIRECTORY_FUTURE_SKEW_MS,
|
||||
RADIO_TUNER_DIRECTORY_LIMIT,
|
||||
RADIO_REJECTED_STATION_COUNT_MAX,
|
||||
} from './policy.js';
|
||||
|
||||
// Directory errors stay English in layer state and stats; the layer row and
|
||||
// the Radio panel translate them when shown.
|
||||
const ERROR_REFRESH_DEGRADED = msg(
|
||||
'Directory refresh degraded; showing the previous station catalog.',
|
||||
);
|
||||
const ERROR_COVERAGE_DEGRADED = msg('Radio directory coverage is degraded.');
|
||||
const ERROR_REFRESH_FAILED = msg(
|
||||
'Directory refresh failed; showing the previous station catalog.',
|
||||
);
|
||||
const ERROR_DIRECTORY_UNAVAILABLE = msg(
|
||||
'Radio directory is temporarily unavailable.',
|
||||
);
|
||||
|
||||
export function createIngestion({
|
||||
state: layerState,
|
||||
services,
|
||||
@@ -53,17 +68,24 @@ export function createIngestion({
|
||||
typeof body.degraded !== 'boolean'
|
||||
)
|
||||
throw new Error('Radio directory freshness metadata was malformed');
|
||||
// Rows the server skipped as structurally malformed. Older envelopes
|
||||
// omit the field; a present value must be a bounded count.
|
||||
const serverRejectedStationCount =
|
||||
body.rejectedStationCount === undefined
|
||||
? 0
|
||||
: body.rejectedStationCount;
|
||||
if (
|
||||
!Number.isSafeInteger(serverRejectedStationCount) ||
|
||||
serverRejectedStationCount < 0 ||
|
||||
serverRejectedStationCount > RADIO_REJECTED_STATION_COUNT_MAX
|
||||
)
|
||||
throw new Error('Radio directory diagnostic metadata was malformed');
|
||||
const rows = body.stations;
|
||||
const acceptedRows = rows.filter(
|
||||
parts.catalogModel.isValidRadioDirectoryStation,
|
||||
);
|
||||
if (!acceptedRows.length)
|
||||
throw new Error('Radio directory returned no usable stations');
|
||||
if (acceptedRows.length !== rows.length) {
|
||||
throw new Error(
|
||||
'Radio directory response contained malformed stations',
|
||||
);
|
||||
}
|
||||
const acceptedGeneration = body.acceptedGeneration;
|
||||
if (
|
||||
acceptedGeneration !== null &&
|
||||
@@ -136,12 +158,20 @@ export function createIngestion({
|
||||
}
|
||||
if (!repeatingAcceptedGeneration) layerState._updatedAt = updatedAt;
|
||||
}
|
||||
layerState._degraded = body.degraded;
|
||||
// Combine server-side structural rejections with rows this client
|
||||
// refused. The count is diagnostic: it marks coverage degraded but does
|
||||
// not undo the generation admitted above.
|
||||
layerState._rejectedStationCount = Math.min(
|
||||
RADIO_REJECTED_STATION_COUNT_MAX,
|
||||
serverRejectedStationCount + rows.length - acceptedRows.length,
|
||||
);
|
||||
layerState._degraded =
|
||||
body.degraded || layerState._rejectedStationCount > 0;
|
||||
layerState._stale = body.stale;
|
||||
layerState._error = preservingWarmCatalog
|
||||
? 'Directory refresh degraded; showing the previous station catalog.'
|
||||
? ERROR_REFRESH_DEGRADED
|
||||
: layerState._degraded
|
||||
? 'Radio directory coverage is degraded.'
|
||||
? ERROR_COVERAGE_DEGRADED
|
||||
: null;
|
||||
} catch (error) {
|
||||
if (
|
||||
@@ -156,8 +186,8 @@ export function createIngestion({
|
||||
)
|
||||
return;
|
||||
layerState._error = layerState._stations.length
|
||||
? 'Directory refresh failed; showing the previous station catalog.'
|
||||
: 'Radio directory is temporarily unavailable.';
|
||||
? ERROR_REFRESH_FAILED
|
||||
: ERROR_DIRECTORY_UNAVAILABLE;
|
||||
layerState._stale = layerState._stations.length > 0;
|
||||
layerState._degraded = layerState._stations.length > 0;
|
||||
} finally {
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { setLocale, t, translateKnown } from '../../i18n/index.js';
|
||||
import { createIngestion } from './ingestion.js';
|
||||
|
||||
/**
|
||||
* Directory errors are stored in English in layer state (layerPanel and the
|
||||
* Radio panel translate them when shown). Every error the ingestion can set
|
||||
* must therefore have a catalog entry in each shipped language.
|
||||
*/
|
||||
|
||||
function makeIngestion({ stations = [], body = null, failure = null } = {}) {
|
||||
const layerState = {
|
||||
_enabled: true,
|
||||
_requestGeneration: 0,
|
||||
_sessionGeneration: 0,
|
||||
_abortController: null,
|
||||
_loading: false,
|
||||
_error: null,
|
||||
_stale: false,
|
||||
_degraded: false,
|
||||
_stations: stations,
|
||||
_updatedAt: null,
|
||||
_tuningActive: false,
|
||||
_cancelledTuningPresentationStation: null,
|
||||
_acceptedCatalogSnapshot: { generation: null, instance: null },
|
||||
};
|
||||
const parts = {
|
||||
presentation: { emitState() {} },
|
||||
model: { radioRequestIsCurrent: () => true },
|
||||
catalogModel: {
|
||||
isValidRadioDirectoryStation: () => true,
|
||||
freezeRadioStation: (station) => station,
|
||||
createAcceptedCatalogSnapshot: () => null,
|
||||
},
|
||||
rendering: { reconcileStations() {}, updateSelectionEntity() {} },
|
||||
};
|
||||
const source = {
|
||||
async getDirectory() {
|
||||
if (failure) throw failure;
|
||||
return body;
|
||||
},
|
||||
};
|
||||
const { methods } = createIngestion({
|
||||
state: layerState,
|
||||
services: {},
|
||||
parts,
|
||||
source,
|
||||
});
|
||||
return { layerState, methods };
|
||||
}
|
||||
|
||||
const degradedBody = () => ({
|
||||
stations: [{ id: 'a' }],
|
||||
updatedAt: new Date().toISOString(),
|
||||
stale: false,
|
||||
degraded: true,
|
||||
acceptedGeneration: 1,
|
||||
catalogInstance: 'instance-1',
|
||||
});
|
||||
|
||||
const CASES = [
|
||||
{
|
||||
name: 'directory unavailable without a catalog',
|
||||
options: { failure: new Error('network') },
|
||||
expected: 'Radio directory is temporarily unavailable.',
|
||||
},
|
||||
{
|
||||
name: 'refresh failed with a warm catalog',
|
||||
options: { stations: [{ id: 'a' }], failure: new Error('network') },
|
||||
expected: 'Directory refresh failed; showing the previous station catalog.',
|
||||
},
|
||||
{
|
||||
name: 'degraded coverage without a catalog',
|
||||
options: { body: degradedBody() },
|
||||
expected: 'Radio directory coverage is degraded.',
|
||||
},
|
||||
{
|
||||
name: 'degraded refresh with a warm catalog',
|
||||
options: { stations: [{ id: 'a' }], body: degradedBody() },
|
||||
expected:
|
||||
'Directory refresh degraded; showing the previous station catalog.',
|
||||
},
|
||||
];
|
||||
|
||||
for (const { name, options, expected } of CASES) {
|
||||
test(`radio directory error is English in state and translated on show: ${name}`, async () => {
|
||||
const { layerState, methods } = makeIngestion(options);
|
||||
await methods.update();
|
||||
assert.equal(layerState._error, expected);
|
||||
try {
|
||||
for (const locale of ['es', 'ru']) {
|
||||
setLocale(locale);
|
||||
const shown = translateKnown(layerState._error);
|
||||
assert.notEqual(shown, expected, `${locale}: ${name}`);
|
||||
assert.equal(t(layerState._error), shown);
|
||||
}
|
||||
} finally {
|
||||
setLocale('en');
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -109,6 +109,7 @@ export function createLifecycle({
|
||||
layerState._loading = false;
|
||||
layerState._stale = false;
|
||||
layerState._degraded = false;
|
||||
layerState._rejectedStationCount = 0;
|
||||
layerState._error = null;
|
||||
layerState._updatedAt = null;
|
||||
layerState._managerLifecyclePresentation = null;
|
||||
|
||||
@@ -1,8 +1,30 @@
|
||||
import {
|
||||
RADIO_CATEGORY_COLORS,
|
||||
RADIO_CLUSTER_LABELS,
|
||||
RADIO_MARKER_CATEGORY_ORDER,
|
||||
} from './policy.js';
|
||||
import { t } from '../../i18n/index.js';
|
||||
|
||||
/** Short uppercase category word on a cluster badge, in the page language. */
|
||||
function radioClusterLabel(categoryId) {
|
||||
switch (categoryId) {
|
||||
case 'news':
|
||||
return t('NEWS', { context: 'radio' });
|
||||
case 'talk':
|
||||
return t('TALK', { context: 'radio' });
|
||||
case 'weather':
|
||||
return t('WEATHER', { context: 'radio' });
|
||||
case 'public-safety':
|
||||
return t('SAFETY', { context: 'radio' });
|
||||
case 'aviation-marine':
|
||||
return t('AIR / SEA', { context: 'radio' });
|
||||
case 'traffic-transit':
|
||||
return t('TRANSIT', { context: 'radio' });
|
||||
case 'music':
|
||||
return t('MUSIC', { context: 'radio' });
|
||||
default:
|
||||
return t('OTHER', { context: 'radio' });
|
||||
}
|
||||
}
|
||||
|
||||
export function createModel({ state: layerState, services, parts, source }) {
|
||||
/** Return the shared CSS color for a canonical or detected-genre category. */
|
||||
@@ -18,7 +40,7 @@ export function createModel({ state: layerState, services, parts, source }) {
|
||||
function radioClusterBadgeText(categoryId = 'other', count = 0) {
|
||||
const normalized = String(categoryId || 'other');
|
||||
const canonical = normalized.startsWith('genre:') ? 'music' : normalized;
|
||||
const label = RADIO_CLUSTER_LABELS[canonical] || RADIO_CLUSTER_LABELS.other;
|
||||
const label = radioClusterLabel(canonical);
|
||||
const stationCount = Math.max(0, Math.floor(Number(count) || 0));
|
||||
return `${stationCount} ${label}`;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,18 @@
|
||||
import { msg } from '../../i18n/index.js';
|
||||
import { RADIO_VOICE_PLAYBACK_TIMEOUT_MS } from './policy.js';
|
||||
|
||||
// Playback errors stay English in layer state; the Radio panel shows them
|
||||
// through t().
|
||||
const AUDIO_ERROR_STREAM_FAILED = msg(
|
||||
'Broadcaster stream is unavailable or blocked by the browser.',
|
||||
);
|
||||
const AUDIO_ERROR_GESTURE_REQUIRED = msg(
|
||||
'Playback requires a direct click or tap.',
|
||||
);
|
||||
const AUDIO_ERROR_START_FAILED = msg(
|
||||
'Broadcaster stream could not be started.',
|
||||
);
|
||||
|
||||
export function createPlayback({ state: layerState, services, parts, source }) {
|
||||
function audioEventBelongsToActiveAttempt(audio) {
|
||||
const attempt = layerState._activePlaybackAttempt;
|
||||
@@ -75,8 +88,7 @@ export function createPlayback({ state: layerState, services, parts, source }) {
|
||||
const attempt = layerState._activePlaybackAttempt;
|
||||
if (tryRadioFallback(failedId, attempt?.origin, attempt?.id)) return;
|
||||
layerState._audioState = 'error';
|
||||
layerState._audioError =
|
||||
'Broadcaster stream is unavailable or blocked by the browser.';
|
||||
layerState._audioError = AUDIO_ERROR_STREAM_FAILED;
|
||||
parts.presentation.emitState();
|
||||
});
|
||||
}
|
||||
@@ -202,8 +214,8 @@ export function createPlayback({ state: layerState, services, parts, source }) {
|
||||
layerState._audioState = 'error';
|
||||
layerState._audioError =
|
||||
error?.name === 'NotAllowedError'
|
||||
? 'Playback requires a direct click or tap.'
|
||||
: 'Broadcaster stream could not be started.';
|
||||
? AUDIO_ERROR_GESTURE_REQUIRED
|
||||
: AUDIO_ERROR_START_FAILED;
|
||||
parts.presentation.emitState();
|
||||
return false;
|
||||
}
|
||||
|
||||
+34
-37
@@ -10,7 +10,7 @@ export const MARKER_LIFT_M = 2.5;
|
||||
|
||||
export const SELECTED_LIFT_M = 5;
|
||||
|
||||
export const RADIO_PICK_TOLERANCE_PX = 8;
|
||||
const RADIO_PICK_TOLERANCE_PX = 8;
|
||||
|
||||
export const RADIO_TUNER_DIRECTORY_LIMIT = 750;
|
||||
|
||||
@@ -24,6 +24,10 @@ export const RADIO_DIRECTORY_STALE_MS = 7 * 24 * 60 * 60 * 1000;
|
||||
|
||||
export const RADIO_DIRECTORY_FUTURE_SKEW_MS = 5 * 60 * 1000;
|
||||
|
||||
// Bound for the server's `rejectedStationCount` envelope field and the
|
||||
// combined client counter; matches server/providers/radio/constants.js.
|
||||
export const RADIO_REJECTED_STATION_COUNT_MAX = 10_000;
|
||||
|
||||
export const RADIO_UUID_RE =
|
||||
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
||||
|
||||
@@ -62,32 +66,36 @@ export const DEFAULT_RADIO_FILTER = 'all';
|
||||
|
||||
export const GLOBAL_RADIO_ALTITUDE_M = 2_000_000;
|
||||
|
||||
// Genre labels stay English data (the radio source, shared with the AI tools,
|
||||
// imports this module); categories.js translates them.
|
||||
const msg = (text) => text;
|
||||
|
||||
export const MUSIC_GENRES = Object.freeze([
|
||||
['alternative', 'Alternative'],
|
||||
['ambient', 'Ambient'],
|
||||
['blues', 'Blues'],
|
||||
['classical', 'Classical'],
|
||||
['country', 'Country'],
|
||||
['dance', 'Dance'],
|
||||
['electronic', 'Electronic'],
|
||||
['folk', 'Folk'],
|
||||
['funk', 'Funk'],
|
||||
['hip hop', 'Hip-Hop'],
|
||||
['house', 'House'],
|
||||
['indie', 'Indie'],
|
||||
['jazz', 'Jazz'],
|
||||
['latin', 'Latin'],
|
||||
['metal', 'Metal'],
|
||||
['oldies', 'Oldies'],
|
||||
['pop', 'Pop'],
|
||||
['punk', 'Punk'],
|
||||
['r&b', 'R&B'],
|
||||
['reggae', 'Reggae'],
|
||||
['rock', 'Rock'],
|
||||
['soul', 'Soul'],
|
||||
['techno', 'Techno'],
|
||||
['trance', 'Trance'],
|
||||
['world', 'World'],
|
||||
['alternative', msg('Alternative')],
|
||||
['ambient', msg('Ambient')],
|
||||
['blues', msg('Blues')],
|
||||
['classical', msg('Classical')],
|
||||
['country', msg('Country')],
|
||||
['dance', msg('Dance')],
|
||||
['electronic', msg('Electronic')],
|
||||
['folk', msg('Folk')],
|
||||
['funk', msg('Funk')],
|
||||
['hip hop', msg('Hip-Hop')],
|
||||
['house', msg('House')],
|
||||
['indie', msg('Indie')],
|
||||
['jazz', msg('Jazz')],
|
||||
['latin', msg('Latin')],
|
||||
['metal', msg('Metal')],
|
||||
['oldies', msg('Oldies')],
|
||||
['pop', msg('Pop')],
|
||||
['punk', msg('Punk')],
|
||||
['r&b', msg('R&B')],
|
||||
['reggae', msg('Reggae')],
|
||||
['rock', msg('Rock')],
|
||||
['soul', msg('Soul')],
|
||||
['techno', msg('Techno')],
|
||||
['trance', msg('Trance')],
|
||||
['world', msg('World')],
|
||||
]);
|
||||
|
||||
export const CATEGORY_MATCHERS = Object.freeze({
|
||||
@@ -127,17 +135,6 @@ export const RADIO_CATEGORY_COLORS = Object.freeze({
|
||||
other: '#9aa7b3',
|
||||
});
|
||||
|
||||
export const RADIO_CLUSTER_LABELS = Object.freeze({
|
||||
news: 'NEWS',
|
||||
talk: 'TALK',
|
||||
weather: 'WEATHER',
|
||||
'public-safety': 'SAFETY',
|
||||
'aviation-marine': 'AIR / SEA',
|
||||
'traffic-transit': 'TRANSIT',
|
||||
music: 'MUSIC',
|
||||
other: 'OTHER',
|
||||
});
|
||||
|
||||
export const RADIO_MARKER_CATEGORY_ORDER = Object.freeze([
|
||||
'news',
|
||||
'public-safety',
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { getLocale } from '../../i18n/index.js';
|
||||
|
||||
export function createPresentation({
|
||||
state: layerState,
|
||||
services,
|
||||
@@ -10,9 +12,26 @@ export function createPresentation({
|
||||
return layerState._acceptedCatalogSnapshot;
|
||||
}
|
||||
|
||||
/** Build the station categories, labelled in the current locale. */
|
||||
|
||||
function buildCategories() {
|
||||
layerState._categories = Object.freeze(
|
||||
parts.categories
|
||||
.buildRadioCategories(layerState._stations)
|
||||
.map((category) => Object.freeze(category)),
|
||||
);
|
||||
layerState._categoriesLocale = getLocale();
|
||||
}
|
||||
|
||||
/** Return an immutable snapshot consumed by the right-rail UI. */
|
||||
|
||||
function getRadioUIState() {
|
||||
// Labels follow a language switch the next time the state is read.
|
||||
if (
|
||||
layerState._categories.length &&
|
||||
layerState._categoriesLocale !== getLocale()
|
||||
)
|
||||
buildCategories();
|
||||
const visible = parts.queries.visibleStations();
|
||||
const selected = parts.queries.selectedStation();
|
||||
return Object.freeze({
|
||||
@@ -20,6 +39,7 @@ export function createPresentation({
|
||||
loading: layerState._loading,
|
||||
stale: layerState._stale,
|
||||
degraded: layerState._degraded,
|
||||
rejectedStationCount: layerState._rejectedStationCount,
|
||||
error: layerState._error,
|
||||
updatedAt: layerState._updatedAt,
|
||||
filter: layerState._filter,
|
||||
@@ -97,6 +117,7 @@ export function createPresentation({
|
||||
return {
|
||||
getRadioAcceptedCatalogSnapshot,
|
||||
getRadioUIState,
|
||||
buildCategories,
|
||||
emitState,
|
||||
subscribeToRadio,
|
||||
subscribeToRadioPlaybackControls,
|
||||
|
||||
@@ -206,7 +206,7 @@ export function createRendering({
|
||||
: null;
|
||||
layerState._horizonScanCount += 1;
|
||||
let visibilityChanged = false;
|
||||
for (const [id, record] of layerState._renderById) {
|
||||
for (const record of layerState._renderById.values()) {
|
||||
const matches = parts.categories.stationMatchesRadioCategory(
|
||||
record.station,
|
||||
layerState._filter,
|
||||
@@ -240,11 +240,7 @@ export function createRendering({
|
||||
layerState._stationById = new Map(
|
||||
stations.map((station) => [station.id, station]),
|
||||
);
|
||||
layerState._categories = Object.freeze(
|
||||
parts.categories
|
||||
.buildRadioCategories(stations)
|
||||
.map((category) => Object.freeze(category)),
|
||||
);
|
||||
parts.presentation.buildCategories();
|
||||
if (
|
||||
layerState._filter === DEFAULT_RADIO_FILTER &&
|
||||
!parts.categories.filterRadioStations(stations, DEFAULT_RADIO_FILTER)
|
||||
|
||||
@@ -21,6 +21,7 @@ export function createState({ services }) {
|
||||
layerState._stale = false;
|
||||
|
||||
layerState._degraded = false;
|
||||
layerState._rejectedStationCount = 0;
|
||||
|
||||
layerState._error = null;
|
||||
|
||||
@@ -33,6 +34,7 @@ export function createState({ services }) {
|
||||
layerState._stationById = new Map();
|
||||
|
||||
layerState._categories = [];
|
||||
layerState._categoriesLocale = null;
|
||||
|
||||
layerState._renderById = new Map();
|
||||
|
||||
|
||||
Reference in new issue
Block a user