fix(media): catch autoplay rejections from play()
CI / Build & Quality Checks (push) Successful in 5m10s
CI / Docker image build & smoke test (push) Skipped
CI / Trigger Desktop Build (push) Successful in 7s
CI / Secret scan (gitleaks) (push) Canceled after 0s
CI / Playwright smoke (e2e) (push) Canceled after 0s
CI / Build & Quality Checks (push) Successful in 5m10s
CI / Docker image build & smoke test (push) Skipped
CI / Trigger Desktop Build (push) Successful in 7s
CI / Secret scan (gitleaks) (push) Canceled after 0s
CI / Playwright smoke (e2e) (push) Canceled after 0s
Notification sounds called `audio.play()` without handling the promise, so every message that arrived before the user interacted with the page (e.g. right after launch) logged an uncaught NotAllowedError — 15 in a short test run. Same pattern in the video thumbnail loader, the voice preview (which now also resets its Play button) and useMediaPlay. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PPmy3tPq869XDW4njjVaKA
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
343de27cad
commit
23649f1255
@@ -383,7 +383,7 @@ export function VoiceMessageRecorder({ onSend, onError }: VoiceRecorderProps) {
|
|||||||
audio.pause();
|
audio.pause();
|
||||||
setPreviewPlaying(false);
|
setPreviewPlaying(false);
|
||||||
} else {
|
} else {
|
||||||
audio.play();
|
audio.play().catch(() => setPreviewPlaying(false));
|
||||||
setPreviewPlaying(true);
|
setPreviewPlaying(true);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ export const useMediaPlay = (
|
|||||||
(play: boolean) => {
|
(play: boolean) => {
|
||||||
const targetEl = getTargetElement();
|
const targetEl = getTargetElement();
|
||||||
if (!targetEl) return;
|
if (!targetEl) return;
|
||||||
if (play) targetEl.play();
|
if (play) targetEl.play().catch(() => undefined);
|
||||||
else targetEl.pause();
|
else targetEl.pause();
|
||||||
},
|
},
|
||||||
[getTargetElement],
|
[getTargetElement],
|
||||||
|
|||||||
@@ -259,7 +259,9 @@ function InviteNotifications() {
|
|||||||
|
|
||||||
const playSound = useCallback(() => {
|
const playSound = useCallback(() => {
|
||||||
const audioElement = audioRef.current;
|
const audioElement = audioRef.current;
|
||||||
audioElement?.play();
|
// Rejects under the autoplay policy until the user has interacted with the
|
||||||
|
// page (e.g. messages arriving right after launch); nothing to do then.
|
||||||
|
audioElement?.play().catch(() => undefined);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// Arm once the client's initial sync has settled (+ a short grace so the async
|
// Arm once the client's initial sync has settled (+ a short grace so the async
|
||||||
@@ -572,7 +574,9 @@ function MessageNotifications() {
|
|||||||
|
|
||||||
const playSound = useCallback(() => {
|
const playSound = useCallback(() => {
|
||||||
const audioElement = audioRef.current;
|
const audioElement = audioRef.current;
|
||||||
audioElement?.play();
|
// Rejects under the autoplay policy until the user has interacted with the
|
||||||
|
// page (e.g. messages arriving right after launch); nothing to do then.
|
||||||
|
audioElement?.play().catch(() => undefined);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// Shared delivery tail for both the main timeline and per-thread paths:
|
// Shared delivery tail for both the main timeline and per-thread paths:
|
||||||
|
|||||||
@@ -134,7 +134,9 @@ export const loadVideoElement = (url: string): Promise<HTMLVideoElement> =>
|
|||||||
|
|
||||||
video.src = url;
|
video.src = url;
|
||||||
video.load();
|
video.load();
|
||||||
video.play();
|
// Only nudges the decoder toward the first frame; `onloadeddata` settles
|
||||||
|
// the promise, so an autoplay refusal here is harmless.
|
||||||
|
video.play().catch(() => undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
export const getThumbnailDimensions = (width: number, height: number): [number, number] => {
|
export const getThumbnailDimensions = (width: number, height: number): [number, number] => {
|
||||||
|
|||||||
Reference in New Issue
Block a user