Merged in bugfix/cleanup (pull request #3)
Refactor camera configuration and overview snapshot hooks; update environment variables and changed camera names to A and B
This commit is contained in:
14
.env
14
.env
@@ -6,16 +6,4 @@ VITE_OUTSIDE_BASEURL=http://100.82.205.44
|
|||||||
VITE_FOLKESTONE_URL=http://100.116.253.81/mergedHistory/sightingSummary?mostRecentRef=
|
VITE_FOLKESTONE_URL=http://100.116.253.81/mergedHistory/sightingSummary?mostRecentRef=
|
||||||
VITE_MAV_URL=http://192.168.75.11/SightingListFront/sightingSummary?mostRecentRef=
|
VITE_MAV_URL=http://192.168.75.11/SightingListFront/sightingSummary?mostRecentRef=
|
||||||
|
|
||||||
VITE_AGX_BOX_FRONT_URL=http://192.168.0.90:8080/SightingListFront/sightingSummary?mostRecentRef=
|
VITE_AGX_BOX_URL=http://100.118.196.113:8080
|
||||||
VITE_AGX_BOX_REAR_URL=http://192.168.0.90:8080/SightingListRear/sightingSummary?mostRecentRef=
|
|
||||||
|
|
||||||
VITE_AGX=http://100.72.72.70:8080/SightingListRear/sightingSummary?mostRecentRef=
|
|
||||||
VITE_AGX_FRONT=http://100.72.72.70:8080/SightingListFront/sightingSummary?mostRecentRef=
|
|
||||||
|
|
||||||
VITE_AGX_FRONT_BASE=http://100.72.72.70:8080/
|
|
||||||
|
|
||||||
VITE_LOCAL=http://10.42.0.1:8080/SightingListRear/sightingSummary?mostRecentRef=
|
|
||||||
VITE_LOCAL_FRONT=http://10.42.0.1:8080/SightingListFront/sightingSummary?mostRecentRef=
|
|
||||||
|
|
||||||
VITE_LOCAL_BASE=http://10.42.0.1:8080/
|
|
||||||
VITE_LOCAL_BASE_NEW=http://100.113.222.39
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export const SnapshotContainer = ({
|
|||||||
zoomLevel,
|
zoomLevel,
|
||||||
onZoomLevelChange,
|
onZoomLevelChange,
|
||||||
}: SnapshotContainerProps) => {
|
}: SnapshotContainerProps) => {
|
||||||
const { canvasRef, isError, isPending } = useGetOverviewSnapshot();
|
const { canvasRef, isError, isPending } = useGetOverviewSnapshot(side);
|
||||||
if (isError) return <p className="h-100">An error occurred</p>;
|
if (isError) return <p className="h-100">An error occurred</p>;
|
||||||
if (isPending) return <p className="h-100">Loading...</p>;
|
if (isPending) return <p className="h-100">Loading...</p>;
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ const CameraSettingFields = ({
|
|||||||
onZoomLevelChange,
|
onZoomLevelChange,
|
||||||
}: CameraSettingsProps) => {
|
}: CameraSettingsProps) => {
|
||||||
const [showPwd, setShowPwd] = useState(false);
|
const [showPwd, setShowPwd] = useState(false);
|
||||||
|
console.log(initialData);
|
||||||
const initialValues = useMemo<CameraSettingValues>(
|
const initialValues = useMemo<CameraSettingValues>(
|
||||||
() => ({
|
() => ({
|
||||||
friendlyName: initialData?.id ?? "",
|
friendlyName: initialData?.id ?? "",
|
||||||
@@ -48,6 +48,7 @@ const CameraSettingFields = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleSubmit = (values: CameraSettingValues) => {
|
const handleSubmit = (values: CameraSettingValues) => {
|
||||||
|
console.log(values);
|
||||||
updateCameraConfig(values);
|
updateCameraConfig(values);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -2,11 +2,10 @@ import clsx from "clsx";
|
|||||||
import Card from "../UI/Card";
|
import Card from "../UI/Card";
|
||||||
import { useSwipeable } from "react-swipeable";
|
import { useSwipeable } from "react-swipeable";
|
||||||
import { useNavigate } from "react-router";
|
import { useNavigate } from "react-router";
|
||||||
import { useOverviewVideo } from "../../hooks/useOverviewVideo";
|
|
||||||
import SightingOverview from "../SightingOverview/SightingOverview";
|
import SightingOverview from "../SightingOverview/SightingOverview";
|
||||||
|
|
||||||
const FrontCameraOverviewCard = () => {
|
const FrontCameraOverviewCard = () => {
|
||||||
useOverviewVideo();
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const handlers = useSwipeable({
|
const handlers = useSwipeable({
|
||||||
onSwipedRight: () => navigate("/camera-settings"),
|
onSwipedRight: () => navigate("/camera-settings"),
|
||||||
|
|||||||
@@ -19,10 +19,10 @@ const updateCamerasideConfig = async (data: {
|
|||||||
const updateUrl = `${base_url}/update-config?id=${data.id}`;
|
const updateUrl = `${base_url}/update-config?id=${data.id}`;
|
||||||
|
|
||||||
const updateConfigPayload = {
|
const updateConfigPayload = {
|
||||||
id: data.id,
|
id: data.friendlyName,
|
||||||
fields: [
|
fields: [
|
||||||
{
|
{
|
||||||
property: "propLEDDriverControlURI",
|
property: "id",
|
||||||
value: data.friendlyName,
|
value: data.friendlyName,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import { CAM_BASE } from "../utils/config";
|
|||||||
|
|
||||||
const apiUrl = CAM_BASE;
|
const apiUrl = CAM_BASE;
|
||||||
|
|
||||||
async function fetchSnapshot() {
|
async function fetchSnapshot(cameraSide: string) {
|
||||||
const response = await fetch(`${apiUrl}/CameraRear-preview`);
|
const response = await fetch(`${apiUrl}/${cameraSide}-preview`);
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error("Cannot reach endpoint");
|
throw new Error("Cannot reach endpoint");
|
||||||
}
|
}
|
||||||
@@ -13,7 +13,7 @@ async function fetchSnapshot() {
|
|||||||
return await response.blob();
|
return await response.blob();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useGetOverviewSnapshot() {
|
export function useGetOverviewSnapshot(side: string) {
|
||||||
const latestUrlRef = useRef<string | null>(null);
|
const latestUrlRef = useRef<string | null>(null);
|
||||||
const canvasRef = useRef<HTMLCanvasElement | null>(null);
|
const canvasRef = useRef<HTMLCanvasElement | null>(null);
|
||||||
const imageRef = useRef<HTMLImageElement | null>(null);
|
const imageRef = useRef<HTMLImageElement | null>(null);
|
||||||
@@ -38,7 +38,7 @@ export function useGetOverviewSnapshot() {
|
|||||||
isPending,
|
isPending,
|
||||||
} = useQuery({
|
} = useQuery({
|
||||||
queryKey: ["overviewSnapshot"],
|
queryKey: ["overviewSnapshot"],
|
||||||
queryFn: () => fetchSnapshot(),
|
queryFn: () => fetchSnapshot(side),
|
||||||
refetchOnWindowFocus: false,
|
refetchOnWindowFocus: false,
|
||||||
refetchInterval: 250,
|
refetchInterval: 250,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,36 +0,0 @@
|
|||||||
import { useQuery } from "@tanstack/react-query";
|
|
||||||
import { useRef } from "react";
|
|
||||||
import { CAM_BASE } from "../utils/config";
|
|
||||||
|
|
||||||
async function fetchOverviewImage(cameraSide: string) {
|
|
||||||
const response = await fetch(`${CAM_BASE}/${cameraSide}-preview`);
|
|
||||||
if (!response.ok) throw new Error("could not fetch overview image");
|
|
||||||
return response.blob();
|
|
||||||
}
|
|
||||||
|
|
||||||
export function useOverviewVideo() {
|
|
||||||
const canvasRef = useRef<HTMLCanvasElement | null>(null);
|
|
||||||
const { isPending, isError, data } = useQuery({
|
|
||||||
queryKey: ["overviewVideo"],
|
|
||||||
queryFn: () => fetchOverviewImage("CameraFront"),
|
|
||||||
// refetchInterval: () =>
|
|
||||||
// typeof document !== "undefined" && document.visibilityState === "hidden"
|
|
||||||
// ? SLOW_MS
|
|
||||||
// : FAST_MS,
|
|
||||||
// refetchIntervalInBackground: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (isPending) return;
|
|
||||||
|
|
||||||
if (isError) return;
|
|
||||||
|
|
||||||
const img = new Image();
|
|
||||||
const imgUrl = URL.createObjectURL(data);
|
|
||||||
img.src = imgUrl;
|
|
||||||
|
|
||||||
const canvas = canvasRef.current;
|
|
||||||
if (!canvas) return;
|
|
||||||
const ctx = canvas.getContext("2d");
|
|
||||||
|
|
||||||
ctx?.drawImage(img, 0, 0);
|
|
||||||
}
|
|
||||||
@@ -4,7 +4,10 @@ import { SightingFeedProvider } from "../context/providers/SightingFeedProvider"
|
|||||||
import { CAM_BASE } from "../utils/config";
|
import { CAM_BASE } from "../utils/config";
|
||||||
|
|
||||||
const Dashboard = () => {
|
const Dashboard = () => {
|
||||||
const base_url = `${CAM_BASE}/SightingListFront/sightingSummary?mostRecentRef=`;
|
const mode = import.meta.env.MODE;
|
||||||
|
const base_url = `${CAM_BASE}/SightingList/sightingSummary?mostRecentRef=`;
|
||||||
|
console.log(mode);
|
||||||
|
console.log(base_url);
|
||||||
return (
|
return (
|
||||||
<SightingFeedProvider url={base_url}>
|
<SightingFeedProvider url={base_url}>
|
||||||
<div className="mx-auto flex flex-col lg:flex-row gap-2 px-1 sm:px-2 lg:px-0 w-full min-h-screen">
|
<div className="mx-auto flex flex-col lg:flex-row gap-2 px-1 sm:px-2 lg:px-0 w-full min-h-screen">
|
||||||
|
|||||||
@@ -17,15 +17,15 @@ const FrontCamera = () => {
|
|||||||
return (
|
return (
|
||||||
<div className="mx-auto flex flex-col lg:flex-row gap-2 px-1 sm:px-2 lg:px-0 w-full min-h-screen">
|
<div className="mx-auto flex flex-col lg:flex-row gap-2 px-1 sm:px-2 lg:px-0 w-full min-h-screen">
|
||||||
<OverviewVideoContainer
|
<OverviewVideoContainer
|
||||||
title={"Front Camera"}
|
title={"Camera A"}
|
||||||
side="CameraFront"
|
side="CameraA"
|
||||||
settingsPage={true}
|
settingsPage={true}
|
||||||
zoomLevel={zoomLevel}
|
zoomLevel={zoomLevel}
|
||||||
onZoomLevelChange={setZoomLevel}
|
onZoomLevelChange={setZoomLevel}
|
||||||
/>
|
/>
|
||||||
<CameraSettings
|
<CameraSettings
|
||||||
title="Front Camera Settings"
|
title="Camera A Settings"
|
||||||
side="CameraFront"
|
side="CameraA"
|
||||||
zoomLevel={zoomLevel}
|
zoomLevel={zoomLevel}
|
||||||
onZoomLevelChange={setZoomLevel}
|
onZoomLevelChange={setZoomLevel}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -17,14 +17,14 @@ const RearCamera = () => {
|
|||||||
return (
|
return (
|
||||||
<div className="mx-auto flex flex-col lg:flex-row gap-2 px-1 sm:px-2 lg:px-0 w-full min-h-screen">
|
<div className="mx-auto flex flex-col lg:flex-row gap-2 px-1 sm:px-2 lg:px-0 w-full min-h-screen">
|
||||||
<CameraSettings
|
<CameraSettings
|
||||||
title="Rear Camera Settings"
|
title="Camera B Settings"
|
||||||
side={"CameraRear"}
|
side={"CameraB"}
|
||||||
zoomLevel={zoomLevel}
|
zoomLevel={zoomLevel}
|
||||||
onZoomLevelChange={setZoomLevel}
|
onZoomLevelChange={setZoomLevel}
|
||||||
/>
|
/>
|
||||||
<OverviewVideoContainer
|
<OverviewVideoContainer
|
||||||
title={"Rear Camera"}
|
title={"Camera B"}
|
||||||
side={"CameraRear"}
|
side={"CameraB"}
|
||||||
settingsPage={true}
|
settingsPage={true}
|
||||||
zoomLevel={zoomLevel}
|
zoomLevel={zoomLevel}
|
||||||
onZoomLevelChange={setZoomLevel}
|
onZoomLevelChange={setZoomLevel}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const rawCamBase = import.meta.env.VITE_OUTSIDE_BASEURL;
|
const rawCamBase = import.meta.env.VITE_AGX_BOX_URL;
|
||||||
export const CAM_BASE =
|
export const CAM_BASE =
|
||||||
rawCamBase && rawCamBase.trim().length > 0
|
rawCamBase && rawCamBase.trim().length > 0
|
||||||
? rawCamBase
|
? rawCamBase
|
||||||
|
|||||||
Reference in New Issue
Block a user