From 11639ed25c239a62cc95e823e995a99232f5dbf3 Mon Sep 17 00:00:00 2001 From: Nick Mowen Date: Thu, 15 Dec 2022 10:40:09 -0700 Subject: [PATCH] Add ability to set presets from UI --- web/src/api/ws.jsx | 9 ++++ web/src/components/CameraControlPanel.jsx | 56 +++++++++++++++++++++++ web/src/routes/Camera.jsx | 7 +++ 3 files changed, 72 insertions(+) create mode 100644 web/src/components/CameraControlPanel.jsx diff --git a/web/src/api/ws.jsx b/web/src/api/ws.jsx index 734200215..8995a065b 100644 --- a/web/src/api/ws.jsx +++ b/web/src/api/ws.jsx @@ -120,6 +120,15 @@ export function useSnapshotsState(camera) { return { payload, send, connected }; } +export function usePtzCommand(camera) { + const { + value: { payload }, + send, + connected, + } = useWs(`${camera}/ptz`, `${camera}/ptz`); + return { payload, send, connected }; +} + export function useRestart() { const { value: { payload }, diff --git a/web/src/components/CameraControlPanel.jsx b/web/src/components/CameraControlPanel.jsx new file mode 100644 index 000000000..6e8571c37 --- /dev/null +++ b/web/src/components/CameraControlPanel.jsx @@ -0,0 +1,56 @@ +import { h } from 'preact'; +import { useState } from 'preact/hooks'; +import useSWR from 'swr'; +import { usePtzCommand } from '../api/ws'; +import ActivityIndicator from './ActivityIndicator'; +import Button from './Button'; + +export default function CameraControlPanel({ camera = '' }) { + const { data: ptz } = useSWR(`${camera}/ptz/info`); + const [currentPreset, setCurrentPreset] = useState(''); + + const { payload: _, send: sendPtz } = usePtzCommand(camera); + + const onSetPreview = async (e) => { + e.stopPropagation(); + + if (currentPreset == 'none') { + return; + } + + sendPtz(`preset-${currentPreset}`); + setCurrentPreset(''); + }; + + if (!ptz) { + return ; + } + + return ( +
+ ptz is enabled with features {ptz.features[0]} + {ptz.presets && ( +
+
+ +
+ + +
+ )} +
+ ); +} diff --git a/web/src/routes/Camera.jsx b/web/src/routes/Camera.jsx index 7a50d530a..01cfdcc27 100644 --- a/web/src/routes/Camera.jsx +++ b/web/src/routes/Camera.jsx @@ -15,6 +15,7 @@ import { useApiHost } from '../api'; import useSWR from 'swr'; import WebRtcPlayer from '../components/WebRtcPlayer'; import MsePlayer from '../components/MsePlayer'; +import CameraControlPanel from '../components/CameraControlPanel'; const emptyObject = Object.freeze({}); @@ -188,6 +189,12 @@ export default function Camera({ camera }) { {player} + {cameraConfig?.onvif?.host && ( +
+ +
+ )} +
Tracked objects