Web background service on labs

7
Web Background Service A labs.ericsson.com enabler https://labs.ericsson.com/apis/web-background-service/

description

The Web Background service enables web applications to run partly in the background, even when the browser is not running. The part of the JavaScript code that is executed in the background can use APIs such as XMLHttpRequest to communicate over the network and Web Notifications to get the user's attention.

Transcript of Web background service on labs

Page 1: Web background service on labs

Web Background Service

A labs.ericsson.com enablerhttps://labs.ericsson.com/apis/web-background-service/

Page 2: Web background service on labs

2

Web Background service

A stand-alone Java application that runs on Android as well as on platforms supporting Java Standard Edition

Enables web applications, running in the browser, to run part of the application logic in the background

The JavaScript code running in the background will continue to run when the associated web application running in the browser is closed

Page 3: Web background service on labs

3

Web Background features

The background JavaScript code can useAPIs such as XMLHttpRequest to communicate over the network and Web Notifications to get the user's attention

Remote Procedure Call (RPC) bridge allows for simple interaction between the main application and the background code

Management Console lets the user manage currently running background applications

Page 4: Web background service on labs

4

Web Background example

Simple banana counting script runningin the Web Background service

The background script updates the web page with the current banana count using RPC

When the web application running in the browser is closed, notifications are used to alert the user

Page 5: Web background service on labs

5

Web Background example

Web application running in the browser<html><head><title>Simple Web Background application</title><script src="wb.js"></script> <!– bootstrap script --><script>wb.onload = function () {

wb.enable("icon.png", document.title, "Here's the description", "persistent.js");

};

function log(msg) {document.body.innerHTML += msg + "<br>";

}</script></head><body></body></html>

Page 6: Web background service on labs

6

Web Background example

persistent.js (running in the WB service)var count = 0;var notification;wb.client.importFunctions("log");

wb.client.onconnect = function () {setInterval(function() {

var msg = "number of bananas: " + count++;if (wb.client.connected)

wb.client.log(msg);else {

if (notification)notification.cancel();

notification = notifications.createNotification("icon.png",”Banana count", msg);

notification.show();}

}, 3000);};

Page 7: Web background service on labs

7