• Save
WebAPIs & WebRTC - Spotify/sthlm.js
Upcoming SlideShare
Loading in...5
×
 

WebAPIs & WebRTC - Spotify/sthlm.js

on

  • 1,757 views

 

Statistics

Views

Total Views
1,757
Views on SlideShare
1,693
Embed Views
64

Actions

Likes
6
Downloads
0
Comments
0

1 Embed 64

https://twitter.com 64

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

WebAPIs & WebRTC - Spotify/sthlm.js WebAPIs & WebRTC - Spotify/sthlm.js Presentation Transcript

  • 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 applicationsInstalled Web AppA regular web appPrivileged Web AppMore 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" }}
  • 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
  • BATTERY STATUSAPI
  • 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);
  • SCREENORIENTATION API
  • // Portrait mode:screen.mozLockOrientation("portrait");/* Possible values: "landscape" "portrait" "landscape-primary" "landscape-secondary" "portrait-primary" "portrait-secondary"*/
  • VIBRATION API
  • // 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);
  • 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", { 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 LIGHTEVENTS
  • 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 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.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]);
  • 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; }};
  • 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
  • { "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("Cant view the image!");};
  • Future APIs
  • Resource lock API Spellcheck APIUDP Datagram Socket API LogAPIPeer to Peer API Keyboard/IME APIWebNFC WebRTCWebUSB FileHandle APIHTTP-cache API Sync APICalendar API
  • 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 || 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}
  • 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
  • https://lists.mozilla.org/listinfo/dev-webapps irc://irc.mozilla.org/ #openwebapps
  • Trying things out
  • Robert Nymanrobertnyman.comrobert@mozilla.comMozilla @robertnyman