AUDNotifier is Javascript Library make use browser notification easily
-
Send Notification according to Mobile or Desktop
-
Set Audio when Notification fires
npm install aud-notifier
use notify init
to add Notifier Service Worker file to your public path
you can send notification using sendNotification
methods
AUDNotifier.sendNotification(title,options)
// send notification on desktop only
AUDNotifier.sendDesktopNotification(title,options)
// send notification on mobile only
AUDNotifier.sendMobileNotification(title,options)
you can send notification using sendNotificationRepeatedly
methods
AUDNotifier.sendNotificationRepeatedly(title,options,numberOfRepeats=1,repeatAfter=1000)
/*
send using set of times
the example below first repeat will fire after 2000 ms from send notification
and second repeat will fire after 1000 ms from first notification
*/
AUDNotifier.sendNotificationRepeatedly(title,options,2,[2000,1000])
// send notification repeatedly on desktop only
AUDNotifier.sendDesktopNotificationRepeatedly(title,options,numberOfRepeats=1,repeatAfter=1000)
// send notification repeatedly on mobile only
AUDNotifier.sendMobileNotificationRepeatedly(title,options,numberOfRepeats=1,repeatAfter=1000)
new options you can use
set audio when notification fires options.audio supports wav,ogg and mp3
AUDNotifier.sendNotification(title,{
audio:'audio-source'
})
to control volume
AUDNotifier.sendNotification(title,{
audio:{
src:'audio-source',
volume:0.5 //from 0 to 1
}
})
AUDNotifier.sendNotification(title,{
onClick:function(event) {
},
onClose:function(event) {
},
onShow:function(event) {
},
onError:function(event) {
}
})
Note:
options events doesn't fires if you browser use serviceworker notifications and you don't use library service worker
AUDNotifier.sendNotification(title,{
closeAfter:5000// close notification after 5000ms(5 seconds)
})
AUDNotifier.sendNotification(title,{
redirect:'https://example.com'// go to redirect link on click
})
Note:
options redirect doesn't fires if you browser use serviceworker notifications and you don't use library service worker
close notification after send notification
AUDNotifier.sendNotification(title,options).then(notification=>{
notification.close()
})
close by tag
AUDNotifier.close(tag)
close all
AUDNotifier.clear()
AUDNotifier.Permission.requestPermission({
onGranted:function(){}, // run when permission is granted
onDenied:function(){}, // run when permission is denied
onDefault:function(){}, // run when permission is default
})
AUDNotifier.Permission.isGranted() // check if permission is granted
AUDNotifier.Permission.isDenied() // check if permission is denied
AUDNotifier.Permission.isDefault() // check if permission is default
AUDNotifier.Permission.get()
if the browser send Notification using service worker you can set your service worker using
AUDNotifier.setServiceWorkerSettings({
file:'file.js',
scope:'/path'
})
Note:
this method doesn't fires if you browser use serviceworker notifications