- 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`.
60 lines
1.9 KiB
TypeScript
60 lines
1.9 KiB
TypeScript
import { describe, expect, it, vi } from 'vitest';
|
|
|
|
import { OffscreenVideo } from '../../../../../src/components-lib/live/providers/go2rtc-experimental/offscreen-video';
|
|
import { FakeMediaStream, FakeMediaStreamTrack } from './test-utils';
|
|
|
|
// @vitest-environment jsdom
|
|
describe('OffscreenVideo', () => {
|
|
it('should create the video from the factory on get', () => {
|
|
const video = document.createElement('video');
|
|
const offscreen = new OffscreenVideo(() => video);
|
|
|
|
expect(offscreen.get()).toBe(video);
|
|
});
|
|
|
|
it('should reuse the same video across repeated get', () => {
|
|
const create = vi.fn(() => document.createElement('video'));
|
|
const offscreen = new OffscreenVideo(create);
|
|
|
|
expect(offscreen.get()).toBe(offscreen.get());
|
|
expect(create).toBeCalledTimes(1);
|
|
});
|
|
|
|
it('should create a video with the default factory when none is injected', () => {
|
|
const offscreen = new OffscreenVideo();
|
|
|
|
expect(offscreen.get()).toBeInstanceOf(HTMLVideoElement);
|
|
});
|
|
|
|
it('should detach src and srcObject on clear', () => {
|
|
const video = document.createElement('video');
|
|
const offscreen = new OffscreenVideo(() => video);
|
|
offscreen.get();
|
|
video.src = 'data:video/mp4;base64,AAAA';
|
|
video.srcObject = new FakeMediaStream([
|
|
new FakeMediaStreamTrack('video'),
|
|
]).asMediaStream();
|
|
|
|
offscreen.clear();
|
|
|
|
expect(video.hasAttribute('src')).toBe(false);
|
|
expect(video.srcObject).toBeNull();
|
|
});
|
|
|
|
it('should create a fresh video after clear', () => {
|
|
const create = vi.fn(() => document.createElement('video'));
|
|
const offscreen = new OffscreenVideo(create);
|
|
offscreen.get();
|
|
offscreen.clear();
|
|
offscreen.get();
|
|
|
|
expect(create).toBeCalledTimes(2);
|
|
});
|
|
|
|
it('should tolerate clear when no video is held', () => {
|
|
const offscreen = new OffscreenVideo(() => document.createElement('video'));
|
|
|
|
expect(() => offscreen.clear()).not.toThrow();
|
|
});
|
|
});
|