Add RTSP URL parsing utility and enhance camera settings handling
- Implement parseRTSPUrl function to extract username, password, IP, port, and path from RTSP URLs. - Update CameraSettingFields to utilize parsed RTSP URL data for camera configuration. - Modify WiFiSettingsForm to allow password visibility toggle. - Improve SightingOverview loading and error handling UI. - Adjust NavigationArrow component to reflect updated camera side logic.
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 { faEye, faEyeSlash } from "@fortawesome/free-regular-svg-icons";
|
||||||
import CardHeader from "../UI/CardHeader";
|
import CardHeader from "../UI/CardHeader";
|
||||||
import { useCameraZoom } from "../../hooks/useCameraZoom";
|
import { useCameraZoom } from "../../hooks/useCameraZoom";
|
||||||
|
import { parseRTSPUrl } from "../../utils/utils";
|
||||||
|
|
||||||
type CameraSettingsProps = {
|
type CameraSettingsProps = {
|
||||||
initialData: CameraConfig;
|
initialData: CameraConfig;
|
||||||
@@ -30,6 +31,8 @@ const CameraSettingFields = ({
|
|||||||
const { mutation, query } = useCameraZoom({ camera: cameraControllerSide });
|
const { mutation, query } = useCameraZoom({ camera: cameraControllerSide });
|
||||||
const zoomOptions = [1, 2, 4, 8];
|
const zoomOptions = [1, 2, 4, 8];
|
||||||
|
|
||||||
|
const parsed = parseRTSPUrl(initialData?.propURI?.value);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!query.data) return;
|
if (!query.data) return;
|
||||||
const apiZoom = getZoomLevel(query.data);
|
const apiZoom = getZoomLevel(query.data);
|
||||||
@@ -61,8 +64,8 @@ const CameraSettingFields = ({
|
|||||||
() => ({
|
() => ({
|
||||||
friendlyName: initialData?.id ?? "",
|
friendlyName: initialData?.id ?? "",
|
||||||
cameraAddress: initialData?.propURI?.value ?? "",
|
cameraAddress: initialData?.propURI?.value ?? "",
|
||||||
userName: "",
|
userName: parsed?.username ?? "",
|
||||||
password: "",
|
password: parsed?.password ?? "",
|
||||||
id: initialData?.id,
|
id: initialData?.id,
|
||||||
|
|
||||||
zoom: zoomLevel,
|
zoom: zoomLevel,
|
||||||
@@ -179,7 +182,7 @@ const CameraSettingFields = ({
|
|||||||
</div>
|
</div>
|
||||||
<div className="my-3">
|
<div className="my-3">
|
||||||
<CardHeader title="Zoom settings" />
|
<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) => (
|
{zoomOptions.map((zoom) => (
|
||||||
<div key={zoom}>
|
<div key={zoom}>
|
||||||
<Field
|
<Field
|
||||||
|
|||||||
@@ -3,8 +3,12 @@ import FormGroup from "../components/FormGroup";
|
|||||||
import type { WifiSettingValues } from "../../../types/types";
|
import type { WifiSettingValues } from "../../../types/types";
|
||||||
import { useWifiAndModem } from "../../../hooks/useCameraWifiandModem";
|
import { useWifiAndModem } from "../../../hooks/useCameraWifiandModem";
|
||||||
import { toast } from "sonner";
|
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 WiFiSettingsForm = () => {
|
||||||
|
const [showPwd, setShowPwd] = useState(false);
|
||||||
const { wifiQuery, wifiMutation } = useWifiAndModem();
|
const { wifiQuery, wifiMutation } = useWifiAndModem();
|
||||||
|
|
||||||
const wifiSSID = wifiQuery?.data?.propSSID?.value;
|
const wifiSSID = wifiQuery?.data?.propSSID?.value;
|
||||||
@@ -32,7 +36,7 @@ const WiFiSettingsForm = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
wifiMutation.mutate(wifiConfig);
|
wifiMutation.mutate(wifiConfig);
|
||||||
//todo: check what response is
|
|
||||||
if (wifiMutation.error) {
|
if (wifiMutation.error) {
|
||||||
toast.error("Failed to update WiFi settings");
|
toast.error("Failed to update WiFi settings");
|
||||||
return;
|
return;
|
||||||
@@ -72,10 +76,16 @@ const WiFiSettingsForm = () => {
|
|||||||
<Field
|
<Field
|
||||||
id="password"
|
id="password"
|
||||||
name="password"
|
name="password"
|
||||||
type="password"
|
type={showPwd ? "text" : "password"}
|
||||||
className="p-1.5 border border-gray-400 rounded-lg"
|
className="p-1.5 border border-gray-400 rounded-lg"
|
||||||
placeholder="Enter Password"
|
placeholder="Enter Password"
|
||||||
/>
|
/>
|
||||||
|
<FontAwesomeIcon
|
||||||
|
type="button"
|
||||||
|
className="absolute right-5 end-0"
|
||||||
|
onClick={() => setShowPwd((s) => !s)}
|
||||||
|
icon={showPwd ? faEyeSlash : faEye}
|
||||||
|
/>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
<FormGroup>
|
<FormGroup>
|
||||||
<label
|
<label
|
||||||
|
|||||||
@@ -22,10 +22,25 @@ const SightingOverview = () => {
|
|||||||
|
|
||||||
const { sync } = useHiDPICanvas(imgRef, canvasRef);
|
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)
|
if (isError) return;
|
||||||
return <p className="h-100">An error occurred, Cannot display footage</p>;
|
<div className="h-100 flex items-center justify-center text-red-500 text-lg">
|
||||||
|
An error occurred. Cannot display footage.
|
||||||
|
</div>;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col md:flex-row">
|
<div className="flex flex-col md:flex-row">
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ const NavigationArrow = ({ side, settingsPage }: NavigationArrowProps) => {
|
|||||||
if (settingsPage) {
|
if (settingsPage) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{side === "CameraFront" ? (
|
{side === "CameraA" ? (
|
||||||
<FontAwesomeIcon
|
<FontAwesomeIcon
|
||||||
icon={faArrowRight}
|
icon={faArrowRight}
|
||||||
className="absolute top-[50%] right-[2%] backdrop-blur-lg hover:cursor-pointer animate-bounce z-30"
|
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) {
|
if (!response.ok) {
|
||||||
throw new Error("Cannot reach camera zoom endpoint");
|
throw new Error("Cannot reach camera zoom endpoint");
|
||||||
}
|
}
|
||||||
const data = await response.json();
|
|
||||||
console.log(data);
|
return response.json();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchZoomInConfig({
|
async function fetchZoomInConfig({
|
||||||
queryKey,
|
queryKey,
|
||||||
}: QueryFunctionContext<[string, zoomConfig]>) {
|
}: QueryFunctionContext<[string, zoomConfig]>) {
|
||||||
const [, { camera }] = queryKey;
|
const [, { camera }] = queryKey;
|
||||||
console.log(camera);
|
|
||||||
const response = await fetch(`${CAM_BASE}/Ip${camera}-inspect`);
|
const response = await fetch(`${CAM_BASE}/Ip${camera}-inspect`);
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error("Cannot get camera zoom settings");
|
throw new Error("Cannot get camera zoom settings");
|
||||||
|
|||||||
@@ -6,6 +6,23 @@ const randomChars = () => {
|
|||||||
return letter;
|
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 generateNumberPlate = () => {
|
||||||
const numberPlateLetters = new Array(4);
|
const numberPlateLetters = new Array(4);
|
||||||
const characters: string[] = [];
|
const characters: string[] = [];
|
||||||
|
|||||||
Reference in New Issue
Block a user