update chromecast to use new proxy

also it was using the wrong proxy before 💀
This commit is contained in:
Pas 2025-10-24 19:29:58 -06:00
parent e658d13ec5
commit af2c2b8acf
2 changed files with 27 additions and 25 deletions

View file

@ -9,7 +9,11 @@ import {
DisplayInterfaceEvents,
DisplayMeta,
} from "@/components/player/display/displayInterface";
import { conf } from "@/setup/config";
import {
createM3U8ProxyUrl,
createMP4ProxyUrl,
isUrlAlreadyProxied,
} from "@/components/player/utils/proxy";
import { LoadableSource } from "@/stores/player/utils/qualities";
import { processCdnLink } from "@/utils/cdn";
import { canFullscreen, canFullscreenAnyElement } from "@/utils/detectFeatures";
@ -113,32 +117,25 @@ export function makeChromecastDisplayInterface(
let contentUrl = processCdnLink(source.url);
// When casting HLS, use an enabled M3U8 proxy so the Chromecast device can fetch the manifest
// Only proxy streams if they need it:
// 1. Not already proxied AND
// 2. Has headers (either preferredHeaders or headers)
const allHeaders = {
...source.preferredHeaders,
...source.headers,
};
const hasHeaders = Object.keys(allHeaders).length > 0;
// Handle HLS streams
if (source.type === "hls") {
try {
const all = conf().M3U8_PROXY_URLS;
let enabledMap: Record<string, boolean> = {};
const enabledRaw = localStorage.getItem("m3u8-proxy-enabled");
if (enabledRaw) {
try {
enabledMap = JSON.parse(enabledRaw) as Record<string, boolean>;
} catch {
enabledMap = {};
}
}
const enabled = all.filter(
(_url, idx) => enabledMap[idx.toString()] !== false,
);
const list = enabled.length > 0 ? enabled : all;
if (list.length > 0) {
const base = list[Math.floor(Math.random() * list.length)];
const trimmed = base.endsWith("/") ? base.slice(0, -1) : base;
contentUrl = `${trimmed}/?destination=${encodeURIComponent(contentUrl)}`;
}
} catch {
// If anything goes wrong, fall back to direct URL
if (!isUrlAlreadyProxied(source.url) && hasHeaders) {
contentUrl = createM3U8ProxyUrl(source.url, allHeaders);
}
}
// Handle MP4 streams with headers
else if (source.type === "mp4" && hasHeaders) {
contentUrl = createMP4ProxyUrl(source.url, source.headers || {});
}
const mediaInfo = new chrome.cast.media.MediaInfo(contentUrl, type);
mediaInfo.streamType = chrome.cast.media.StreamType.BUFFERED;

View file

@ -47,11 +47,16 @@ export function createMP4ProxyUrl(
* @returns True if the URL is already proxied, false otherwise
*/
export function isUrlAlreadyProxied(url: string): boolean {
// Check if URL contains the m3u8-proxy pattern
// Check if URL contains the m3u8-proxy pattern (Airplay format)
if (url.includes("/m3u8-proxy?url=")) {
return true;
}
// Check if URL contains the destination pattern (Chromecast format)
if (url.includes("/?destination=")) {
return true;
}
// Also check if URL starts with any of the configured proxy URLs
const proxyUrls = getM3U8ProxyUrls();
return proxyUrls.some((proxyUrl) => url.startsWith(proxyUrl));