Add initial keyboard shortcut support.

This commit is contained in:
Dermot Duffy
2024-06-05 21:44:17 -07:00
parent 904f6d8142
commit 7ab545738d
186 changed files with 9564 additions and 3658 deletions
+82
View File
@@ -0,0 +1,82 @@
import { PTZAction, PTZBaseAction } from '../../config/ptz';
import { ActionPhase, ActionType, CameraConfig } from '../../config/types';
import { PTZCapabilities, PTZMovementType } from '../../types';
export const getConfiguredPTZAction = (
cameraConfig: CameraConfig,
action: PTZAction,
options?: {
phase?: ActionPhase;
preset?: string;
},
): ActionType | ActionType[] | null => {
if (action === 'preset') {
return (options?.preset ? cameraConfig.ptz.presets?.[options.preset] : null) ?? null;
}
if (options?.phase) {
return cameraConfig.ptz[`actions_${action}_${options.phase}`] ?? null;
}
return cameraConfig.ptz[`actions_${action}`] ?? null;
};
const hasConfiguredPTZAction = (
cameraConfig: CameraConfig,
action: PTZBaseAction,
options?: {
phase?: ActionPhase;
preset?: string;
},
): boolean => {
return !!getConfiguredPTZAction(cameraConfig, action, options);
};
export const getConfiguredPTZMovementType = (
cameraConfig: CameraConfig,
action: PTZBaseAction,
): PTZMovementType[] | null => {
const continuous =
hasConfiguredPTZAction(cameraConfig, action, { phase: 'start' }) &&
hasConfiguredPTZAction(cameraConfig, action, { phase: 'stop' });
const relative = hasConfiguredPTZAction(cameraConfig, action);
return continuous || relative
? [
...(continuous ? ['continuous' as const] : []),
...(relative ? ['relative' as const] : []),
]
: null;
};
export const getPTZCapabilitiesFromCameraConfig = (
cameraConfig: CameraConfig,
): PTZCapabilities | null => {
const left = getConfiguredPTZMovementType(cameraConfig, 'left');
const right = getConfiguredPTZMovementType(cameraConfig, 'right');
const up = getConfiguredPTZMovementType(cameraConfig, 'up');
const down = getConfiguredPTZMovementType(cameraConfig, 'down');
const zoomIn = getConfiguredPTZMovementType(cameraConfig, 'zoom_in');
const zoomOut = getConfiguredPTZMovementType(cameraConfig, 'zoom_out');
const presets = cameraConfig.ptz.presets
? Object.keys(cameraConfig.ptz.presets)
: undefined;
return left?.length ||
right?.length ||
up?.length ||
down?.length ||
zoomIn?.length ||
zoomOut?.length ||
presets?.length
? {
left: left ?? undefined,
right: right ?? undefined,
up: up ?? undefined,
down: down ?? undefined,
zoomIn: zoomIn ?? undefined,
zoomOut: zoomOut ?? undefined,
presets: presets,
}
: null;
};