Pusho Service client for JavaScript
npm install pusho-js
const pusho = require('pusho');
/**
* Create a Connection
*/
const host = 'http://localhost:4000';
const apiKey = 'my-api-key'; // Generated by Pusho
const conn = pusho.connect(host, apiKey);
/**
* Subscribe to Get Push Notifications
*/
const fingerprint = 'my-unique-fingerprint';
const notificationHandler = ({ msg } => {
// handle the message here
alert(msg);
});
const subscription = pusho.notifications.subscribe(conn, fingerprint, notificationHandler);
/**
* Unsubscribe from push notifications
*/
pusho.notifications.unsubscribe(subscription);
/**
* Send push notifications to client.
* Note: mostly used on backend systems
*/
const myPayload = 'Hello World!'; // Can be anything
pusho.notifications.push(fingerprint, myPayload);
- Fork it ( https://github.com/[my-github-username]/pusho-js/fork )
- Create your feature branch (git checkout -b feature/my_new_feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request