mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
Releasing the tuning dial always started the chosen station, plus tuning static, even when nothing was playing. It now follows the Previous/Next rule: the release plays only if a stream was loading, buffering or playing when the drag began; otherwise it just selects the station. The privacy note no longer lists finishing tuning as a way to connect and now names voice instead, in all locales. Docs, changelog and comments are tightened to match.
100 lines
2.6 KiB
JavaScript
100 lines
2.6 KiB
JavaScript
import { radioLayer } from '../data/radio.js';
|
|
|
|
export function radioStationRow(overrides = {}) {
|
|
return {
|
|
id: '00000000-0000-4000-8000-000000000001',
|
|
name: 'Station',
|
|
lat: 30,
|
|
lon: -97,
|
|
streamUrl: 'https://radio.example.com/station.mp3',
|
|
homepage: null,
|
|
tags: ['news'],
|
|
languages: ['English'],
|
|
state: 'Texas',
|
|
country: 'United States',
|
|
countryCode: 'US',
|
|
metadataTrust: 'untrusted-community',
|
|
codec: 'MP3',
|
|
bitrate: 128,
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Run `body` against an enabled `radioLayer` that serves `stations`.
|
|
* Streams listed in `failingUrls` (mutable) reject play(); `body` receives the
|
|
* played URLs and the catalog, whose rows and generation the next update() serves.
|
|
*/
|
|
export async function withRadioLayer({ stations, failingUrls = [] }, body) {
|
|
const originalFetch = globalThis.fetch;
|
|
const originalAudio = globalThis.Audio;
|
|
const playUrls = [];
|
|
const catalog = { rows: stations, generation: 1 };
|
|
globalThis.Audio = class FakeAudio {
|
|
constructor() {
|
|
this.volume = 0.8;
|
|
this.src = '';
|
|
}
|
|
|
|
addEventListener() {}
|
|
pause() {}
|
|
play() {
|
|
playUrls.push(this.src);
|
|
if (failingUrls.includes(this.src)) {
|
|
return Promise.reject(
|
|
new DOMException('unavailable', 'NotSupportedError'),
|
|
);
|
|
}
|
|
return Promise.resolve();
|
|
}
|
|
removeAttribute() {
|
|
this.src = '';
|
|
}
|
|
load() {}
|
|
};
|
|
globalThis.fetch = async (url) =>
|
|
String(url).startsWith('/api/radio/click/')
|
|
? { ok: true }
|
|
: new Response(
|
|
JSON.stringify({
|
|
stations: catalog.rows,
|
|
stale: false,
|
|
degraded: false,
|
|
acceptedGeneration: catalog.generation,
|
|
catalogInstance: 'qa-instance-a',
|
|
updatedAt: new Date().toISOString(),
|
|
}),
|
|
{ status: 200, headers: { 'Content-Type': 'application/json' } },
|
|
);
|
|
const viewer = {
|
|
camera: { positionWC: { x: 7_000_000, y: 0, z: 0 } },
|
|
scene: {
|
|
canvas: {
|
|
disableRootEvents: true,
|
|
onwheel: null,
|
|
addEventListener() {},
|
|
removeEventListener() {},
|
|
},
|
|
},
|
|
dataSources: { add() {}, remove() {} },
|
|
entities: {
|
|
add(entity) {
|
|
return entity;
|
|
},
|
|
remove() {},
|
|
},
|
|
};
|
|
radioLayer.destroy();
|
|
try {
|
|
radioLayer.init(viewer);
|
|
radioLayer.enable();
|
|
await radioLayer.update();
|
|
await body({ playUrls, catalog });
|
|
} finally {
|
|
globalThis.fetch = originalFetch;
|
|
if (originalAudio === undefined) delete globalThis.Audio;
|
|
else globalThis.Audio = originalAudio;
|
|
radioLayer.destroy();
|
|
}
|
|
}
|