I want to play audio like whatsapp web push notification or telegram web notification. I already able received push notification in service worker, the problem is how to play audio when push notification received ?
I already read the documentation of Notification API on here :https://developer.mozilla.org/en-US/docs/Web/API/notification/sound
Based the documentation, Notification have parameter Sound (Notification.sound) .
I already implement that parameter to my syntax :
self.registration.showNotification(title, {
body: body,
icon: icon,
tag:tag,
data: data,
sound: 'http://127.0.0.1/myfolder/audio/alert.mp3'
})
But still can’t play the audio when receied push message in service worker, how to make play ?
Thanks.
2
Answers
As indicated on that MDN page:
I don’t know of any browser vendors who are planning on adding in support at this time; the way you’d normally determine that is to visit the feature status page for a given browser and see what’s on the public list. Chrome and Firefox, which are the most relevant browsers when it comes to service worker notifications, official feature trackers are hosted at
One alternative would be to use a custom vibration pattern, which is support in Chrome for Android as of version 45.
In our solution we created a Google Chrome Extension which listens to the events from Service Worker and plays the audio. For the Service Worker -> background-script communication we use this “hack”: How can Chrome extension background script communicate with web page service worker?
It is also possible to listen on push directly with the extension (using GCM).