mirror of
https://github.com/p-stream/p-stream.git
synced 2026-03-11 17:55:33 +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() {
|
||||
const canAirplay = usePlayerStore((s) => s.interface.canAirplay);
|
||||
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)
|
||||
// or when the webkit event has confirmed availability
|
||||
if (!canAirplay && !isSafari) return null;
|
||||
if ((!canAirplay && !isSafari) || !isCastable) return null;
|
||||
|
||||
return (
|
||||
<VideoPlayerButton
|
||||
|
|
|
|||
|
|
@ -23,8 +23,24 @@ export interface ChromecastProps {
|
|||
export function Chromecast({ className }: ChromecastProps) {
|
||||
const [castHidden, setCastHidden] = useState(false);
|
||||
const isCasting = usePlayerStore((s) => s.interface.isCasting);
|
||||
const source = usePlayerStore((s) => s.source);
|
||||
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(() => {
|
||||
const w = window as unknown as { cast?: typeof cast };
|
||||
const castFramework = w.cast?.framework;
|
||||
|
|
@ -72,7 +88,7 @@ export function Chromecast({ className }: ChromecastProps) {
|
|||
"google-cast-button",
|
||||
"cast-button-container",
|
||||
isCasting ? "casting" : "",
|
||||
castHidden ? "hidden" : "",
|
||||
castHidden || !isCastable ? "hidden" : "",
|
||||
].join(" ")}
|
||||
>
|
||||
<div ref={launcherRef} />
|
||||
|
|
|
|||
|
|
@ -834,6 +834,8 @@ export function makeVideoElementDisplayInterface(): DisplayInterface {
|
|||
if (source?.type === "hls") {
|
||||
if (hls) {
|
||||
hls.loadSource(proxiedUrl);
|
||||
} else {
|
||||
videoPlayer.src = proxiedUrl;
|
||||
}
|
||||
} else {
|
||||
videoPlayer.src = proxiedUrl;
|
||||
|
|
|
|||
Loading…
Reference in a new issue