Skip to content

Commit

Permalink
Merge branch 'fix/autoplay-without-user-gesture' into 'master'
Browse files Browse the repository at this point in the history
Wrap the error triggered by the autoplay permission for notification sound.

See merge request kchat/webapp!561
  • Loading branch information
antonbuks committed Oct 18, 2023
2 parents 61ca906 + 95d0968 commit ce6298a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion utils/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,12 @@ export function ding(name: string) {

export function tryNotificationSound(name: string) {
const audio = new Audio(notificationSounds.get(name) ?? notificationSounds.get('Bing'));
audio.play();
try {
audio.play();
} catch {
// Prevent the issue "DOMException: play() failed because the user didn't interact with the document first."
// Due to user gesture permissions: https://developer.chrome.com/blog/autoplay/
}
}

export function hasSoundOptions() {
Expand Down

0 comments on commit ce6298a

Please sign in to comment.