Handle play() and load() promises for audio elements
Updated audio playback and preloading logic to check for and handle returned promises from play() and load() methods. This prevents uncaught promise rejections in browsers where these methods may return undefined, improving reliability and error handling for notification sounds.
This commit is contained in:
@@ -92,9 +92,12 @@ export default function ChatTable() {
|
||||
// Play notification sound
|
||||
const playNotificationSound = () => {
|
||||
if (audioRef.current) {
|
||||
audioRef.current.play().catch(e => {
|
||||
console.log("Failed to play notification sound:", e);
|
||||
});
|
||||
const playPromise = audioRef.current.play();
|
||||
if (playPromise !== undefined) {
|
||||
playPromise.catch(e => {
|
||||
console.log("Failed to play notification sound:", e);
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user