fix(web): only pick SoundCloud tracks with app playback enabled for the Frutiger Aero soundtrack

This commit is contained in:
Martin Dvořák 2026-10-16 00:45:15 +02:00
commit 8f8a54cf18
5 changed files with 44 additions and 21 deletions

View file

@ -186,10 +186,15 @@ Themes: `web` = default frosted-glass website (sidebar + content, light/dark),
random track from the *Frutiger Aero* SoundCloud playlist (a hidden SoundCloud random track from the *Frutiger Aero* SoundCloud playlist (a hidden SoundCloud
iframe driven through their widget API: it picks a random index from `getSounds` iframe driven through their widget API: it picks a random index from `getSounds`
and re-randomises on every `PLAY` event so the set never plays in order; the chip and re-randomises on every `PLAY` event so the set never plays in order; the chip
label is synced from `getCurrentSound`, not from what we asked for). That widget label is synced from `getCurrentSound`, not from what we asked for). Two
API drives the iframe over `postMessage`, so every call is gated behind an SoundCloud quirks are handled there: entries from `getSounds` can arrive
`alive()` check: React detaches the iframe *before* the effect cleanup runs, and not-yet-hydrated (no `title`/`user`) and are still perfectly playable, so the
an unguarded `pause()` there throws `Cannot read properties of null (reading random pick filters on `playable !== false` *only* — `playable: false` means the
uploader left "Enable app playback" off, and SoundCloud refuses to stream those
to a third-party app at all (picking one just leaves the player silent); and the
widget API drives the iframe over `postMessage`, so every call is gated behind
an `alive()` check — React detaches the iframe *before* the effect cleanup runs,
and an unguarded `pause()` there throws `Cannot read properties of null (reading
'postMessage')`, which unmounts the whole page. The two remaining feature panels (`.web-split`) stretch 'postMessage')`, which unmounts the whole page. The two remaining feature panels (`.web-split`) stretch
to equal height and share a fixed `16 / 10` `.fw` window (the `FeatureWindow` to equal height and share a fixed `16 / 10` `.fw` window (the `FeatureWindow`
component) — decorative, **asset-free CSS mock-ups** rather than screenshots: component) — decorative, **asset-free CSS mock-ups** rather than screenshots:

View file

@ -1,7 +1,7 @@
# Graph Report - dvorakmortonxd.dev (2026-10-16) # Graph Report - dvorakmortonxd.dev (2026-10-16)
## Corpus Check ## Corpus Check
- 44 files · ~320,357 words - 44 files · ~320,564 words
- Verdict: corpus is large enough that graph structure adds value. - Verdict: corpus is large enough that graph structure adds value.
- Unclassified: 19 file(s) not represented in the graph (top: (none) 6, .ttf 3, .css 3) - Unclassified: 19 file(s) not represented in the graph (top: (none) 6, .ttf 3, .css 3)
@ -11,7 +11,7 @@
- Token cost: 0 input · 0 output - Token cost: 0 input · 0 output
## Graph Freshness ## Graph Freshness
- Built from commit: `be33317d` - Built from commit: `0fb84583`
- Run `git rev-parse HEAD` and compare to check if the graph is stale. - Run `git rev-parse HEAD` and compare to check if the graph is stale.
- Run `graphify update .` after code changes (no API cost). - Run `graphify update .` after code changes (no API cost).

File diff suppressed because one or more lines are too long

View file

@ -366,9 +366,9 @@
"semantic_hash": "6f69e16823f10d9c7af1625eff2b32e8" "semantic_hash": "6f69e16823f10d9c7af1625eff2b32e8"
}, },
"AGENTS.md": { "AGENTS.md": {
"mtime": 1792103035.6232371, "mtime": 1792104286.5544052,
"seen": 1792103044.7911508, "seen": 1792104298.8915398,
"ast_hash": "546487f136313be6c94c604a4ff8866d", "ast_hash": "9aeb2ca2591e1b5a33a5082e7c728cfe",
"semantic_hash": "" "semantic_hash": ""
}, },
"public/freezmo_aero.png": { "public/freezmo_aero.png": {
@ -384,9 +384,9 @@
"semantic_hash": "" "semantic_hash": ""
}, },
"src/app/components/AeroMusic.tsx": { "src/app/components/AeroMusic.tsx": {
"mtime": 1792102961.1760592, "mtime": 1792104240.1346495,
"seen": 1792103044.7910783, "seen": 1792104298.8914325,
"ast_hash": "8587acdbce460ee950777e38a552c311", "ast_hash": "9d82d03e20d0a618d1c7bb737e670abf",
"semantic_hash": "" "semantic_hash": ""
} }
} }

View file

@ -20,6 +20,9 @@ const PICK_GUARD_MS = 3000;
type SoundCloudSound = { type SoundCloudSound = {
title?: string; title?: string;
user?: { username?: string }; user?: { username?: string };
/* False when the uploader left "Enable app playback" off — SoundCloud then
refuses to stream the track to third-party apps entirely. */
playable?: boolean;
}; };
type SoundCloudWidget = { type SoundCloudWidget = {
@ -115,12 +118,12 @@ export default function AeroMusic() {
widgetRef.current = widget; widgetRef.current = widget;
/* The chip mirrors what the player is actually on, so a skip that gets /* The chip mirrors what the player is actually on, so a skip that gets
ignored can't leave it lying. Partial reads are ignored rather than ignored can't leave it lying. The payload can still be a stub with no
blanking the label. */ title yet, which is ignored rather than blanking the label. */
const syncTrack = () => { const syncTrack = () => {
if (!alive()) return; if (!alive()) return;
widget?.getCurrentSound((sound) => { widget?.getCurrentSound((sound) => {
if (!alive() || !sound || !sound.title) return; if (!alive() || !sound?.title) return;
setTrack({ title: sound.title, artist: sound.user?.username || "SoundCloud" }); setTrack({ title: sound.title, artist: sound.user?.username || "SoundCloud" });
}); });
}; };
@ -129,16 +132,31 @@ export default function AeroMusic() {
if (!alive()) return; if (!alive()) return;
widget?.getSounds((sounds) => { widget?.getSounds((sounds) => {
if (!alive() || !sounds || sounds.length === 0) return; if (!alive() || !sounds || sounds.length === 0) return;
let index = Math.floor(Math.random() * sounds.length); /* A few tracks in any set are `playable: false` (the uploader left
"Enable app playback" off) and SoundCloud refuses to stream those
to third-party apps — picking one just leaves the player stuck on
silence. Skip those, but keep the original set index because
that's what `skip()` takes. Don't filter on the track metadata:
entries can arrive not-yet-hydrated (no title/user) and are still
perfectly playable. */
const all = sounds.map((sound, index) => ({ sound, index }));
const playable = all.filter(({ sound }) => sound.playable !== false);
const pool = playable.length > 0 ? playable : all;
let choice = Math.floor(Math.random() * pool.length);
/* Don't just replay whatever is already on. */ /* Don't just replay whatever is already on. */
if (sounds.length > 1 && index === chosen) index = (index + 1) % sounds.length; if (pool.length > 1 && pool[choice].index === chosen) {
choice = (choice + 1) % pool.length;
}
const { sound, index } = pool[choice];
chosen = index; chosen = index;
pickedAt = Date.now(); pickedAt = Date.now();
widget?.skip(index); widget?.skip(index);
widget?.play(); widget?.play();
/* Show it straight away, then settle on the truth once the player /* Show it straight away when it is already named, then settle on the
has caught up. */ truth once the player has caught up. */
setTrack(toTrack(sounds[index])); if (sound.title) setTrack(toTrack(sound));
window.clearTimeout(syncTimer); window.clearTimeout(syncTimer);
syncTimer = window.setTimeout(syncTrack, 900); syncTimer = window.setTimeout(syncTrack, 900);
}); });