WebAPIs & more
@robertnyman
Firefox OS  Using HTML5, CSS and  JavaScript together with a  number of APIs to build  apps and customize the UI.
WebAPIs
https://wiki.mozilla.org/WebAPI
Security Levels
Web Content                        Certified Web AppRegular web content                Device-critical applicationsInstalle...
https://wiki.mozilla.org/WebAPI#Planned_for_initial_release_of_B2G_.          28aka_Basecamp.29
"permissions": {    "contacts": {        "description": "Required for autocompletion in the share screen",        "access"...
Vibration API (W3C)             Web ActivitiesScreen Orientation              Push Notifications APIGeolocation API        ...
BATTERY STATUSAPI
var battery = navigator.battery;if (battery) {        var batteryLevel = Math.round(battery.level * 100) + "%",           ...
NOTIFICATION
var notification = navigator.mozNotification;notification.createNotification(    "See this",    "This is a notification", ...
SCREENORIENTATION API
// Portrait mode:screen.mozLockOrientation("portrait");/*     Possible values:         "landscape"         "portrait"     ...
VIBRATION API
// Vibrate for one secondnavigator.vibrate(1000);// Vibration pattern [vibrationTime, pause,…]navigator.vibrate([200, 100,...
WEB PAYMENTS
var pay = navigator.mozPay(paymentToken);pay.onsuccess = function (event) {    // Weee! Money!};
NETWORKINFORMATION API
var connection = window.navigator.mozConnection,    online = connection.bandwidth > 0,    metered = connection.metered;
ALARM API
var alarmId1,    request = navigator.mozAlarms.add(        new Date("May 15, 2012 16:20:00"),        "honorTimezone",     ...
var request = navigator.mozAlarms.getAll();request.onsuccess = function (event) {    console.log(JSON.stringify(event.targ...
navigator.mozSetMessageHandler(    "alarm",    function (message) {        // Note: message has to be set in the manifest ...
DEVICEPROXIMITY
window.addEventListener("deviceproximity", function (event) {    // Current device proximity, in centimeters    console.lo...
AMBIENT LIGHTEVENTS
window.addEventListener("devicelight", function (event) {    // The level of the ambient light in lux    console.log(event...
window.addEventListener("lightlevel", function (event) {    // Possible values: "normal", "bright", "dim"    console.log(e...
window.addEventListener("devicelight", function (event) {    // The lux values for "dim" typically begin below 50,    // a...
Device Storage APIBrowser APITCP Socket APIContacts APIsystemXHR                 PRIVILEGED APIS
DEVICE STORAGEAPI
var deviceStorage = navigator.getDeviceStorage("videos");
// "external", "shared", or "default".deviceStorage.type;// Add a file - returns DOMRequest with file namedeviceStorage.ad...
var storage = navigator.getDeviceStorage("videos"),    cursor = storage.enumerate();cursor.onerror = function() {   consol...
CONTACTS API
var contact = new mozContact();contact.init({name: "Tom"});var request = navigator.mozContacts.save(contact);request.onsuc...
WEB ACTIVITIES
{    "activities": {        "share": {            "filters": {                "type": ["image/png", "image/gif"]          ...
var activity = new MozActivity({    name: "view",    data: {        type: "image/png",        url: ...    }});activity.ons...
Future APIs
Resource lock API         Spellcheck APIUDP Datagram Socket API   LogAPIPeer to Peer API          Keyboard/IME APIWebNFC  ...
Installing apps
https://addons.mozilla.org/firefox/addon/firefox-os-                    simulator/
FIREFOX OS                        BOILERPLATE APPhttps://github.com/robnyman/Firefox-OS-Boilerplate-App
WebRTC
var video = document.querySelector(video);navigator.getUserMedia = navigator.getUserMedia ||navigator.webkitGetUserMedia |...
function successCallback(stream) {    // Set the source of the video element with the stream from the camera    if (video....
Getting help
https://lists.mozilla.org/listinfo/dev-webapps         irc://irc.mozilla.org/           #openwebapps
Trying things out
Robert Nymanrobertnyman.comrobert@mozilla.comMozilla   @robertnyman
WebAPIs & WebRTC - Spotify/sthlm.js
WebAPIs & WebRTC - Spotify/sthlm.js
WebAPIs & WebRTC - Spotify/sthlm.js
WebAPIs & WebRTC - Spotify/sthlm.js
WebAPIs & WebRTC - Spotify/sthlm.js
WebAPIs & WebRTC - Spotify/sthlm.js
WebAPIs & WebRTC - Spotify/sthlm.js
WebAPIs & WebRTC - Spotify/sthlm.js
WebAPIs & WebRTC - Spotify/sthlm.js
WebAPIs & WebRTC - Spotify/sthlm.js
WebAPIs & WebRTC - Spotify/sthlm.js
WebAPIs & WebRTC - Spotify/sthlm.js
WebAPIs & WebRTC - Spotify/sthlm.js
Upcoming SlideShare
Loading in...5
×

WebAPIs & WebRTC - Spotify/sthlm.js

1,593

Published on

Published in: Technology

WebAPIs & WebRTC - Spotify/sthlm.js

  1. 1. WebAPIs & more
  2. 2. @robertnyman
  3. 3. Firefox OS Using HTML5, CSS and JavaScript together with a number of APIs to build apps and customize the UI.
  4. 4. WebAPIs
  5. 5. https://wiki.mozilla.org/WebAPI
  6. 6. Security Levels
  7. 7. Web Content Certified Web AppRegular web content Device-critical applicationsInstalled Web AppA regular web appPrivileged Web AppMore access, more responsibility
  8. 8. https://wiki.mozilla.org/WebAPI#Planned_for_initial_release_of_B2G_. 28aka_Basecamp.29
  9. 9. "permissions": { "contacts": { "description": "Required for autocompletion in the share screen", "access": "readcreate" }, "alarms": { "description": "Required to schedule notifications" }}
  10. 10. Vibration API (W3C) Web ActivitiesScreen Orientation Push Notifications APIGeolocation API WebFM APIMouse Lock API (W3C) WebPaymentOpen WebApps IndexedDB (W3C)Network Information API (W3C) Ambient light sensorBattery Status API (W3C) Proximity sensorAlarm API Notification REGULAR APIS
  11. 11. BATTERY STATUSAPI
  12. 12. 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);}
  13. 13. NOTIFICATION
  14. 14. var notification = navigator.mozNotification;notification.createNotification( "See this", "This is a notification", iconURL);
  15. 15. SCREENORIENTATION API
  16. 16. // Portrait mode:screen.mozLockOrientation("portrait");/* Possible values: "landscape" "portrait" "landscape-primary" "landscape-secondary" "portrait-primary" "portrait-secondary"*/
  17. 17. VIBRATION API
  18. 18. // 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);
  19. 19. WEB PAYMENTS
  20. 20. var pay = navigator.mozPay(paymentToken);pay.onsuccess = function (event) { // Weee! Money!};
  21. 21. NETWORKINFORMATION API
  22. 22. var connection = window.navigator.mozConnection, online = connection.bandwidth > 0, metered = connection.metered;
  23. 23. ALARM API
  24. 24. var alarmId1, request = navigator.mozAlarms.add( new Date("May 15, 2012 16:20:00"), "honorTimezone", { mydata: "my event" } );request.onsuccess = function (event) { alarmId1 = event.target.result;};request.onerror = function (event) { console.log(event.target.error.name);};
  25. 25. var request = navigator.mozAlarms.getAll();request.onsuccess = function (event) { console.log(JSON.stringify(event.target.result));};request.onerror = function (event) { console.log(event.target.error.name);};
  26. 26. navigator.mozSetMessageHandler( "alarm", function (message) { // Note: message has to be set in the manifest file console.log("Alarm fired: " + JSON.stringify(message)); });
  27. 27. DEVICEPROXIMITY
  28. 28. 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);});
  29. 29. AMBIENT LIGHTEVENTS
  30. 30. window.addEventListener("devicelight", function (event) { // The level of the ambient light in lux console.log(event.value);});
  31. 31. window.addEventListener("lightlevel", function (event) { // Possible values: "normal", "bright", "dim" console.log(event.value);});
  32. 32. 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);});
  33. 33. Device Storage APIBrowser APITCP Socket APIContacts APIsystemXHR PRIVILEGED APIS
  34. 34. DEVICE STORAGEAPI
  35. 35. var deviceStorage = navigator.getDeviceStorage("videos");
  36. 36. // "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]);
  37. 37. 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 isnt a video, skip it if (file.type.substring(0, 6) !== "video/") { cursor.continue(); return; } // If it isnt playable, skip it var testplayer = document.createElement("video"); if (!testplayer.canPlayType(file.type)) { cursor.continue(); return; }};
  38. 38. CONTACTS API
  39. 39. 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")};
  40. 40. WEB ACTIVITIES
  41. 41. { "activities": { "share": { "filters": { "type": ["image/png", "image/gif"] } "href": "sharing.html", "disposition": "window" } }}
  42. 42. var activity = new MozActivity({ name: "view", data: { type: "image/png", url: ... }});activity.onsuccess = function () { console.log("Showing the image!");};activity.onerror = function () { console.log("Cant view the image!");};
  43. 43. Future APIs
  44. 44. Resource lock API Spellcheck APIUDP Datagram Socket API LogAPIPeer to Peer API Keyboard/IME APIWebNFC WebRTCWebUSB FileHandle APIHTTP-cache API Sync APICalendar API
  45. 45. Installing apps
  46. 46. https://addons.mozilla.org/firefox/addon/firefox-os- simulator/
  47. 47. FIREFOX OS BOILERPLATE APPhttps://github.com/robnyman/Firefox-OS-Boilerplate-App
  48. 48. WebRTC
  49. 49. 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 supportedin this browser.); // Display a friendly "sorry" message to the user}
  50. 50. 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();}
  51. 51. Getting help
  52. 52. https://lists.mozilla.org/listinfo/dev-webapps irc://irc.mozilla.org/ #openwebapps
  53. 53. Trying things out
  54. 54. Robert Nymanrobertnyman.comrobert@mozilla.comMozilla @robertnyman

×