diff --git a/app/(auth)/player/direct-player.tsx b/app/(auth)/player/direct-player.tsx index a4a52abb..22670cf0 100644 --- a/app/(auth)/player/direct-player.tsx +++ b/app/(auth)/player/direct-player.tsx @@ -36,7 +36,7 @@ import React, { useRef, useState, } from "react"; -import { Alert, AppState, AppStateStatus, Platform, View } from "react-native"; +import { Alert, Platform, View } from "react-native"; import { useSharedValue } from "react-native-reanimated"; export default function page() { @@ -299,37 +299,6 @@ export default function page() { }, []) ); - const [appState, setAppState] = useState(AppState.currentState); - - useEffect(() => { - const handleAppStateChange = (nextAppState: AppStateStatus) => { - if (appState.match(/inactive|background/) && nextAppState === "active") { - console.log("App has come to the foreground!"); - // Handle app coming to the foreground - } else if (nextAppState.match(/inactive|background/)) { - console.log("App has gone to the background!"); - // Handle app going to the background - if (videoRef.current && videoRef.current.pause) { - videoRef.current.pause(); - } - } - setAppState(nextAppState); - }; - - // Use AppState.addEventListener and return a cleanup function - const subscription = AppState.addEventListener( - "change", - handleAppStateChange - ); - - return () => { - // Cleanup the event listener when the component is unmounted - subscription.remove(); - }; - }, [appState]); - - // Preselection of audio and subtitle tracks. - if (!settings) return null; let initOptions = [`--sub-text-scale=${settings.subtitleSize}`]; diff --git a/providers/WebSocketProvider.tsx b/providers/WebSocketProvider.tsx index 1311459f..8f9103e4 100644 --- a/providers/WebSocketProvider.tsx +++ b/providers/WebSocketProvider.tsx @@ -7,7 +7,7 @@ import React, { useMemo, useCallback, } from "react"; -import { Alert, AppState, AppStateStatus } from "react-native"; +import { Alert } from "react-native"; import { useAtomValue } from "jotai"; import { useQuery } from "@tanstack/react-query"; import { @@ -104,28 +104,6 @@ export const WebSocketProvider = ({ children }: WebSocketProviderProps) => { init(); }, [api, deviceId]); - useEffect(() => { - const handleAppStateChange = (state: AppStateStatus) => { - if (state === "background" || state === "inactive") { - console.log("App moving to background, closing WebSocket..."); - ws?.close(); - } else if (state === "active") { - console.log("App coming to foreground, reconnecting WebSocket..."); - connectWebSocket(); - } - }; - - const subscription = AppState.addEventListener( - "change", - handleAppStateChange - ); - - return () => { - subscription.remove(); - ws?.close(); - }; - }, [ws, connectWebSocket]); - return ( {children}