empower mobile web developers with javascript & webapi - praguejs - 2014-03-27

71
Empower mobile web developers with JavaScript & WebAPI Frédéric Harper Sr. Technical Evangelist @ Mozilla @fharper | outofcomfortzone.net Prague JS Prague, Czech Republic 2014-03-27

Post on 18-Oct-2014

706 views

Category:

Technology


2 download

DESCRIPTION

HTML5 is a giant step in the right direction: it gives a lot more tools that developers need to create better experiences for users. The problem? It’s not there yet when it comes to web development for mobile devices. In this talk, Frédéric Harper will show you how you can use HTML, and JavaScript to build amazing mobile applications, and brush up what you published before. You’ll learn about the open web technologies, including WebAPIs, and tools designed to get you started developing HTML apps for Firefox OS, and the web.

TRANSCRIPT

Page 1: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

Empower mobile web developers with JavaScript & WebAPI Frédéric Harper Sr. Technical Evangelist @ Mozilla @fharper | outofcomfortzone.net

Prague JS Prague, Czech Republic

2014-03-27

Page 2: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

Omlouváme se, nemluvím česky Thanks Google translate…

Page 3: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

Creative Commons: http://j.mp/1ljZuJC

Page 4: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

38 billion devices connected in 2020

ABI Research - 2013-05-09 - http://j.mp/38billion

Page 5: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

You should start with the web…

Page 6: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27
Page 7: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27
Page 8: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

What you deserve

Page 9: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27
Page 10: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

Built with the Web

Using HTML5, CSS3 and JavaScript

with a number of APIs

to build apps.

Page 11: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27
Page 12: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

It’s open source

Page 13: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

Architecture

Page 14: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

Benefits of HTML5

ü  In-built distribution – the Web

ü  Simple technologies used by a lot of developers

ü  Evolution of existing practices

ü  Open, independent, and standardized

Page 15: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

Some facts

§  7 mobile operator & 4 hardware partners

§  ZTE Open, Alcatel One Touch Fire, Geeksphone Keon,

Geeksphone Peak, LG FireWeb…

§  More to come: Huawei Y300, ZTE Open C, Alcatel One

Touche Fire C & E & S…

§  Aimed at emerging markets/low end market

Page 16: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27
Page 17: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27
Page 18: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

A Firefox OS app?

§  Creating a hosted or packaged app

§  Using §  Vanilla HTML5

§  Librairies…

§  Regular API

§  Privileged API

§  Certified API

Page 19: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

HTML5 + manifest (JSON) = Firefox OS app { "version": “42", "name": ”My amazing app", "launch_path": "/index.html", "description": ”My super amazing app do super amazing things", "icons": { "16": "/images/logo16.png”,}, "developer": { "name": ”Frédéric Harper", "url": "http://outofcomfortzone.net",}, "default_locale": "en", "permissions": { "geolocation": { "description": ”Get the long/lat of the user" } }}

Page 20: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

DEMO Emberjs todomvc

Page 21: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

Web APIs

Page 22: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

Web APIs – Regular •  Alarm API •  Ambient light sensor •  Archive API •  Battery Status API •  Geolocation API •  IndexedDB •  Network Information API •  Notifications API

•  Open WebApps •  Proximity sensor •  Push API •  Screen Orientation •  Vibration API •  Web Activities •  WebFM API •  WebPayment

packaged

hosted

Page 23: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

Ambient Light Sensor

Page 24: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

Ambient Light Sensor

window.addEventListener("devicelight", function (event) {

// The level of the ambient light in lux// The lux values for "dim" typically begin below 50,// and the values for "bright" begin above 10000

console.log(event.value);});

Page 25: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

DEMO Boilerplate – Ambient Light Sensor

Page 26: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

Battery Status

Page 27: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

Battery Status

var battery = navigator.battery;

if (battery) {

var batteryLevel = Math.round(battery.level * 100) + "%", 

charging = (battery.charging)? “yes" : "no",

chargingTime = parseInt(battery.chargingTime / 60, 10,dischargingTime = parseInt(battery.dischargingTime / 60, 10);

 

battery.addEventListener("levelchange", setStatus, false);battery.addEventListener("chargingchange", setStatus, false);

battery.addEventListener("chargingtimechange", setStatus, false);}

Page 28: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

DEMO Boilerplate – Battery status

Page 29: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

Web APIs – Privileged •  Browser API •  Contacts API •  Device Storage API •  systemXHR •  TCP Socket API

packaged

Page 30: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

Browser

Page 31: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

Browser

<div>

<span id='location-bar'></span><button onclick='go_button_clicked()'>Go</button>

</div><div id='load-status'></div>

<div id='security-status'></div>

<img id='favicon'><div id='title'></div>

<iframe mozbrowser src=‘yoursite.com' id='browser'></iframe>

Page 32: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

Browser

addEventListener('mozbrowserloadstart', function(e) {

//Do stuff});

/*

Possible values:

"mozbrowserloadstart“ "mozbrowserloadend""mozbrowserlocationchange“ "mozbrowsertitlechange"

"mozbrowsericonchange“ "mozbrowsersecuritychange"

"mozbrowsercontextmenu“ "mozbrowsererror""mozbrowserkeyevent“ "mozbrowsershowmodalprompt"

"mozbrowseropenwindow“ "mozbrowserclose"*/

Page 33: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

Contacts

Page 34: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

Contacts

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 35: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

Web APIs – Certified •  Camera API •  Idle API •  Mobile Connection API •  Network Stats API •  Permissions API •  Power Management API •  Settings API •  Time/Clock API

•  Voicemail •  WebBluetooth •  WebSMS •  WebTelephony •  WiFi Information API

OS/OEM

Page 36: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

Web Activities

Page 37: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

Web Activities •  browse •  configure •  costcontrol •  dial •  open •  pick •  record •  save-bookmark

•  share •  view •  update •  new

•  mail •  websms/sms •  webcontacts/contact

Page 38: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

Pick var activity = new MozActivity({ name: "pick", //Provide the data required //by the filter of the activity data: { type: "image/jpeg" }});

Page 39: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

Pick activity.onsuccess = function () { var img = document.createElement("img"); if (this.result.blob.type.indexOf("image") != -1) { img.src = window.URL.createObjectURL(this.result.blob); }};activity.onerror = function () { //error};

Page 40: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

Dial var call = new MozActivity({ name: "dial", data: { number: "+46777888999" }});

Page 41: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

new webcontacts/contact var newContact = new MozActivity({ name: "new",

data: {

type: "webcontacts/contact",

params: {

givenName: "Frédéric",

lastName: "Harper",

email: ”[email protected]",

company: "Mozilla"

}

}

});

Page 42: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

Web Activity Received Handler "activities": { "pick": { "filters": { "type": ["image/jpeg", "image/png"] }, "disposition": "inline", "returnValue": true, "href": "/index.html#pick" }}

Page 43: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

Don’t forget to handle it! navigator.mozSetMessageHandler('activity', function(activityRequest) { var option = activityRequest.source; if (activityRequest.source.name === "pick") { // Do something to handle the activity if (picture) { activityRequest.postResult(picture); } else { activityRequest.postError("Unable to provide a picture"); } }});

Page 44: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

Creative Commons: http://j.mp/1iZHGAW

Page 45: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

How to start

Page 46: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

Creative Commons: http://j.mp/Ilm7wx

Page 47: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

Cordova & Phonegap

Page 48: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

API implementations •  Camera •  Contacts •  Device •  Device-motion •  Geolocation •  Orientation •  Vibration

Page 49: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

Get ready!

$ sudo npm install -g cordova

$ cordova create hello com.example.hello HelloWorld

$ cd hello

$ cordova platform add firefoxos

$ cordova prepare firefoxos

Page 50: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

Camera API $ cordova plugin add org.apache.cordova.camera//Cordova codenavigator.camera.getPicture(function (src) { var img = document.createElement('img'); img.id = 'slide'; img.src = src; }, function () {}, { destinationType: 1});

Page 51: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

Firefox OS App Manager + Simulator (1.2+)

Page 52: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

Firefox Web Developer Tools

Page 53: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

DEMO How to debug a Firefox OS app

Page 54: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27
Page 55: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27
Page 56: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27
Page 57: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27
Page 58: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

Some candies

Page 59: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27
Page 60: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

Prototyping with JSFiddle

•  Append /webapp.manifest

to install the app in the

Firefox OS simulator

•  Append /fxos.html to get an

install page like a Firefox OS

hosted app.

Page 61: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27
Page 62: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27
Page 63: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

What’s next

Page 64: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27
Page 65: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

More Web APIs & features

•  Calendar API

•  FileHandle API Sync API

•  Keyboard/IME API WebRTC

•  HTTP-cache API

•  Peer to Peer API

•  Spellcheck API LogAPI

•  Resource lock API

•  UDP Datagram Socket API

•  WebNFC

•  WebUSB

Page 66: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

Creative Commons: http://j.mp/1gIdcPF

To infinity, and beyond…

Page 67: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

When you’ll build your next app Why not think about the web first…

Page 68: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

Resources Firefox OS Simulator http://j.mp/fxosSimulator Firefox OS App Manager http://j.mp/fxosAppManager Mozilla Developer Network https://developer.mozilla.org StackOverflow forum http://j.mp/fxosStackOverflow

Firefox OS Boilerplate http://j.mp/fxosBoilerplate Firefox OS UI Component http://buildingfirefoxos.com/ Mozilla Brick http://j.mp/mozBrick Mozilla Appmaker https://appmaker.mozillalabs.com/

Page 69: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

Join us for an epic workshop http://mozhacks.wufoo.com/forms/firefox-os-app-workshop-prague

Page 70: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

Planning to port or build a

Firefox OS app?

Please let me know!

Page 71: Empower Mobile Web Developers with JavaScript & WebAPI - PragueJS - 2014-03-27

Frédéric Harper

[email protected]

@fharper

http://hacks.mozilla.com

http://outofcomfortzone.net