Merged in bugfix/minor-issues-2 (pull request #6)
Add RTSP URL parsing utility and enhance camera settings handling
This commit is contained in:
@@ -10,6 +10,7 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import { faEye, faEyeSlash } from "@fortawesome/free-regular-svg-icons";
|
||||
import CardHeader from "../UI/CardHeader";
|
||||
import { useCameraZoom } from "../../hooks/useCameraZoom";
|
||||
import { parseRTSPUrl } from "../../utils/utils";
|
||||
|
||||
type CameraSettingsProps = {
|
||||
initialData: CameraConfig;
|
||||
@@ -30,6 +31,8 @@ const CameraSettingFields = ({
|
||||
const { mutation, query } = useCameraZoom({ camera: cameraControllerSide });
|
||||
const zoomOptions = [1, 2, 4, 8];
|
||||
|
||||
const parsed = parseRTSPUrl(initialData?.propURI?.value);
|
||||
|
||||
useEffect(() => {
|
||||
if (!query.data) return;
|
||||
const apiZoom = getZoomLevel(query.data);
|
||||
@@ -61,8 +64,8 @@ const CameraSettingFields = ({
|
||||
() => ({
|
||||
friendlyName: initialData?.id ?? "",
|
||||
cameraAddress: initialData?.propURI?.value ?? "",
|
||||
userName: "",
|
||||
password: "",
|
||||
userName: parsed?.username ?? "",
|
||||
password: parsed?.password ?? "",
|
||||
id: initialData?.id,
|
||||
|
||||
zoom: zoomLevel,
|
||||
@@ -179,7 +182,7 @@ const CameraSettingFields = ({
|
||||
</div>
|
||||
<div className="my-3">
|
||||
<CardHeader title="Zoom settings" />
|
||||
<div className="mx-auto flex gap-10 items-center">
|
||||
<div className="mx-auto grid grid-cols-4 items-center">
|
||||
{zoomOptions.map((zoom) => (
|
||||
<div key={zoom}>
|
||||
<Field
|
||||
|
||||
@@ -3,8 +3,12 @@ import FormGroup from "../components/FormGroup";
|
||||
import type { WifiSettingValues } from "../../../types/types";
|
||||
import { useWifiAndModem } from "../../../hooks/useCameraWifiandModem";
|
||||
import { toast } from "sonner";
|
||||
import { useState } from "react";
|
||||
import { faEyeSlash, faEye } from "@fortawesome/free-solid-svg-icons";
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
|
||||
const WiFiSettingsForm = () => {
|
||||
const [showPwd, setShowPwd] = useState(false);
|
||||
const { wifiQuery, wifiMutation } = useWifiAndModem();
|
||||
|
||||
const wifiSSID = wifiQuery?.data?.propSSID?.value;
|
||||
@@ -32,7 +36,7 @@ const WiFiSettingsForm = () => {
|
||||
};
|
||||
|
||||
wifiMutation.mutate(wifiConfig);
|
||||
//todo: check what response is
|
||||
|
||||
if (wifiMutation.error) {
|
||||
toast.error("Failed to update WiFi settings");
|
||||
return;
|
||||
@@ -72,10 +76,16 @@ const WiFiSettingsForm = () => {
|
||||
<Field
|
||||
id="password"
|
||||
name="password"
|
||||
type="password"
|
||||
type={showPwd ? "text" : "password"}
|
||||
className="p-1.5 border border-gray-400 rounded-lg"
|
||||
placeholder="Enter Password"
|
||||
/>
|
||||
<FontAwesomeIcon
|
||||
type="button"
|
||||
className="absolute right-5 end-0"
|
||||
onClick={() => setShowPwd((s) => !s)}
|
||||
icon={showPwd ? faEyeSlash : faEye}
|
||||
/>
|
||||
</FormGroup>
|
||||
<FormGroup>
|
||||
<label
|
||||
|
||||
@@ -22,10 +22,25 @@ const SightingOverview = () => {
|
||||
|
||||
const { sync } = useHiDPICanvas(imgRef, canvasRef);
|
||||
|
||||
if (isLoading) return <p className="h-100">Loading</p>;
|
||||
if (!mostRecent)
|
||||
return (
|
||||
<div className="h-150 flex items-center justify-center text-3xl animate-pulse">
|
||||
<NavigationArrow side={side} />
|
||||
<p>No Recent Sightings</p>
|
||||
</div>
|
||||
);
|
||||
if (isLoading)
|
||||
return (
|
||||
<div className="h-150 flex items-center justify-center text-3xl animate-pulse">
|
||||
<NavigationArrow side={side} />
|
||||
<p>Loading</p>
|
||||
</div>
|
||||
);
|
||||
|
||||
if (isError)
|
||||
return <p className="h-100">An error occurred, Cannot display footage</p>;
|
||||
if (isError) return;
|
||||
<div className="h-100 flex items-center justify-center text-red-500 text-lg">
|
||||
An error occurred. Cannot display footage.
|
||||
</div>;
|
||||
|
||||
return (
|
||||
<div className="flex flex-col md:flex-row">
|
||||
|
||||
@@ -25,7 +25,7 @@ const NavigationArrow = ({ side, settingsPage }: NavigationArrowProps) => {
|
||||
if (settingsPage) {
|
||||
return (
|
||||
<>
|
||||
{side === "CameraFront" ? (
|
||||
{side === "CameraA" ? (
|
||||
<FontAwesomeIcon
|
||||
icon={faArrowRight}
|
||||
className="absolute top-[50%] right-[2%] backdrop-blur-lg hover:cursor-pointer animate-bounce z-30"
|
||||
|
||||
@@ -13,16 +13,14 @@ async function zoomIn(options: ZoomInOptions) {
|
||||
if (!response.ok) {
|
||||
throw new Error("Cannot reach camera zoom endpoint");
|
||||
}
|
||||
const data = await response.json();
|
||||
console.log(data);
|
||||
return;
|
||||
|
||||
return response.json();
|
||||
}
|
||||
|
||||
async function fetchZoomInConfig({
|
||||
queryKey,
|
||||
}: QueryFunctionContext<[string, zoomConfig]>) {
|
||||
const [, { camera }] = queryKey;
|
||||
console.log(camera);
|
||||
const response = await fetch(`${CAM_BASE}/Ip${camera}-inspect`);
|
||||
if (!response.ok) {
|
||||
throw new Error("Cannot get camera zoom settings");
|
||||
|
||||
@@ -6,6 +6,23 @@ const randomChars = () => {
|
||||
return letter;
|
||||
};
|
||||
|
||||
export function parseRTSPUrl(url: string) {
|
||||
const regex = /rtsp:\/\/([^:]+):([^@]+)@([^:/]+):?(\d+)?(\/.*)?/;
|
||||
const match = url.match(regex);
|
||||
|
||||
if (!match) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
username: match[1],
|
||||
password: match[2],
|
||||
ip: match[3],
|
||||
port: match[4] || "554", // default RTSP port
|
||||
path: match[5] || "/",
|
||||
};
|
||||
}
|
||||
|
||||
const generateNumberPlate = () => {
|
||||
const numberPlateLetters = new Array(4);
|
||||
const characters: string[] = [];
|
||||
|
||||
Reference in New Issue
Block a user