Search code examples
htmlnotificationsfirefox-os

How to implement notification in Firefox OS?


I have an instant messaging application almost complete the only thing I'm missing are firefox notifications for you. As is the API?


Solution

  • It's not clear if you're after Notifications API or Push Notifications API, so I'll talk about both.

    First, the Notification "API" (I'm not sure if it's been renamed to be an API, and I'm afraid it's just known as "Notification" by now). You can use mozNotification to create new notification objects and use show to display them:

    var notification = navigator.mozNotification;
    
var n = notification.createNotification("Title", "Body", "optional_icon.png");
    n.show();
    

    On both links, you can get a better understanding what can be done with this.

    Be sure you ask for permission to use this (add this to your manifest.webapp):

    "permissions": {
        "desktop-notification":{}
    }
    

    To make it easier, I've made a demo app. That a look at how it works, and the changes I've made.

    Warning: this is different from Web Notifications.

    The Push API is already listed on Mozilla Wiki, but it's work in progress AFAIK. You can follow the news on this specific API on Mozilla Wiki, on github (server side stuff) and on the Gecko implementation bug.

    There's another API, the SimplePush API, that seems to be working by now. Unfortunately, I don't know much about it. But at least the documentation seems pretty good.

    Unfortunately again, I don't know how those APIs relate to W3C's Push API. I'm afraid the Push API is somewhat related to the standard, although I'm not sure of that. I wouldn't rely on any other documentation besides Mozilla's, in the case of these APIs.