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
+71 -15
View File
@@ -1,19 +1,75 @@
import { Capabilities } from '../camera-manager/capabilities';
import { FrigateCardPTZConfig, PTZ_CONTROL_ACTIONS } from '../config/types';
import { CameraManager } from '../camera-manager/manager';
import { PTZAction } from '../config/ptz';
import { PTZCapabilities } from '../types';
import { View } from '../view/view';
import { getStreamCameraID } from './substream';
export const hasUsablePTZ = (
capabilities: Capabilities | null,
config: FrigateCardPTZConfig,
): boolean => {
for (const actionName of PTZ_CONTROL_ACTIONS) {
if ('actions_' + actionName in config) {
return true;
export type PTZType = 'digital' | 'ptz';
interface PTZTarget {
targetID: string;
type: PTZType;
}
export const getPTZTarget = (
view: View,
options?: {
type?: PTZType;
cameraManager?: CameraManager;
},
): PTZTarget | null => {
if (view.isViewerView()) {
const targetID = view.queryResults?.getSelectedResult()?.getID() ?? null;
return options?.type === 'ptz' || !targetID
? null
: {
targetID: targetID,
type: 'digital',
};
} else if (view.is('live')) {
const substreamAwareCameraID = getStreamCameraID(view);
let type: PTZType = 'digital';
if (options?.type !== 'digital' && options?.cameraManager) {
if (hasCameraTruePTZ(options.cameraManager, substreamAwareCameraID)) {
type = 'ptz';
}
if (type !== 'ptz' && options?.type === 'ptz') {
return null;
}
}
return {
targetID: substreamAwareCameraID,
type: type,
};
}
const ptzCapabilities = capabilities?.getPTZCapabilities();
return (
!!ptzCapabilities?.panTilt?.length ||
!!ptzCapabilities?.zoom?.length ||
!!ptzCapabilities?.presets?.length
);
return null;
};
export const hasCameraTruePTZ = (
cameraManager: CameraManager,
cameraID: string,
): boolean => {
return !!cameraManager
.getStore()
.getCamera(cameraID)
?.getCapabilities()
?.hasPTZCapability();
};
export const ptzActionToCapabilityKey = (
action: PTZAction,
): keyof PTZCapabilities | null => {
switch (action) {
case 'left':
case 'right':
case 'up':
case 'down':
return action;
case 'zoom_in':
return 'zoomIn';
case 'zoom_out':
return 'zoomOut';
}
return null;
};