Node.js and the AeroGear UnifiedPush Server

With the recent release of the AeroGear UnifiedPush server and it is very simple to send push notifications to mobile devices.

Node.js integration

Usually a backend application is responsible for sending notifications based on events. Besides a Java library we also have an early version of a Node.js client library.

The setup of the JavaScript library is pretty simple, just clone the repo and install it locally:

npm install path/to/cloned/aerogear-unified-push-node-client

After it is present, the API is pretty straightforward to use:

// import the library
var agSender = require( "aerogear-sender-client" ).AeroGear;

// create the payload for the mobile device
var message = {
  alert: "Sent via AeroGear's Node.js SDK",
  sound: "default",
  badge: 2
};

// apply the UnifiedPush credentials for sending messages:
var options = {
  applicationID: "myPushApplicationID",
  masterSecret: "myMasterSecret"
};

// use the sender to submit a 'broadcast':
agSender.Sender( "https://my-server.rhcloud.com" )
  .broadcast( message, options )
    .on( "success", function( response ) {
      console.log( "success called", response );
    });

Once you have included this into your backend application, you are able to receive the message on those devices that are registered with the UnifiedPush Server:

Running the Server in the cloud

If you are interested in testing the server, it is quite simple to try our OpenShift cartridge – no server installation is required!

Have fun!

Howdy!

Posted in aerogear

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 32 other followers

%d bloggers like this: