import { Feather } from "@expo/vector-icons"; import { BlurView } from "expo-blur"; import React, { useCallback, useEffect } from "react"; import { Platform, TouchableOpacity, ViewProps } from "react-native"; import GoogleCast, { CastButton, CastContext, useCastDevice, useDevices, useMediaStatus, useRemoteMediaClient, } from "react-native-google-cast"; import { RoundButton } from "./RoundButton"; interface Props extends ViewProps { width?: number; height?: number; background?: "blur" | "transparent"; } export const Chromecast: React.FC = ({ width = 48, height = 48, background = "transparent", ...props }) => { const client = useRemoteMediaClient(); const castDevice = useCastDevice(); const devices = useDevices(); const sessionManager = GoogleCast.getSessionManager(); const discoveryManager = GoogleCast.getDiscoveryManager(); const mediaStatus = useMediaStatus(); useEffect(() => { (async () => { if (!discoveryManager) { console.warn("DiscoveryManager is not initialized"); return; } await discoveryManager.startDiscovery(); })(); }, [client, devices, castDevice, sessionManager, discoveryManager]); // Android requires the cast button to be present for startDiscovery to work const AndroidCastButton = useCallback( () => Platform.OS === "android" ? ( ) : ( <> ), [Platform.OS] ); if (background === "transparent") return ( { if (mediaStatus?.currentItemId) CastContext.showExpandedControls(); else CastContext.showCastDialog(); }} {...props} > ); return ( { if (mediaStatus?.currentItemId) CastContext.showExpandedControls(); else CastContext.showCastDialog(); }} {...props} > ); };