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

@@ -24,6 +24,11 @@ type MediaPrototypeWithGuardState = {
};
};
type GuardableMediaElement = {
muted?: boolean;
pause?: () => void;
};
function resolveLocalStorage(): Storage | undefined {
if (typeof window === 'undefined') {
return undefined;
@@ -202,6 +207,8 @@ export class PlayerShellComponent implements OnInit, OnDestroy {
return;
}
this.silenceExistingMediaElements();
const mediaPrototype = (window as Window & { HTMLMediaElement?: { prototype?: MediaPrototypeWithGuardState } }).HTMLMediaElement
?.prototype;
@@ -235,6 +242,26 @@ export class PlayerShellComponent implements OnInit, OnDestroy {
};
}
private silenceExistingMediaElements(): void {
if (typeof document === 'undefined' || typeof document.querySelectorAll !== 'function') {
return;
}
const activeElements = document.querySelectorAll('audio,video') as
| NodeListOf<GuardableMediaElement>
| GuardableMediaElement[]
| undefined;
if (!activeElements || typeof (activeElements as { forEach?: unknown }).forEach !== 'function') {
return;
}
activeElements.forEach((element) => {
element.muted = true;
element.pause?.();
});
}
private scheduleStateSync(): void {
this.clearStateSyncTimer();