npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

av-push

v0.0.5

Published

Push notification lib

Downloads

8

Readme

node-av-push

A Node.js universal Push Notification Distribution library.

Installation

Via npm:

$ npm install av-push

As a sub-module of your project. In this case you will also need to install apn.

$ git submodule add http://github.com/arvan/node-av-push.git av-push
$ git submodule update --init

Changelog

v0.0.5

  • Support for GCM notifications

Quick start

Below is the simple usage of this class. Just require the object, initialise and use it.

var avPush = require('av-push');
avPush.init({cert: 'my-certificate-file', key: 'my-key-file', passphrase: 'my-passphrase'});

....
....

avPush.configure({alert: 'This is a notification text', badge: 1});
avPush.send('some-device-token');

Below you can find more detailed usage tips and examples.

Usage

Class reference

Properties

options
apnConnection
note

Methods

- init(options)
- configure(notification)
- send(device_tokens)
- destroy()

Creating class object

To get started with sending notifications, the class object should be created and initialized. Here is an example:

var avPush = require('av-push');
avPush.init({cert: 'my-certificate-file', key: 'my-key-file', passphrase: 'my-passphrase'});

The init() method gets 1 argument. it is the class options. For now, this options tell what are the push distribution certificate files and some other apn configuration. Complete list of options is listed below:

options = {
	cert: ''                            /* Certificate file path */
	key:  ''                            /* Key data */
	passphrase: ''                      /* A passphrase for the Key file */
	gateway: 'gateway.push.apple.com',  /* gateway address gateway.sandbox.push.apple.com */
	enhanced: true,                     /* enable enhanced format */
	errorCallback: function(err, notif) {
		if(err){
			console.log(err);
		}
	},                                  /* Callback when error occurs function(err,notification) */
	cacheLength: 100,                   /* Number of notifications to cache for error purposes */
	isLocalized: false,                 /* Boolean indicating if APN is localized or not */
	apiKey: '',                         /* The api key for GCM */
    type: this.type.APN                 /* Type of the notification. Currently supported types are APN and GCM */
};

Setting up the notification

After initializing class object, it can be used to send as many different notifications as you need using just one object. In order to do so, you will need to set up a notification. Just like this:

avPush.configure({alert: 'Some text'});

The configure method takes one argument which is a JSON object with the notification data. Typically, notification data for APN looks like this:

notification = {
	alert: String,
	badge: Number,
	key: String,
	args: Array,
	params: Object
}

Note that you can easily send either simple text notification, or a localized notification. In order to use localized notification, you need to initialize AVPush object with isLocalized option set to true. Just like this:

avPush.init({isLocalized: true, ...});

After that, back to where you're setting up the notification:

avPush.configure({key: 'some_localization_key'});

You can also provide localization arguments to the notification:

avPush.configure({key: 'some_localization_key', args: ['arg1', 'arg2', ...]});

If you wish to send some custom fields with your notification, just add them to the list under params key and they will be added to the notification payload.

For GCM messages, the notification object looks different. As you can send whatever you want with the notification, the standart alert, badge, key and arg parameters are missing.

notification = {
    params: Object
}

Sending notification

Finally, you can send the created notification to as many users as you want. Just call:

avPush.send('some-device-token');

The send method takes one argument which is ether string of one device token, or array of device tokens. So you can send the same notification to several users like this:

avPush.send(['device-token-1', 'device-token-2', 'device-token-3', ...]);

Shutting down

When the avPush object is no longer needed, it should be shut down in order to close all connections and free some memory.

avPush.destroy();