fix(player): silence active media on secondary-device guard install
All checks were successful
CI / test-and-quality (push) Successful in 3m39s
CI / test-and-quality (pull_request) Successful in 3m54s

This commit is contained in:
2026-03-01 23:29:15 +00:00
parent 000a486db1
commit f50f6a08ae
2 changed files with 58 additions and 0 deletions

View File

@@ -351,6 +351,37 @@ describe('PlayerShellComponent gameplay wiring', () => {
component.ngOnDestroy();
});
it('silences active media elements when secondary-device audio guard is installed', () => {
const pauseAudio = vi.fn();
const pauseVideo = vi.fn();
const audioElement = { muted: false, pause: pauseAudio };
const videoElement = { muted: false, pause: pauseVideo };
const querySelectorAll = vi.fn().mockReturnValue([audioElement, videoElement]);
vi.stubGlobal('document', { querySelectorAll });
vi.stubGlobal('window', {
location: { hash: '', search: '' },
history: { state: null, replaceState: vi.fn() },
localStorage: { getItem: vi.fn().mockReturnValue('en'), setItem: vi.fn(), removeItem: vi.fn() },
sessionStorage: { getItem: vi.fn().mockReturnValue(null), setItem: vi.fn(), removeItem: vi.fn() },
HTMLMediaElement: { prototype: { play: vi.fn().mockResolvedValue(undefined) } },
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
});
vi.stubGlobal('navigator', { language: 'en-US', onLine: true });
const component = new PlayerShellComponent();
component.ngOnInit();
expect(querySelectorAll).toHaveBeenCalledWith('audio,video');
expect(audioElement.muted).toBe(true);
expect(videoElement.muted).toBe(true);
expect(pauseAudio).toHaveBeenCalledTimes(1);
expect(pauseVideo).toHaveBeenCalledTimes(1);
component.ngOnDestroy();
});
it('installs secondary-device audio guard while player shell is mounted', async () => {
const originalPlay = vi.fn().mockRejectedValue(new Error('original play'));
const mediaPrototype = { play: originalPlay };