feat: Add experimental rewrite of go2rtc live provider (MSE/WebRTC/MP4/MJPEG) (#2580)
- Closes #2556 - Closes #2450 **Key intended features:** - go2rtc compatible - 100% test coverage to significantly improve ability to test, maintain and work around browser weirdnesses (e.g. Safari). - Written from the ground up in the style of the rest of the project. **To use:** - Change `live_provider` from `go2rtc` to `go2rtc-experimental`.
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import { renderNoMediaNotification } from '../../../src/components/notification/media';
|
||||
import { createCameraManager, createStore } from '../../test-utils';
|
||||
|
||||
// @vitest-environment jsdom
|
||||
describe('renderNoMediaNotification', () => {
|
||||
it('should render the no-media block when not loading', () => {
|
||||
expect(renderNoMediaNotification({ cameraID: null })).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should render the awaiting-media block when loading', () => {
|
||||
expect(renderNoMediaNotification({ cameraID: null, inProgress: true })).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should resolve the camera title from the manager', () => {
|
||||
const cameraManager = createCameraManager();
|
||||
vi.mocked(cameraManager.getCameraMetadata).mockReturnValue({
|
||||
title: 'Office',
|
||||
icon: { icon: 'mdi:cctv' },
|
||||
});
|
||||
|
||||
expect(
|
||||
renderNoMediaNotification({ cameraID: 'camera.office' }, cameraManager),
|
||||
).toBeTruthy();
|
||||
expect(cameraManager.getCameraMetadata).toBeCalledWith('camera.office');
|
||||
});
|
||||
|
||||
it('should fall back to the raw camera ID when metadata has no title', () => {
|
||||
const cameraManager = createCameraManager();
|
||||
vi.mocked(cameraManager.getCameraMetadata).mockReturnValue(null);
|
||||
|
||||
expect(
|
||||
renderNoMediaNotification({ cameraID: 'camera.office' }, cameraManager),
|
||||
).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should fall back to the default camera when cameraID is null', () => {
|
||||
const cameraManager = createCameraManager(
|
||||
createStore([{ cameraID: 'camera.default' }]),
|
||||
);
|
||||
vi.mocked(cameraManager.getCameraMetadata).mockReturnValue(null);
|
||||
|
||||
expect(renderNoMediaNotification({ cameraID: null }, cameraManager)).toBeTruthy();
|
||||
expect(cameraManager.getCameraMetadata).toBeCalledWith('camera.default');
|
||||
});
|
||||
|
||||
it('should not resolve a title when no camera is resolvable', () => {
|
||||
const cameraManager = createCameraManager(createStore());
|
||||
|
||||
expect(renderNoMediaNotification({ cameraID: null }, cameraManager)).toBeTruthy();
|
||||
expect(cameraManager.getCameraMetadata).not.toBeCalled();
|
||||
});
|
||||
});
|
||||
@@ -1,75 +0,0 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import { renderNoMedia } from '../../../src/components/notification/no-media';
|
||||
import { createCameraManager, createStore } from '../../test-utils';
|
||||
|
||||
// @vitest-environment jsdom
|
||||
describe('renderNoMedia', () => {
|
||||
it('should render "No media" heading when not loading', () => {
|
||||
const result = renderNoMedia({
|
||||
cameraID: null,
|
||||
cameraManager: null,
|
||||
});
|
||||
expect(result).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should render "Awaiting media" heading when loading', () => {
|
||||
const result = renderNoMedia({
|
||||
cameraID: null,
|
||||
cameraManager: null,
|
||||
loading: true,
|
||||
});
|
||||
expect(result).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should include camera title as metadata when camera resolves', () => {
|
||||
const cameraManager = createCameraManager();
|
||||
vi.mocked(cameraManager.getCameraMetadata).mockReturnValue({
|
||||
title: 'Office',
|
||||
icon: { icon: 'mdi:cctv' },
|
||||
});
|
||||
|
||||
const result = renderNoMedia({
|
||||
cameraID: 'camera.office',
|
||||
cameraManager,
|
||||
});
|
||||
expect(result).toBeTruthy();
|
||||
expect(cameraManager.getCameraMetadata).toBeCalledWith('camera.office');
|
||||
});
|
||||
|
||||
it('should fall back to raw camera ID when metadata has no title', () => {
|
||||
const cameraManager = createCameraManager();
|
||||
vi.mocked(cameraManager.getCameraMetadata).mockReturnValue(null);
|
||||
|
||||
const result = renderNoMedia({
|
||||
cameraID: 'camera.office',
|
||||
cameraManager,
|
||||
});
|
||||
expect(result).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should fall back to default camera ID when cameraID is null', () => {
|
||||
const store = createStore([{ cameraID: 'camera.default' }]);
|
||||
const cameraManager = createCameraManager(store);
|
||||
vi.mocked(cameraManager.getCameraMetadata).mockReturnValue(null);
|
||||
|
||||
const result = renderNoMedia({
|
||||
cameraID: null,
|
||||
cameraManager,
|
||||
});
|
||||
expect(result).toBeTruthy();
|
||||
expect(cameraManager.getCameraMetadata).toBeCalledWith('camera.default');
|
||||
});
|
||||
|
||||
it('should not include metadata when no camera is resolvable', () => {
|
||||
// Empty store -- no default camera.
|
||||
const cameraManager = createCameraManager(createStore());
|
||||
|
||||
const result = renderNoMedia({
|
||||
cameraID: null,
|
||||
cameraManager,
|
||||
});
|
||||
expect(result).toBeTruthy();
|
||||
expect(cameraManager.getCameraMetadata).not.toBeCalled();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user