fix: remove app state (?)

This commit is contained in:
Fredrik Burmester
2025-01-02 09:57:19 +01:00
parent 497a1adc26
commit 3058b866c3
2 changed files with 2 additions and 55 deletions

View File

@@ -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}`];

View File

@@ -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 (
<WebSocketContext.Provider value={{ ws, isConnected }}>
{children}