I've looked many resources and but couldn't found positive results. I want to play some sound while receiving a push notification.
self.addEventListener("push", (e) => {
const data = e.data.json();
// console.log("Push Recieved...");
self.registration.showNotification(data.title, {
body: data.message,
icon: data?.icon,
image: data?.media,
url: data?.url,
data: { url: data?.url },
vibrate: [
100, 30, 100, 30, 100, 30, 200, 30, 200, 30, 200, 30, 100, 30, 100, 30,
100,
],
});
const playSound = new Audio(
"https://notificationsounds.com/storage/sounds/file-b8_discreet-song.mp3"
);
playSound.play();
alert("NEW ORDER RECEIVED");
navigator.vibrate([
100, 30, 100, 30, 100, 30, 200, 30, 200, 30, 200, 30, 100, 30, 100, 30, 100,
]);
});
I tried this way also. But caught an error saying Audio is not a function.