diff --git a/frontend/package.json b/frontend/package.json index 1ab411b..b5da2d4 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -12,6 +12,7 @@ "postcss": "^8.4.12", "react": "^17.0.2", "react-dom": "^17.0.2", + "react-helmet": "^6.1.0", "react-icons": "^4.3.1", "react-router-dom": "6", "react-scripts": "5.0.0", @@ -24,7 +25,8 @@ "@types/jest": "^27.0.1", "@types/node": "^16.7.13", "@types/react": "^17.0.20", - "@types/react-dom": "^17.0.9" + "@types/react-dom": "^17.0.9", + "@types/react-helmet": "^6.1.5" }, "scripts": { "start": "react-scripts start", diff --git a/frontend/public/index.html b/frontend/public/index.html index 08121a0..d0d2da6 100644 --- a/frontend/public/index.html +++ b/frontend/public/index.html @@ -24,7 +24,7 @@ - + \ No newline at end of file diff --git a/frontend/src/components/header.component.tsx b/frontend/src/components/header.component.tsx index 12e4887..6fbc9c8 100644 --- a/frontend/src/components/header.component.tsx +++ b/frontend/src/components/header.component.tsx @@ -37,7 +37,6 @@ const Header = () => { return (
- {/* */} - {/* */}
@@ -60,7 +58,6 @@ const Header = () => {
    - {/* */}
+ + + {stream.stream_type} + + +
+ + +
+
+ , + + {false && ( + + Loading epg}> + + + + )} + , + ])} + + + + ); }; diff --git a/frontend/src/utils/chromecast/CastButton.tsx b/frontend/src/utils/chromecast/CastButton.tsx new file mode 100644 index 0000000..0c11e1a --- /dev/null +++ b/frontend/src/utils/chromecast/CastButton.tsx @@ -0,0 +1,33 @@ +import React from "react"; +import useCast from "./useCast"; +import { Button } from "@windmill/react-ui"; +import { FaChromecast } from "react-icons/fa"; + +interface ICastButtonProps { + streamId: number; + onPlay: (streamId: number) => void; +} +const CastButton = ({ streamId, onPlay }: ICastButtonProps) => { + const cast = useCast({ + initialize_media_player: "DEFAULT_MEDIA_RECEIVER_APP_ID", + auto_initialize: true, + }); + const handleClick = React.useCallback(async () => { + if (cast.castReceiver) { + await cast.handleConnection(); + onPlay(streamId); + } + }, [cast.castReceiver, cast.handleConnection]); + return ( + + ); +}; + +export default CastButton; diff --git a/frontend/src/utils/chromecast/CastProvider.tsx b/frontend/src/utils/chromecast/CastProvider.tsx new file mode 100644 index 0000000..6457243 --- /dev/null +++ b/frontend/src/utils/chromecast/CastProvider.tsx @@ -0,0 +1,72 @@ +import * as React from "react"; + +import { Helmet } from "react-helmet"; +import castContext from "./castContext"; +import CastReceiver from "./CastReceiver"; + +const { useState, useEffect } = React; +const wait = (time: number) => + new Promise((res) => { + setTimeout(res, time); + }); + +function CastProvider({ children }: { children: any }) { + const [cast, setCast] = useState<{ + castReceiver?: CastReceiver; + castSender?: any; + }>({}); + const [session, setSession] = useState({}); + useEffect(() => { + (async () => { + let toBreak = false; + let tries = 15; + let castReceiver: CastReceiver; + let castSender: any; + while (true) { + try { + // @ts-ignore + castReceiver = window.chrome.cast as CastReceiver; + // @ts-ignore + castSender = window.cast.framework as any; + toBreak = true; + } catch (err) { + tries--; + if (!tries) { + toBreak = true; + } + } finally { + if (toBreak) break; + } + await wait(95); + } + // @ts-ignore + if (tries !== 0 && !!castReceiver) { + setCast({ + castReceiver, + castSender, + }); + } else { + throw new Error("Can't Load castReceiver and\\or castSender"); + } + })(); + }, []); + return ( + <> + +