Node -webkit notification sound

I created a function for the node-webkit application to run OS X notification. It works fine, but I wonder if I can install system or custom sound instead of classic iPhone sound?

I looked at the official notification API documentation from Mozzila ( https://developer.mozilla.org/en-US/docs/Web/API/notification ), and there is no sound option, however, it is possible that node -webkit implanted this function (I can’t imagine that they didn’t do this), but if they did, I can’t find any documentation about it.

So my question is: is there a sound option for notifications in node -webkit?

function notif(title ,tekst, url){ var notice = new Notification(title, { body: tekst }); notice.onshow = function(evt) { setTimeout(function(){notice.close()}, 5000); } notice.onclick = function(evt) { gui.Shell.openExternal(url); setTimeout(function(){notice.close()}, 1000); }; } 
+7
macos node-webkit
source share
1 answer

Unwanted iPhone sound has been fixed / removed in a recent node-webkit pull request and released.

As for creating my own sounds, I use a wrapper around the source notification object so that whenever I call the show show command, I also play a sound if necessary.

 /** * Use composition to expand capabilities of Notifications feature. */ function NotificationWrapper(appIcon, title, description, soundFile) { /** * A path to a sound file, like /sounds/notification.wav */ function playSound(soundFile) { if(soundFile === undefined) return; var audio = document.createElement('audio'); audio.src = soundFile; audio.play(); audio = undefined; } /** * Show the notification here. */ var notification = new window.Notification(title, { body: description, icon: appIcon }); /** * Play the sound. */ playSound(soundFile); /** * Return notification object to controller so we can bind click events. */ return notification; } 

To use it, we simply call it using the new keyword:

 var myNotification = new NotificationWrapper( '#', // image icon path goes here 'node-webkit is awesome', 'Especially now that I can use my own sounds', '/sounds/notification.wav' ); myNotification.addEventListener('click', function() { console.log('You clicked the notification.'); }); 
+5
source share

All Articles