SlideShare a Scribd company logo
WebAPIs & more
WebAPIs & WebRTC - Spotify/sthlm.js
@robertnyman
WebAPIs & WebRTC - Spotify/sthlm.js
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
WebAPIs & WebRTC - Spotify/sthlm.js
Security Levels
Web Content                        Certified Web App

Regular web content                Device-critical applications

Installed Web App

A regular web app

Privileged Web App

More access, more responsibility
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": "readcreate"
    },
    "alarms": {
        "description": "Required to schedule notifications"
    }
}
WebAPIs & WebRTC - Spotify/sthlm.js
Vibration API (W3C)             Web Activities
Screen Orientation              Push Notifications API
Geolocation API                 WebFM API
Mouse Lock API (W3C)            WebPayment
Open WebApps                    IndexedDB (W3C)
Network Information API (W3C)   Ambient light sensor
Battery Status API (W3C)        Proximity sensor
Alarm API                       Notification




                      REGULAR APIS
BATTERY STATUS
API
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);
}
NOTIFICATION
var notification = navigator.mozNotification;
notification.createNotification(
    "See this",
    "This is a notification",
    iconURL
);
SCREEN
ORIENTATION API
// Portrait mode:
screen.mozLockOrientation("portrait");

/*
     Possible values:
         "landscape"
         "portrait"
         "landscape-primary"
         "landscape-secondary"
         "portrait-primary"
         "portrait-secondary"
*/
VIBRATION API
// Vibrate for one second
navigator.vibrate(1000);

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

// Vibrate for 5 seconds
navigator.vibrate(5000);

// Turn off vibration
navigator.vibrate(0);
WEB PAYMENTS
var pay = navigator.mozPay(paymentToken);
pay.onsuccess = function (event) {
    // Weee! Money!
};
NETWORK
INFORMATION 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",
        {
            mydata: "my event"
        }
    );

request.onsuccess = function (event) {
    alarmId1 = event.target.result;
};

request.onerror = function (event) {
    console.log(event.target.error.name);
};
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);
};
navigator.mozSetMessageHandler(
    "alarm",
    function (message) {
        // Note: message has to be set in the manifest file
        console.log("Alarm fired: " + JSON.stringify(message));
    }
);
DEVICEPROXIMITY
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);
});
AMBIENT LIGHT
EVENTS
window.addEventListener("devicelight", function (event) {
    // The level of the ambient light in lux
    console.log(event.value);
});
window.addEventListener("lightlevel", function (event) {
    // Possible values: "normal", "bright", "dim"
    console.log(event.value);
});
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);
});
Device Storage API
Browser API
TCP Socket API
Contacts API
systemXHR




                 PRIVILEGED APIS
DEVICE STORAGE
API
var deviceStorage = navigator.getDeviceStorage("videos");
// "external", "shared", or "default".
deviceStorage.type;

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

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

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

// Returns editable FileHandle object
deviceStorage.getEditable(name);

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

// Enumerates files
deviceStorage.enumerate([directory]);

// Enumerates files as FileHandles
deviceStorage.enumerateEditable([directory]);
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;
     }
};
CONTACTS API
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")
};
WEB ACTIVITIES
WebAPIs & WebRTC - Spotify/sthlm.js
{
    "activities": {
        "share": {
            "filters": {
                "type": ["image/png", "image/gif"]
            }
            "href": "sharing.html",
            "disposition": "window"
        }
    }
}
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!");
};
WebAPIs & WebRTC - Spotify/sthlm.js
Future APIs
WebAPIs & WebRTC - Spotify/sthlm.js
Resource lock API         Spellcheck API
UDP Datagram Socket API   LogAPI
Peer to Peer API          Keyboard/IME API
WebNFC                    WebRTC
WebUSB                    FileHandle API
HTTP-cache API            Sync API
Calendar API
Installing apps
https://addons.mozilla.org/firefox/addon/firefox-os-
                    simulator/
FIREFOX OS
                        BOILERPLATE APP



https://github.com/robnyman/Firefox-OS-Boilerplate-App
WebRTC
WebAPIs & WebRTC - Spotify/sthlm.js
WebAPIs & WebRTC - Spotify/sthlm.js
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 functions
if (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
}
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();
}
Getting help
WebAPIs & WebRTC - Spotify/sthlm.js
https://lists.mozilla.org/listinfo/dev-webapps

         irc://irc.mozilla.org/
           #openwebapps
Trying things out
WebAPIs & WebRTC - Spotify/sthlm.js
WebAPIs & WebRTC - Spotify/sthlm.js
WebAPIs & WebRTC - Spotify/sthlm.js
Robert Nyman
robertnyman.com
robert@mozilla.com
Mozilla

   @robertnyman

More Related Content

What's hot (19)

PDF
Android swedroid
Johan Nilsson
 
PPTX
HTML5 on Mobile
Adam Lu
 
PDF
Android in practice
Jose Manuel Ortega Candel
 
PDF
HTML5 APIs - Where no man has gone before! - Altran
Robert Nyman
 
PDF
Instant and offline apps with Service Worker
Chang W. Doh
 
PPTX
HTML5 WebWorks
Raul Jimenez
 
PDF
Web versus Native: round 1!
Chris Mills
 
PDF
APIs, now and in the future
Chris Mills
 
PDF
HTML5, The Open Web, and what it means for you - MDN Hack Day, Sao Paulo
Robert Nyman
 
PDF
JQuery UK Service Workers Talk
Natasha Rooney
 
PDF
Android best practices
Jose Manuel Ortega Candel
 
PDF
JQuery UK February 2015: Service Workers On Vacay
Natasha Rooney
 
PDF
APIs for modern web apps
Chris Mills
 
KEY
2011 a grape odyssey
Mike Hagedorn
 
PPTX
Authenticating and Securing Node.js APIs
Jimmy Guerrero
 
PDF
ILUG 2010 - Deploying plug-ins to the enterprise
René Winkelmeyer
 
PDF
PrimeTime JSF with PrimeFaces - Dec 2014
cagataycivici
 
PDF
Empowering the "mobile web"
Chris Mills
 
PDF
Forensic Tools for In-Depth Performance Investigations
Nicholas Jansma
 
Android swedroid
Johan Nilsson
 
HTML5 on Mobile
Adam Lu
 
Android in practice
Jose Manuel Ortega Candel
 
HTML5 APIs - Where no man has gone before! - Altran
Robert Nyman
 
Instant and offline apps with Service Worker
Chang W. Doh
 
HTML5 WebWorks
Raul Jimenez
 
Web versus Native: round 1!
Chris Mills
 
APIs, now and in the future
Chris Mills
 
HTML5, The Open Web, and what it means for you - MDN Hack Day, Sao Paulo
Robert Nyman
 
JQuery UK Service Workers Talk
Natasha Rooney
 
Android best practices
Jose Manuel Ortega Candel
 
JQuery UK February 2015: Service Workers On Vacay
Natasha Rooney
 
APIs for modern web apps
Chris Mills
 
2011 a grape odyssey
Mike Hagedorn
 
Authenticating and Securing Node.js APIs
Jimmy Guerrero
 
ILUG 2010 - Deploying plug-ins to the enterprise
René Winkelmeyer
 
PrimeTime JSF with PrimeFaces - Dec 2014
cagataycivici
 
Empowering the "mobile web"
Chris Mills
 
Forensic Tools for In-Depth Performance Investigations
Nicholas Jansma
 

Similar to WebAPIs & WebRTC - Spotify/sthlm.js (20)

PDF
Bringing the Open Web & APIs to 
mobile devices with Firefox OS - Geek Meet
Robert Nyman
 
PDF
Web APIs & Apps - Mozilla
Robert Nyman
 
PDF
Firefox OS learnings & visions, WebAPIs - budapest.mobile
Robert Nyman
 
PDF
Firefox OS, the Open Web & WebAPIs - HTML5DevConf, San Francisco
Robert Nyman
 
PDF
Mozilla, Firefox OS and the Open Web
Robert Nyman
 
PDF
WebAPIs & Apps - Mozilla London
Robert Nyman
 
PDF
WebRTC & Firefox OS - presentation at Google
Robert Nyman
 
PDF
Firefox OS, the Open Web & WebAPIs - Geek Meet Västerås
Robert Nyman
 
PDF
Bringing the Open Web & APIs to 
mobile devices with Firefox OS - SpainJS
Robert Nyman
 
PDF
Bringing the Open Web & APIs to 
mobile devices with Firefox OS - BrazilJS
Robert Nyman
 
PDF
Firefox OS Introduction at Bontouch
Robert Nyman
 
PDF
Bringing the Open Web & APIs to 
mobile devices with Firefox OS, JSFoo, India
Robert Nyman
 
PDF
Bringing the Open Web & APIs to 
mobile devices with Firefox OS - GOTO confer...
Robert Nyman
 
PDF
Firefox OS, HTML5 to the next level - Python Montreal - 2014-05-12
Frédéric Harper
 
PDF
Firefox OS workshop, Colombia
Robert Nyman
 
PDF
HTML, not just for desktops: Firefox OS - Congreso Universitario Móvil - 201...
Frédéric Harper
 
PDF
Firefox OS, fixing the mobile web - FITC Toronto - 2014-04-28
Frédéric Harper
 
PPTX
Firefox OS Web APIs, taking it to the next level
Frédéric Harper
 
PDF
Firefox OS - A (mobile) Web Developers dream - DWX14
Carsten Sandtner
 
PDF
Firefox OS
Sayak Sarkar
 
Bringing the Open Web & APIs to 
mobile devices with Firefox OS - Geek Meet
Robert Nyman
 
Web APIs & Apps - Mozilla
Robert Nyman
 
Firefox OS learnings & visions, WebAPIs - budapest.mobile
Robert Nyman
 
Firefox OS, the Open Web & WebAPIs - HTML5DevConf, San Francisco
Robert Nyman
 
Mozilla, Firefox OS and the Open Web
Robert Nyman
 
WebAPIs & Apps - Mozilla London
Robert Nyman
 
WebRTC & Firefox OS - presentation at Google
Robert Nyman
 
Firefox OS, the Open Web & WebAPIs - Geek Meet Västerås
Robert Nyman
 
Bringing the Open Web & APIs to 
mobile devices with Firefox OS - SpainJS
Robert Nyman
 
Bringing the Open Web & APIs to 
mobile devices with Firefox OS - BrazilJS
Robert Nyman
 
Firefox OS Introduction at Bontouch
Robert Nyman
 
Bringing the Open Web & APIs to 
mobile devices with Firefox OS, JSFoo, India
Robert Nyman
 
Bringing the Open Web & APIs to 
mobile devices with Firefox OS - GOTO confer...
Robert Nyman
 
Firefox OS, HTML5 to the next level - Python Montreal - 2014-05-12
Frédéric Harper
 
Firefox OS workshop, Colombia
Robert Nyman
 
HTML, not just for desktops: Firefox OS - Congreso Universitario Móvil - 201...
Frédéric Harper
 
Firefox OS, fixing the mobile web - FITC Toronto - 2014-04-28
Frédéric Harper
 
Firefox OS Web APIs, taking it to the next level
Frédéric Harper
 
Firefox OS - A (mobile) Web Developers dream - DWX14
Carsten Sandtner
 
Firefox OS
Sayak Sarkar
 
Ad

More from Robert Nyman (20)

PDF
Have you tried listening?
Robert Nyman
 
PDF
Building for Your Next Billion - Google I/O 2017
Robert Nyman
 
PDF
Introduction to Google Daydream
Robert Nyman
 
PDF
Predictability for the Web
Robert Nyman
 
PDF
The Future of Progressive Web Apps - View Source conference, Berlin 2016
Robert Nyman
 
PDF
The Future of the Web - Cold Front conference 2016
Robert Nyman
 
PDF
The Future of Progressive Web Apps - Google for Indonesia
Robert Nyman
 
PDF
Google tech & products
Robert Nyman
 
PDF
Introduction to Progressive Web Apps, Google Developer Summit, Seoul - South ...
Robert Nyman
 
PDF
Progressive Web Apps keynote, Google Developer Summit, Tokyo, Japan
Robert Nyman
 
PDF
The web - What it has, what it lacks and where it must go - keynote at Riga D...
Robert Nyman
 
PDF
The web - What it has, what it lacks and where it must go - Bulgaria Web Summ...
Robert Nyman
 
PDF
The web - What it has, what it lacks and where it must go - Istanbul
Robert Nyman
 
PDF
The web - What it has, what it lacks and where it must go
Robert Nyman
 
PDF
Google, the future and possibilities
Robert Nyman
 
PDF
Developer Relations in the Nordics
Robert Nyman
 
PDF
What is Developer Relations?
Robert Nyman
 
PDF
Android TV Introduction - Stockholm Android TV meetup
Robert Nyman
 
PDF
New improvements for web developers - frontend.fi, Helsinki
Robert Nyman
 
PDF
Mobile phone trends, user data & developer climate - frontend.fi, Helsinki
Robert Nyman
 
Have you tried listening?
Robert Nyman
 
Building for Your Next Billion - Google I/O 2017
Robert Nyman
 
Introduction to Google Daydream
Robert Nyman
 
Predictability for the Web
Robert Nyman
 
The Future of Progressive Web Apps - View Source conference, Berlin 2016
Robert Nyman
 
The Future of the Web - Cold Front conference 2016
Robert Nyman
 
The Future of Progressive Web Apps - Google for Indonesia
Robert Nyman
 
Google tech & products
Robert Nyman
 
Introduction to Progressive Web Apps, Google Developer Summit, Seoul - South ...
Robert Nyman
 
Progressive Web Apps keynote, Google Developer Summit, Tokyo, Japan
Robert Nyman
 
The web - What it has, what it lacks and where it must go - keynote at Riga D...
Robert Nyman
 
The web - What it has, what it lacks and where it must go - Bulgaria Web Summ...
Robert Nyman
 
The web - What it has, what it lacks and where it must go - Istanbul
Robert Nyman
 
The web - What it has, what it lacks and where it must go
Robert Nyman
 
Google, the future and possibilities
Robert Nyman
 
Developer Relations in the Nordics
Robert Nyman
 
What is Developer Relations?
Robert Nyman
 
Android TV Introduction - Stockholm Android TV meetup
Robert Nyman
 
New improvements for web developers - frontend.fi, Helsinki
Robert Nyman
 
Mobile phone trends, user data & developer climate - frontend.fi, Helsinki
Robert Nyman
 
Ad

Recently uploaded (20)

PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
July Patch Tuesday
Ivanti
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
July Patch Tuesday
Ivanti
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 

WebAPIs & WebRTC - Spotify/sthlm.js

  • 5. Firefox OS Using HTML5, CSS and JavaScript together with a number of APIs to build apps and customize the UI.
  • 10. Web Content Certified Web App Regular web content Device-critical applications Installed Web App A regular web app Privileged Web App More access, more responsibility
  • 12. "permissions": { "contacts": { "description": "Required for autocompletion in the share screen", "access": "readcreate" }, "alarms": { "description": "Required to schedule notifications" } }
  • 14. Vibration API (W3C) Web Activities Screen Orientation Push Notifications API Geolocation API WebFM API Mouse Lock API (W3C) WebPayment Open WebApps IndexedDB (W3C) Network Information API (W3C) Ambient light sensor Battery Status API (W3C) Proximity sensor Alarm API Notification REGULAR APIS
  • 16. 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); }
  • 18. var notification = navigator.mozNotification; notification.createNotification( "See this", "This is a notification", iconURL );
  • 20. // Portrait mode: screen.mozLockOrientation("portrait"); /* Possible values: "landscape" "portrait" "landscape-primary" "landscape-secondary" "portrait-primary" "portrait-secondary" */
  • 22. // Vibrate for one second navigator.vibrate(1000); // Vibration pattern [vibrationTime, pause,…] navigator.vibrate([200, 100, 200, 100]); // Vibrate for 5 seconds navigator.vibrate(5000); // Turn off vibration navigator.vibrate(0);
  • 24. var pay = navigator.mozPay(paymentToken); pay.onsuccess = function (event) { // Weee! Money! };
  • 26. var connection = window.navigator.mozConnection, online = connection.bandwidth > 0, metered = connection.metered;
  • 28. 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); };
  • 29. 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); };
  • 30. navigator.mozSetMessageHandler( "alarm", function (message) { // Note: message has to be set in the manifest file console.log("Alarm fired: " + JSON.stringify(message)); } );
  • 32. 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); });
  • 34. window.addEventListener("devicelight", function (event) { // The level of the ambient light in lux console.log(event.value); });
  • 35. window.addEventListener("lightlevel", function (event) { // Possible values: "normal", "bright", "dim" console.log(event.value); });
  • 36. 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); });
  • 37. Device Storage API Browser API TCP Socket API Contacts API systemXHR PRIVILEGED APIS
  • 39. var deviceStorage = navigator.getDeviceStorage("videos");
  • 40. // "external", "shared", or "default". deviceStorage.type; // Add a file - returns DOMRequest with file name deviceStorage.add(blob); // Same as .add, with provided name deviceStorage.addNamed(blob, name); // Returns DOMRequest/non-editable File object deviceStorage.get(name); // Returns editable FileHandle object deviceStorage.getEditable(name); // Returns DOMRequest with success or failure deviceStorage.delete(name); // Enumerates files deviceStorage.enumerate([directory]); // Enumerates files as FileHandles deviceStorage.enumerateEditable([directory]);
  • 41. 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; } };
  • 43. 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") };
  • 46. { "activities": { "share": { "filters": { "type": ["image/png", "image/gif"] } "href": "sharing.html", "disposition": "window" } } }
  • 47. 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!"); };
  • 51. Resource lock API Spellcheck API UDP Datagram Socket API LogAPI Peer to Peer API Keyboard/IME API WebNFC WebRTC WebUSB FileHandle API HTTP-cache API Sync API Calendar API
  • 54. FIREFOX OS BOILERPLATE APP https://github.com/robnyman/Firefox-OS-Boilerplate-App
  • 58. 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 functions if (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 }
  • 59. 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(); }