fix: Clear stale media unavailable errors when a camera recovers (#2627)

- Closes: #2576
This commit is contained in:
Dermot Duffy
2026-07-28 21:21:50 -07:00
committed by GitHub
parent 231e3087b7
commit 15b08db3e8
49 changed files with 1128 additions and 229 deletions
@@ -219,6 +219,22 @@ describe('EntityAvailabilityDetector', () => {
expect(detector.getVerdict()).toEqual({ state: 'unknown' });
});
it('should re-check the entity when reset', () => {
// always_error makes the re-check produce a verdict immediately rather than
// waiting out the grace window.
const { detector, setEntityState } = setup({ alwaysError: true });
detector.subscribe();
// An entity that is already unavailable never fires a state change, so
// resetting must read it rather than wait to be told.
setEntityState('unavailable');
detector.reset();
expect(detector.getVerdict()).toEqual(
expect.objectContaining({ state: 'not_live', authority: 'hard' }),
);
});
it('should do nothing on reset before subscribe', () => {
const { detector, stateWatcher } = setup();
@@ -163,6 +163,26 @@ describe('MediaPlayerLivenessDetector', () => {
expect(onChange).toHaveBeenCalledTimes(1);
});
it('should discard a retained live verdict when watching resumes', async () => {
const { detector, onChange, loadMedia } = setup();
const { player, fireMediaPlayerLiveness } = createPlayer();
detector.subscribe();
loadMedia(player);
await callIntersectionHandler(true);
fireMediaPlayerLiveness(true);
// Away and back with nothing observed in between. The retained `live`
// describes the previous watch, so it must not survive into this one.
detector.unsubscribe();
onChange.mockClear();
detector.subscribe();
loadMedia(player);
await callIntersectionHandler(true);
expect(detector.getVerdict()).toEqual({ state: 'unknown' });
expect(onChange).toHaveBeenCalled();
});
it('should not watch a player without the liveness capability', async () => {
const { detector, onChange, loadMedia } = setup();
const player = mock<MediaPlayerController>();
@@ -13,6 +13,19 @@ const createHostInDocument = (): HTMLElement => {
// @vitest-environment jsdom
describe('ProviderErrorDetector', () => {
it('should not report a change when reset', () => {
const host = createHostInDocument();
const onChange = vi.fn();
const detector = new ProviderErrorDetector(host, onChange);
detector.subscribe();
dispatchLiveErrorEvent(host);
onChange.mockClear();
detector.reset();
expect(onChange).not.toHaveBeenCalled();
});
it('should start unknown', () => {
const detector = new ProviderErrorDetector(document.createElement('div'), vi.fn());
@@ -43,7 +56,7 @@ describe('ProviderErrorDetector', () => {
dispatchLiveErrorEvent(host, {
reason: 'unsupported',
detail: 'Codec not supported',
description: 'Codec not supported',
});
expect(detector.getVerdict()).toEqual({