feat: Make cameras optional (#2343)

This commit is contained in:
Dermot Duffy
2026-02-13 20:21:05 -08:00
committed by GitHub
parent 21f9469784
commit 93f1f08e51
61 changed files with 1312 additions and 557 deletions
+8
View File
@@ -120,6 +120,14 @@ describe('getPTZTarget', () => {
type: 'digital',
});
});
it('without cameraID', () => {
const view = createView({
view: 'live',
camera: null,
});
expect(getPTZTarget(view, { cameraManager: createCameraManager() })).toBeNull();
});
});
describe('in non-media views', () => {
+12
View File
@@ -123,4 +123,16 @@ describe('generateScreenshotTitle', () => {
expect(generateScreenshotFilename(view)).toBe('media_camera-1.jpg');
});
it('should get title for live view without camera', () => {
expect(generateScreenshotFilename(createView({ view: 'live', camera: null }))).toBe(
'live_2023-06-13-21-54-01.jpg',
);
});
it('should get title for viewer view without camera', () => {
expect(generateScreenshotFilename(createView({ view: 'media', camera: null }))).toBe(
'media.jpg',
);
});
});
+28
View File
@@ -3,6 +3,7 @@ import {
getStreamCameraID,
hasSubstream,
removeSubstream,
setSubstream,
} from '../../src/utils/substream';
import { View } from '../../src/view/view';
import { createView } from '../test-utils';
@@ -62,6 +63,25 @@ describe('hasSubstream/getStreamCameraID', () => {
expect(getStreamCameraID(view, 'camera3')).toBe('camera3');
});
});
it('should correctly handle null cameras', () => {
expect(getStreamCameraID(createView({ camera: null }))).toBeNull();
expect(hasSubstream(createView({ camera: null }))).toBeFalsy();
});
});
describe('setSubstream', () => {
it('should set substream', () => {
const view = createView({ camera: 'camera1' });
setSubstream(view, 'substream1');
expect(view.context?.live?.overrides?.get('camera1')).toBe('substream1');
});
it('should return null without a camera', () => {
const view = createView({ camera: null });
setSubstream(view, 'foo');
expect(view.context).toBeNull();
});
});
describe('removeSubstream', () => {
@@ -100,4 +120,12 @@ describe('removeSubstream', () => {
},
});
});
it('should not remove substream without camera', () => {
const view = createView({
camera: null,
});
removeSubstream(view);
expect(view.context).toBeNull();
});
});