web-notifications
v1.1.4
Published
A wrapper for using the Web Notifications API
Downloads
16
Maintainers
Readme
web-notifications (QBNotification)
Overview
A wrapper for using the Web Notifications API.
See it in action in folder test
Browsers support see on caniuse
Install
Install the package via CDN
https://cdn.rawgit.com/QuickBlox/web-notifications/master/qbNotification.js
or as NPM package
npm i web-notifications --save-dev
or as Bower component
bower i web-notifications --save-dev
Usage
Module is written like Universal Module Definition, so use everywhere.
Before show a notification you need to get permission from a user by
QBNotification.requestPermission(function(state) {
console.log('State is changed: ' + state);
});
Then you should create instance of QBNotification.
/**
* @param {[string]} title [Title of notification. Required.]
* @param {[type]} options [Additional options: standard params + timeout]
*/
var notify = new QBNotification(title, options);
Example options
var options = {
body: 'Body of notification',
tag: 'chatQB',
icons: 'image/icons.png',
timeout: 7,
closeOnClick: true
}
Then you can show notification via
notify.show()
Also you have:
/**
* [isSupported - check whether Notification API available in environment or not]
* @return {Boolean} [flag]
*/
QBNotification.isSupported()
/**
* [needsPermission - check whether a user provided his permission to show notifications or not]
* @return {Boolean} [flag]
*/
QBNotification.needsPermission()
Contribution
For test we use JSHint, so do
npm install -g jshint
npm test
before push yours changes.
Helpful links
License
BSD