DEVELOPERS BLOG

Enterprise Push and Pull

ENTERPRISE / 04.18.14 / sbarthelmess

pullpush

A New Type of Enterprise Push

Ok, we all knew it would happen one day. The problem arises that you need to send data larger than 8K to a device. We covered ways to tiptoe around this issue by using the latest compression technologies, but even the best compression is only so good.

What if the REAL problem is you need to send something significantly larger than 8K to a device? What if you still need offline capabilities and streaming is just not an option? Furthermore, if your data is already in a compressed form, like an image in JPG/PNG formats, don’t expect to get it much smaller. If you have grown to love the convenience and security of BlackBerry Push, but just need more scalability, check out this new paradigm – we like to call it “PUSH and PULL.”

Before we explain it in detail, let’s reacquaint ourselves with BlackBerry Push.

Enterprise PUSH as it exists today

  • BlackBerry Push / PAP standards
  • Offline support
  • Guaranteed delivery
  • Any payload type
  • Encrypted end-to-end
  • Runs in background
  • 8K limit

And a quick birds-eye view of our architecture:

pushpull architecture

Envision a small PUSH giving directives for subsequent PULL

This is in essence what we are trying to accomplish. It might look like the following:

  1. Send PUSH request with small payload from App server
  2. BES receives and directs push to device w/ guaranteed delivery
  3. Device receives push metadata
  4. Device PULLS the data from another source

PUSH and PULL has the following features:

  • No file limit size; the device storage is the only restraint
  • Perfect for video transports or large files, content/media delivery systems
  • Guaranteed request, and can check on delivery
  • Simple app / web-services integration
  • May still run in background
  • Asynchronous (more on that later)
  • *Security is up to you

An Example of Push/Pull for the Enterprise

So while the concept of Push/Poke/Pull isn’t entirely new, I noticed I couldn’t find a single example online, so I created one and baked it into the ECL application.

Let’s start by taking a picture for example. A megabyte for a relatively large picture of good quality is quite common. I’ve found a tornado warning picture in the public domain that is pretty close, weighing in at 1.3 MB. Even LZMA compressed at the highest settings, it’s still 1.2 MB. Obviously we have found a good case for Push and Pull.

pushpull image example_tornado

From the ECL example online, there is a code snippet to handle this (starting around line 177):

// Push and Pull Method
pub.getPushPull = function(url) {
               var xhr = new XMLHttpRequest();
               console.log('Getting url: '+url);
               // Attempt to determine filetype from URL
               if(url.lastIndexOf('png')!=-1 || url.lastIndexOf('jpg')!=-1) {
                               console.log('Getting pic!');
                               xhr.open('GET', url, true);
                               xhr.responseType = 'blob';
                               xhr.send();
                               xhr.onprogress = function(evt) {
                                              if (evt.lengthComputable)  msg('Loading: '+parseInt((evt.loaded / evt.total)*100));
                               };
                               xhr.onload = function() {
                                              app.pushHandler.picAlert(this.response);
                               };
               }
}

The concept is simple:

  1. Send a URL in your PUSH payload
  2. The Push listener checks for a valid URL before trying to parse JSON and if true fire off “getPushPull”
  3. getPushPull routine goes out and grabs the metadata based on the file type (in this case png or jpg)
  4. Use HTML5 blob response-type to grab it into local storage
  5. Now you call picAlert and show the image.

Go ahead and try it in the latest ECL application in Github. HINT: If you select Tools > Options > Send media push/pull, the app randomly cycles through 4 test urls (including images, ECL data, and video), and then does the pull to the device – all asynchronously without disturbing the user. In fact, you can still navigate the app while the data is being received and watch the status of the download simultaneously! Simply click on the image once received to make it go away.

pushpull screen shot

Just change these URLs to whatever you’d like to test (again in pushHandler.js, around line 162):

   // Mock routine for requesting the URL   pub.getPokePullUrl = function() {    // Have a web service return the url based on your PIN    // Example of an public appserver url to grab a BIG payload...    var url =[     'https://dl.dropboxusercontent.com/u/17100871/ECL/big_list.json',    'http://upload.wikimedia.org/wikipedia/commons/1/1a/Dszpics1.jpg',    'http://www.pdrvirginia.com/wp-content/uploads/2013/10/Virginia-Tornado-Warning1.png',    'http://techslides.com/demos/sample-videos/small.mp4'    ];

You may more realistically push any of these URLs to your device directly from the server interface included in the ECL app. Instead of a JSON payload in the box, pass the URL and the device will display it as an emergency pop up in the app when pushed. Pretty slick indeed.

Now you are no longer limited by the boundaries of Push itself. The sky is the limit! Give it a whirl and reach out to me with any comments or future functionality you would like to see implemented.

Lastly, if you have any problems, reach out to your BlackBerry account manager for assistance.  You are also welcome to tweet me @latestlinux, or comment below.

Links of interest:

About sbarthelmess