Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions apps/radio/src/lib/audio/manager/audio-manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,34 @@ afterEach(() => {
});

describe("AudioManager", () => {
// RADIO-22: single-mode playSound must go through toPlaybackInput so a
// persisted RadioJar mount (including query variants) never reaches media.
test("single-mode playSound remounts a persisted Radio Alhara RadioJar URL", async () => {
const harness = createMediaPlaybackHarness();
try {
const { manager, browser, effects } = harness;
effects.connectGraph = mock(async () => true);
const soundId = manager.createSound(
{
name: "Radio Alhara",
streamUrl: "https://n03.radiojar.com/78cxy6wkxtzuv?source=radio",
},
"single:alhara",
"native",
"station"
);
const starting = manager.playSound(soundId);
await flushMicrotasks();
expect(browser.audio().loadSources).toEqual([
"https://stream.radioalhara.net/ra",
]);
browser.audio().emit("canplay");
await starting;
} finally {
harness.restore();
}
});

test.each([
[Number.POSITIVE_INFINITY, 1],
[120, 1],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,60 @@ describe("MediaElementPlaybackSource native playback", () => {
}
);

// RADIO-22: Chrome maps the retired RadioJar 404 to MEDIA_ERR_SRC_NOT_SUPPORTED.
// Single-mode loads through toPlaybackInput; the override must keep that mount
// off the media element so readiness never rejects with PLAY_ERROR.
test.each([
"https://n03.radiojar.com/78cxy6wkxtzuv",
"https://n03.radiojar.com/78cxy6wkxtzuv?source=radio",
])(
"single-mode Radio Alhara loads never attach the retired RadioJar mount (%s)",
async (retiredMount) => {
const browser = installBrowser();
const onError = mock(() => undefined);
const source = new MediaElementPlaybackSource(null, "native", {
onError,
});
const currentMount = "https://stream.radioalhara.net/ra";
try {
const audio = browser.audio();
audio.load = () => {
if (audio.src.includes("n03.radiojar.com/78cxy6wkxtzuv")) {
queueMicrotask(() => {
audio.error = {
code: MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED,
} as MediaError;
audio.emit("error");
});
return;
}
if (audio.src !== "") {
queueMicrotask(() => {
audio.error = null;
audio.emit("canplay");
});
}
};
const input = toPlaybackInput({
name: "Radio Alhara",
streamUrl: retiredMount,
});
await source.load(input);
expect(input).toMatchObject({
format: "progressive",
src: currentMount,
});
expect(audio.loadSources).toEqual([currentMount]);
expect(audio.src).toBe(currentMount);
expect(onError).not.toHaveBeenCalled();
expect(source.status).not.toBe("error");
} finally {
source.cleanup();
browser.restore();
}
}
);

test("a failed start stays stopped when late media events arrive", async () => {
const browser = installBrowser();
const onPlaying = mock(() => undefined);
Expand Down
52 changes: 44 additions & 8 deletions apps/radio/src/lib/audio/playback/playback-input.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,58 @@ describe("toPlaybackInput", () => {
});

test("upgrades persisted Radio Alhara URLs to its first-party stream", () => {
const currentMount = "https://stream.radioalhara.net/ra";
for (const streamUrl of [
"https://n03.radiojar.com/78cxy6wkxtzuv",
"https://n03.radiojar.com/78cxy6wkxtzuv?source=radio",
"https://N03.RadioJar.com/78cxy6wkxtzuv#legacy",
"https://n03.radiojar.com:443/78cxy6wkxtzuv/",
]) {
expect(
toPlaybackInput({
name: "Radio Alhara",
streamUrl,
})
).toMatchObject({
format: "progressive",
live: true,
src: currentMount,
});
}
expect(
toPlaybackInput({
name: "Lookalike",
streamUrl: "https://example.com/78cxy6wkxtzuv",
})
).toMatchObject({ src: "https://example.com/78cxy6wkxtzuv" });
expect(
toPlaybackInput({
name: "Radio Alhara",
streamUrl: "https://n03.radiojar.com/78cxy6wkxtzuv",
name: "Embedded path",
streamUrl:
"https://evil.example/https://n03.radiojar.com/78cxy6wkxtzuv",
})
).toMatchObject({
format: "progressive",
live: true,
src: "https://stream.radioalhara.net/ra",
src: "https://evil.example/https://n03.radiojar.com/78cxy6wkxtzuv",
});
expect(
toPlaybackInput({
name: "Lookalike",
streamUrl: "https://example.com/78cxy6wkxtzuv",
name: "Path sibling",
streamUrl: "https://n03.radiojar.com/78cxy6wkxtzuv/extra",
})
).toMatchObject({ src: "https://example.com/78cxy6wkxtzuv" });
).toMatchObject({
src: "https://n03.radiojar.com/78cxy6wkxtzuv/extra",
});
});

test.each([
"https://n03.radiojar.com:8443/78cxy6wkxtzuv",
"http://n03.radiojar.com:8080/78cxy6wkxtzuv?source=radio",
"https://radio.syg.ma:8443/audio.ogg",
"https://stream-relay-geo.ntslive.net:8443/stream",
])("preserves a distinct stream origin (%s)", (streamUrl) => {
expect(toPlaybackInput({ name: "Other origin", streamUrl })).toMatchObject({
src: streamUrl,
});
});

test("upgrades persisted NTS relay URLs to Web Audio compatible sources", () => {
Expand Down
33 changes: 32 additions & 1 deletion apps/radio/src/lib/audio/playback/playback-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,44 @@ const STREAM_URL_OVERRIDES: Readonly<Record<string, string>> = {
"https://streams.radiomast.io/nts2",
};

/** Preserve the origin; query/hash and trailing slash must not bypass. */
function streamOverrideIdentity(url: string): string | null {
try {
const parsed = new URL(url);
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
return null;
}
const path =
parsed.pathname.length > 1 && parsed.pathname.endsWith("/")
? parsed.pathname.slice(0, -1)
: parsed.pathname;
return `${parsed.origin}${path}`;
} catch {
return null;
}
}

const STREAM_URL_OVERRIDE_BY_IDENTITY = new Map<string, string>(
Object.entries(STREAM_URL_OVERRIDES).flatMap(([from, to]) => {
const identity = streamOverrideIdentity(from);
return identity ? [[identity, to] as const] : [];
})
);

function resolveStreamUrlOverride(streamUrl: string): string | undefined {
return (
STREAM_URL_OVERRIDES[streamUrl] ??
STREAM_URL_OVERRIDE_BY_IDENTITY.get(streamOverrideIdentity(streamUrl) ?? "")
);
}

export function toPlaybackInput(
radio: Radio,
sourceKind?: RadioSourceKind
): PlaybackInput {
const src = isRadioBlackoutStreamUrl(radio.streamUrl)
? RADIO_BLACKOUT_STREAM_URL
: (STREAM_URL_OVERRIDES[radio.streamUrl] ?? radio.streamUrl);
: (resolveStreamUrlOverride(radio.streamUrl) ?? radio.streamUrl);
const format =
radio.streamFormat ??
(radio.platformMetadata?.platform === "radio-browser" &&
Expand Down
2 changes: 1 addition & 1 deletion apps/radio/src/lib/node-playback.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1562,7 +1562,7 @@ describe("Node Playback starts", () => {
expect(getPlaybackChannelRuntime(channelOf("bad")).error).toMatchObject({
code: "PLAY_ERROR",
message:
"The stream could not be reached. Check the station URL and try again.",
"Playback could not start. Check the station stream and try again.",
});
expect(harness.context.reportError).toHaveBeenCalledTimes(1);
expect(harness.context.reportError).toHaveBeenCalledWith(
Expand Down
20 changes: 20 additions & 0 deletions apps/radio/src/lib/playback-action-errors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ test("support limits preserve guidance; ordinary media failures still reach Sent
"The operation is not supported.",
"NotSupportedError"
);
// RADIO-22 symptom: MEDIA_ERR_SRC_NOT_SUPPORTED mapped by mediaElementError.
// Keep reporting unexpected stream failures; do not silence the diagnostic.
const unsupportedStream = new Error("Audio stream format is not supported");
try {
expect(toRuntimeAudioError(support).message).toBe(support.safeMessage);
capturePlaybackActionError(
Expand All @@ -35,6 +38,23 @@ test("support limits preserve guidance; ordinary media failures still reach Sent
);
expect(capture).toHaveBeenCalledTimes(1);
expect(capture.mock.calls[0]?.[0]).toBe(failure);
const unsupportedAction = createPlaybackActionError({
cause: unsupportedStream,
mode: "single",
});
expect(unsupportedAction.userMessage).toBe(
"This audio format is not supported. Check the station stream or try another source."
);
const unreachableAction = createPlaybackActionError({
cause: new Error("Audio stream failed to load"),
mode: "single",
});
expect(unreachableAction.userMessage).toBe(
"The stream could not be reached. Check the station URL and try again."
);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
capturePlaybackActionError(unsupportedAction);
expect(capture).toHaveBeenCalledTimes(2);
expect(capture.mock.calls[1]?.[0]).toBe(unsupportedStream);
} finally {
capture.mockRestore();
enabled.mockRestore();
Expand Down
17 changes: 16 additions & 1 deletion apps/radio/src/lib/playback-action-errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,22 @@ function getFriendlyPlaybackErrorMessage(
) {
return "Playback source is no longer available. Reload the station and try again.";
}
if (messageIncludesAny(rawMessage, ["network", "fetch", "stream"])) {
// mediaElementError phrases: format/decode before reachability. Do not match
// bare "stream" — that mislabels format failures as URL problems.
if (messageIncludesAny(rawMessage, ["format is not supported"])) {
return "This audio format is not supported. Check the station stream or try another source.";
}
if (messageIncludesAny(rawMessage, ["could not be decoded"])) {
return "The stream could not be decoded. Try another station or format.";
}
if (
messageIncludesAny(rawMessage, [
"network",
"fetch",
"failed to load",
"timed out",
])
) {
return "The stream could not be reached. Check the station URL and try again.";
}

Expand Down
Loading