bringing the open web and apis to mobile devices with firefox os - whisky web, scotland

106
Bringing the Open Web & APIs to mobile devices with Firefox OS

Upload: robert-nyman

Post on 06-May-2015

1.063 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

Bringing the Open Web & APIs to mobile devices with Firefox OS

Page 2: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland
Page 4: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland
Page 6: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland
Page 7: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

Using HTML5, CSS and JavaScript together with a number of APIs to build apps and customize the UI.

Firefox OS

Page 8: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

Open Web Apps

Page 11: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

Steps to Take

Page 12: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

Develop Web App using HTML5, CSS, & Javascript1.

Create an app manifest file2.

Publish/install the app3.

Page 13: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland
Page 14: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

1. Develop Web App using HTML5, CSS & JavaScript

Page 15: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

Reuse any existing web site/app or develop from scratch with open web standards.

Utilize HTML5 features such as localStorage, offline manifest, IndexedDB and access Web APIs for more options.

Responsive web design for adapting to varying resolutions and screen orientation.

Page 16: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

2. Create an app manifest file

Page 17: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

Create a file with a .webapp extension

Page 18: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

{ "version": "1.0", "name": "MozillaBall", "description": "Exciting Open Web development action!", "icons": { "16": "/img/icon-16.png", "48": "/img/icon-48.png", "128": "/img/icon-128.png" }, "developer": { "name": "Mozilla Labs", "url": "http://mozillalabs.com" }, "installs_allowed_from": ["*"], "appcache_path": "/cache.manifest", "locales": { "es": { "description": "¡Acción abierta emocionante del desarrollo del Web!", "developer": { "url": "http://es.mozillalabs.com/" } }, "it": { "description": "Azione aperta emozionante di sviluppo di fotoricettore!", "developer": { "url": "http://it.mozillalabs.com/" } } }, "default_locale": "en"}

Page 19: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

MANIFEST CHECKERhttp://appmanifest.org/

Page 20: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

Serve with Content-type/MIME type:

application/x-web-app-manifest+json

Page 21: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

Apache - in mime.types:

application/x-web-app-manifest+json webapp

Apache - in .htaccess:

AddType application/x-web-app-manifest+json webapp

NGinx - in mime.types:

types { text/html html htm shtml; text/css css; text/xml xml; application/x-web-app-manifest+json webapp;}

Page 22: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

IIS:

In IIS Manager, right-click the local computer, and click Properties.

Click the MIME Types button.

Click New.

In the Extension box, type the file name extension.

In the MIME type box, type a description that exactly matches the file type defined on the computer.

Click OK.

Page 23: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

curl -I http://mozillalabs.com/manifest.webapp

Page 24: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

3. Publish/install the app

Page 25: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

Firefox Marketplace

Page 28: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

Installing/hosting the app

Page 29: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

var request = navigator.mozApps.install( "http://mozillalabs.com/MozillaBall.webapp", { user_id: "some_user" });

request.onsuccess = function() { // Success! Notification, launch page etc}

request.onerror = function() { // Failed. this.error.name has details}

Page 30: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

Packaged vs. Hosted Apps

Page 31: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

A packaged app is an Open Web App that has all of its resources (HTML, CSS, JavaScript, app manifest, and so on) contained in a zip

file, instead of having its resources on a Web server.

A packaged app is simply a zip file with the app manifest in its root directory. The manifest must be named manifest.webapp.

Page 32: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

Can be privileged apps with more API access than hosted apps

Resources are accessed from the zip file, which is stored on the device where the app is installed)

Enforce a specific Content Security Policy for all application content

Can embed remote content in iframes, but that content will not have access to privileged APIs nor will it have the default CSP applied to it

Page 34: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

WebAPIs

Page 36: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

Security Levels

Page 37: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

Web Content

Regular web content

Installed Web App

A regular web app

Privileged Web App

More access, more responsibility

Certified Web App

Device-critical applications

Page 39: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

"permissions": { "contacts": { "description": "Required for autocompletion in the share screen", "access": "readcreate" }, "alarms": { "description": "Required to schedule notifications" }}

Page 42: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

Vibration API (W3C)

Screen Orientation

Geolocation API

Mouse Lock API (W3C)

Open WebApps

Network Information API (W3C)

Battery Status API (W3C)

Alarm API

Web Activities

Push Notifications API

WebFM API

WebPayment

IndexedDB (W3C)

Ambient light sensor

Proximity sensor

Notification

REGULAR APIS

Page 43: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

BATTERY STATUS API

Page 44: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

var battery = navigator.battery;if (battery) { var batteryLevel = Math.round(battery.level * 100) + "%", charging = (battery.charging)? "" : "not ", chargingTime = parseInt(battery.chargingTime / 60, 10, dischargingTime = parseInt(battery.dischargingTime / 60, 10); // Set events battery.addEventListener("levelchange", setStatus, false); battery.addEventListener("chargingchange", setStatus, false); battery.addEventListener("chargingtimechange", setStatus, false); battery.addEventListener("dischargingtimechange", setStatus, false); }

Page 45: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

NOTIFICATION

Page 46: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

var notification = navigator.mozNotification;notification.createNotification( "See this", "This is a notification", iconURL);

Page 47: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

SCREENORIENTATION API

Page 48: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

// Portrait mode:screen.mozLockOrientation("portrait");

/* Possible values: "landscape" "portrait" "landscape-primary" "landscape-secondary" "portrait-primary" "portrait-secondary"*/

Page 49: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

VIBRATION API

Page 50: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

// Vibrate for one secondnavigator.vibrate(1000);

// Vibration pattern [vibrationTime, pause,…]navigator.vibrate([200, 100, 200, 100]);

// Vibrate for 5 secondsnavigator.vibrate(5000);

// Turn off vibrationnavigator.vibrate(0);

Page 51: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

WEB PAYMENTS

Page 52: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

var pay = navigator.mozPay(paymentToken);pay.onsuccess = function (event) { // Weee! Money!};

Page 53: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

NETWORK INFORMATION API

Page 54: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

var connection = window.navigator.mozConnection, online = connection.bandwidth > 0, metered = connection.metered;

Page 55: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

DEVICEPROXIMITY

Page 56: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

window.addEventListener("deviceproximity", function (event) { // Current device proximity, in centimeters console.log(event.value); // The maximum sensing distance the sensor is // able to report, in centimeters console.log(event.max); // The minimum sensing distance the sensor is // able to report, in centimeters console.log(event.min);});

Page 57: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

AMBIENT LIGHT EVENTS

Page 58: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

window.addEventListener("devicelight", function (event) { // The level of the ambient light in lux console.log(event.value);});

Page 59: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

window.addEventListener("lightlevel", function (event) { // Possible values: "normal", "bright", "dim" console.log(event.value);});

Page 60: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

window.addEventListener("devicelight", function (event) { // The lux values for "dim" typically begin below 50, // and the values for "bright" begin above 10000 console.log(event.value);});

Page 61: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

Device Storage API

Browser API

TCP Socket API

Contacts API

systemXHR

PRIVILEGED APIS

Page 62: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

DEVICE STORAGE API

Page 63: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

var deviceStorage = navigator.getDeviceStorage("videos");

Page 64: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

// "external", "shared", or "default".deviceStorage.type;

// Add a file - returns DOMRequest with file namedeviceStorage.add(blob);

// Same as .add, with provided namedeviceStorage.addNamed(blob, name);

// Returns DOMRequest/non-editable File objectdeviceStorage.get(name);

// Returns editable FileHandle objectdeviceStorage.getEditable(name);

// Returns DOMRequest with success or failuredeviceStorage.delete(name);

// Enumerates filesdeviceStorage.enumerate([directory]);

// Enumerates files as FileHandlesdeviceStorage.enumerateEditable([directory]);

Page 65: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

var storage = navigator.getDeviceStorage("videos"), cursor = storage.enumerate(); cursor.onerror = function() { console.error("Error in DeviceStorage.enumerate()", cursor.error.name);};

cursor.onsuccess = function() { if (!cursor.result) return; var file = cursor.result;

// If this isn't a video, skip it if (file.type.substring(0, 6) !== "video/") { cursor.continue(); return; }

// If it isn't playable, skip it var testplayer = document.createElement("video"); if (!testplayer.canPlayType(file.type)) { cursor.continue(); return; }};

Page 66: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

CONTACTS API

Page 67: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

var contact = new mozContact();contact.init({name: "Tom"});

var request = navigator.mozContacts.save(contact);request.onsuccess = function() { console.log("Success");};

request.onerror = function() { console.log("Error")};

Page 68: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

WebTelephony

WebSMS

Idle API

Settings API

Power Management API

Mobile Connection API

WiFi Information API

WebBluetooth

Permissions API

Network Stats API

Camera API

Time/Clock API

Attention screen

Voicemail

CERTIFIED APIS

Page 69: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

WEBTELEPHONY

Page 70: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

// Telephony objectvar tel = navigator.mozTelephony;

// Check if the phone is muted (read/write property)console.log(tel.muted);

// Check if the speaker is enabled (read/write property)console.log(tel.speakerEnabled);

Page 71: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

// Place a callvar cal = tel.dial(“123456789”);

Page 72: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

// Receiving a calltel.onincoming = function (event) { var incomingCall = event.call;

// Get the number of the incoming call console.log(incomingCall.number);

// Answer the call incomingCall.answer();};

// Disconnect a callcall.hangUp();

// Iterating over calls, and taking action depending on their changed statustel.oncallschanged = function (event) { tel.calls.forEach(function (call) { // Log the state of each call console.log(call.state); });};

Page 73: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

WEBSMS

Page 74: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

// SMS objectvar sms = navigator.mozSMS;

// Send a messagesms.send("123456789", "Hello world!");

Page 75: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

// Recieve a messagesms.onreceived = function (event) { // Read message console.log(event.message);};

Page 76: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

WEB ACTIVITIES

Page 77: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland
Page 78: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

{ "activities": { "share": { "filters": { "type": ["image/png", "image/gif"] } "href": "sharing.html", "disposition": "window" } }}

Page 79: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

var activity = new MozActivity({ name: "view", data: { type: "image/png", url: ... }});

activity.onsuccess = function () { console.log("Showing the image!");};

activity.onerror = function () { console.log("Can't view the image!");};

Page 80: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

var register = navigator.mozRegisterActivityHandler({ name: "view", disposition: "inline", filters: { type: "image/png" }});

register.onerror = function () { console.log("Failed to register activity");}

Page 81: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

navigator.mozSetMessageHandler("activity", function (a) { var img = getImageObject(); img.src = a.source.url; // Call a.postResult() or a.postError() if // the activity should return a value});

Page 82: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland
Page 83: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

Future APIs

Page 84: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland
Page 85: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

Resource lock API

UDP Datagram Socket API

Peer to Peer API

WebNFC

WebUSB

HTTP-cache API

Calendar API

Spellcheck API

LogAPI

Keyboard/IME API

WebRTC

FileHandle API

Sync API

Page 86: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

Web Apps from Mozilla

Page 87: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland
Page 88: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

Dialer

Contacts

Settings

SMS

Web browser

Gallery

Video Player

Music Player

E-mail (POP, IMAP)

Calendar

Alarm Clock

Camera

Notes

First Run Experience

Notifications

Home Screen

Mozilla Marketplace

System Updater

Localization Support

Page 91: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

Get started

Page 94: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

WebRTC

Page 95: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland
Page 96: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland
Page 97: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

var video = document.querySelector('video');

navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;window.URL = window.URL || window.webkitURL || window.mozURL || window.msURL;

// Call the getUserMedia method with our callback functionsif (navigator.getUserMedia) { navigator.getUserMedia({video: true}, successCallback, errorCallback);} else { console.log('Native web camera streaming (getUserMedia) not supported in this browser.'); // Display a friendly "sorry" message to the user}

Page 98: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

function successCallback(stream) { // Set the source of the video element with the stream from the camera if (video.mozSrcObject !== undefined) { video.mozSrcObject = stream; } else { video.src = (window.URL && window.URL.createObjectURL(stream)) || stream; } video.play();}

Page 99: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

Getting help

Page 100: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland
Page 101: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

https://lists.mozilla.org/listinfo/dev-webapps

irc://irc.mozilla.org/#openwebapps

Page 102: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland

Trying things out

Page 103: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland
Page 104: Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland