Red Hat
Aug 21, 2013
by matthiaswessendorf

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!