mirror of
https://github.com/p-stream/p-stream.git
synced 2026-04-21 06:52:18 +00:00
update chromecasting logic
This commit is contained in:
parent
9b02bf794a
commit
51e30c978a
3 changed files with 36 additions and 2 deletions
|
|
@ -6,10 +6,26 @@ import { isSafari } from "@/utils/detectFeatures";
|
||||||
export function Airplay() {
|
export function Airplay() {
|
||||||
const canAirplay = usePlayerStore((s) => s.interface.canAirplay);
|
const canAirplay = usePlayerStore((s) => s.interface.canAirplay);
|
||||||
const display = usePlayerStore((s) => s.display);
|
const display = usePlayerStore((s) => s.display);
|
||||||
|
const source = usePlayerStore((s) => s.source);
|
||||||
|
|
||||||
|
// Check if source is supported for casting
|
||||||
|
// HLS is always supported (proxied if needed)
|
||||||
|
// MP4/File is only supported if it doesn't need headers (no proxy available)
|
||||||
|
const isCastable = (() => {
|
||||||
|
if (!source) return false;
|
||||||
|
if (source.type === "hls") return true;
|
||||||
|
if (source.type === "file") {
|
||||||
|
const hasHeaders =
|
||||||
|
Object.keys(source.headers || {}).length > 0 ||
|
||||||
|
Object.keys(source.preferredHeaders || {}).length > 0;
|
||||||
|
return !hasHeaders;
|
||||||
|
}
|
||||||
|
return true; // Unknown types assumed castable
|
||||||
|
})();
|
||||||
|
|
||||||
// Show Airplay button on Safari browsers (which support AirPlay natively)
|
// Show Airplay button on Safari browsers (which support AirPlay natively)
|
||||||
// or when the webkit event has confirmed availability
|
// or when the webkit event has confirmed availability
|
||||||
if (!canAirplay && !isSafari) return null;
|
if ((!canAirplay && !isSafari) || !isCastable) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<VideoPlayerButton
|
<VideoPlayerButton
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,24 @@ export interface ChromecastProps {
|
||||||
export function Chromecast({ className }: ChromecastProps) {
|
export function Chromecast({ className }: ChromecastProps) {
|
||||||
const [castHidden, setCastHidden] = useState(false);
|
const [castHidden, setCastHidden] = useState(false);
|
||||||
const isCasting = usePlayerStore((s) => s.interface.isCasting);
|
const isCasting = usePlayerStore((s) => s.interface.isCasting);
|
||||||
|
const source = usePlayerStore((s) => s.source);
|
||||||
const launcherRef = useRef<HTMLDivElement>(null);
|
const launcherRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
|
// Check if source is supported for casting
|
||||||
|
// HLS is always supported (proxied if needed)
|
||||||
|
// MP4/File is only supported if it doesn't need headers (no proxy available)
|
||||||
|
const isCastable = (() => {
|
||||||
|
if (!source) return false;
|
||||||
|
if (source.type === "hls") return true;
|
||||||
|
if (source.type === "file") {
|
||||||
|
const hasHeaders =
|
||||||
|
Object.keys(source.headers || {}).length > 0 ||
|
||||||
|
Object.keys(source.preferredHeaders || {}).length > 0;
|
||||||
|
return !hasHeaders;
|
||||||
|
}
|
||||||
|
return true; // Unknown types assumed castable
|
||||||
|
})();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const w = window as unknown as { cast?: typeof cast };
|
const w = window as unknown as { cast?: typeof cast };
|
||||||
const castFramework = w.cast?.framework;
|
const castFramework = w.cast?.framework;
|
||||||
|
|
@ -72,7 +88,7 @@ export function Chromecast({ className }: ChromecastProps) {
|
||||||
"google-cast-button",
|
"google-cast-button",
|
||||||
"cast-button-container",
|
"cast-button-container",
|
||||||
isCasting ? "casting" : "",
|
isCasting ? "casting" : "",
|
||||||
castHidden ? "hidden" : "",
|
castHidden || !isCastable ? "hidden" : "",
|
||||||
].join(" ")}
|
].join(" ")}
|
||||||
>
|
>
|
||||||
<div ref={launcherRef} />
|
<div ref={launcherRef} />
|
||||||
|
|
|
||||||
|
|
@ -834,6 +834,8 @@ export function makeVideoElementDisplayInterface(): DisplayInterface {
|
||||||
if (source?.type === "hls") {
|
if (source?.type === "hls") {
|
||||||
if (hls) {
|
if (hls) {
|
||||||
hls.loadSource(proxiedUrl);
|
hls.loadSource(proxiedUrl);
|
||||||
|
} else {
|
||||||
|
videoPlayer.src = proxiedUrl;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
videoPlayer.src = proxiedUrl;
|
videoPlayer.src = proxiedUrl;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue