Giter VIP home page Giter VIP logo

aerogear-simplepush-unifiedpush-quickstart's Introduction

aerogear-simplepush-unifiedpush-quickstart

An example of using AeroGear's SimplePush/Unified Push JavaScript API. Based on aerogear-simplepush-quickstart enchancing to support registration with the UnifiedPush server.

Please visit our tutorial page for more information.

Getting started!

Prerequisites

  • Java 6.0 (Java SDK 1.6)+
  • Maven
  • JBoss Application Server 7.1.1 or later (e.g. WildFly)
  • AeroGear UnifiedPush server
  • AeroGear SimplePush server

Building the AeroGear SimplePush Server

Download the server from the AeroGear SimplePush Server project’s github page and build the source code:

git clone [email protected]:aerogear/aerogear-simplepush-server.git
cd aerogear-simplepush-server
mvn install -DskipTests=true

Now perform a cd server-netty and execute the following command to start the server on your machine:

mvn exec:java -Dexec.args="-host=localhost -port=7777 -tls=false -ack_interval=10000 -useragent_reaper_timeout=60000 -token_key=yourRandomToken" 

This starts an unsecured instance of the AeroGear SimplePush Server on localhost using port 7777.

NOTE: The server uses an in-memory database for this demo. None of the SimplePush channels are persisted by the server. A restart of the server means that the previous registered channels are gone.

Building the AeroGear UnifiedPush Server

Download the server from the AeroGear UnifiedPush Server project’s github page. First, start your JBoss Application server and once that is done, simple execute on the command line the following:

cd aerogear-unified-push-server
mvn package jboss-as:deploy

This will deploy the UnifiedPush server on your running JBoss installation, ready to accept connections. Now it’s time to perform the initial registrations with the server

Registration of the SimplePush Variant

Once the UnifiedPush server is running, access the administration console via http://SERVER:PORT/ag-push to register your SimplePush variant. Temporarily there is an "admin:123" user created by default, so you can use those credentials to login. On first login, you will be requested to change the password.

JavaScript client

Prior to run the application we need to configure the variantId and variantSecret as well as the URL's of the running servers. Navigate to js/ folder and open in your favorite text editor, the unifiedpush.js file. The file contains the main logic of the application and is responsible to register the channels with the SimplePush server, retrieve the endpoints for the update, and then register those endpoints with the UnifiedPush server so that notifications can be received.

On top of the file you will notice the configuration params that you need to change according to your specific configuration:

// config params for UnifiedPush server
var variantId = "<Your-Variant-ID";
var variantSecret = "<Your-Variant-Secret>";
var simplePushUrl = "<URL of the running SimplePush server>"
var unifiedPushUrl = "<URL of the running UnifiedPush server>";

Once that is done, open the index.html file in your favourite browser. You should see the following:

SimplePush/UnifiedPush main screen

Now, issue the following CURL command to send a push notification against the UnifiedPush server. Don't forget to replace the PushApplicationID and MasterSecret you received when you registered you Application in the administration console:

curl -u "{PushApplicationID}:{MasterSecret}"
    -v -H "Accept: application/json" -H "Content-type: application/json"
    -X POST
    -d '{ "key":"value", "alert":"HELLO!", "sound":"default", "badge":7,
         "simple-push":"version=123"}' http://localhost:8080/ag-push/rest/sender/broadcast

Notice the message being received by the web application!

Have fun!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.