jeudi 1 novembre 2018

How to Play Sound when receive notification [FCM]

i use FCM to send/receive notification on my site every thing work fine. i use

messaging.onMessage(function(payload){

to receive notification when user is online and i play sound using

var src = 'bing.mp3';
var c = document.createElement('audio'); 
c.src=src; c.play();

it's work fine , but not working when tab is inactive. because notifications received throw services worker

messaging.setBackgroundMessageHandler(function(payload){

is there any way to play sound when receive notifications and tab is inactive ?




1 commentaire: