From 275e6d2c43a03db991a8ff7d43c5724898567b1f Mon Sep 17 00:00:00 2001 From: mUusitalo <73437699+mUusitalo@users.noreply.github.com> Date: Tue, 3 Sep 2024 16:09:43 +0300 Subject: [PATCH] Use native HLS in more situations --- .github/workflows/deploy.yml | 6 ++-- app/frontend/src/App.tsx | 68 +++++++++++++++++++----------------- 2 files changed, 38 insertions(+), 36 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index d8b439d..c96fa51 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -3,7 +3,7 @@ name: Build and deploy on: push: branches: - - placeholder + - android-fix-wip workflow_dispatch: jobs: @@ -31,7 +31,7 @@ jobs: run: | docker build . -t ${{ secrets.REGISTRY_LOGIN_SERVER }}/kiltiskamera/kamera docker push ${{ secrets.REGISTRY_LOGIN_SERVER }}/kiltiskamera/kamera - + - name: Azure logout run: | - az logout \ No newline at end of file + az logout diff --git a/app/frontend/src/App.tsx b/app/frontend/src/App.tsx index 58fe61c..d17053d 100644 --- a/app/frontend/src/App.tsx +++ b/app/frontend/src/App.tsx @@ -1,72 +1,74 @@ -import React, { useEffect, useRef, useState } from "react"; -import Chat from "./Chat"; -import VideoLoading from "./VideoLoading"; +import React, { useEffect, useRef, useState } from 'react' +import Chat from './Chat' +import VideoLoading from './VideoLoading' -import Hls from "hls.js"; +import Hls from 'hls.js' const App = () => { - const [videoStatus, setVideoStatus] = useState(false); + const [videoStatus, setVideoStatus] = useState(false) - const videoEl = useRef(null); + const videoEl = useRef(null) useEffect(() => { - let newHls: Hls; + let newHls: Hls const initializeHls = () => { - fetch("https://kiltiskamera.prodeko.org/stream_url") // Include http:// or https:// + fetch('https://kiltiskamera.prodeko.org/stream_url') // Include http:// or https:// .then((response) => response.json()) .then((data) => { - const { url } = data; + const { url } = data if (videoEl.current) { - const videoCurrent = videoEl.current; + const videoCurrent = videoEl.current if ( - videoCurrent.canPlayType("application/vnd.apple.mpegurl") - === "probably" // This result type is ridiculous + Boolean( + videoCurrent.canPlayType('application/vnd.apple.mpegurl') || + videoCurrent.canPlayType('application/x-mpegURL') + ) ) { // HLS is natively supported in Safari - videoCurrent.src = url; - videoCurrent.addEventListener("loadedmetadata", function () { - videoCurrent.play(); - }); + videoCurrent.src = url + videoCurrent.addEventListener('loadedmetadata', function () { + videoCurrent.play() + }) } else if (Hls.isSupported()) { // For other browsers, use Hls.js - newHls = new Hls({ liveDurationInfinity: true }); - newHls.attachMedia(videoCurrent); + newHls = new Hls({ liveDurationInfinity: true }) + newHls.attachMedia(videoCurrent) newHls.on(Hls.Events.MEDIA_ATTACHED, () => { - newHls.loadSource(url); - }); + newHls.loadSource(url) + }) } else { - console.error("HLS not supported on this browser"); + console.error('HLS not supported on this browser') } } }) .catch((error) => { - console.error("Error fetching stream URL:", error); - }); - }; + console.error('Error fetching stream URL:', error) + }) + } - initializeHls(); + initializeHls() // Cleanup function return () => { if (newHls) { - newHls.destroy(); + newHls.destroy() } - }; - }, [videoEl]); + } + }, [videoEl]) return (
{!videoStatus && }
@@ -74,7 +76,7 @@ const App = () => {
- ); -}; + ) +} -export default App; +export default App