Your SlideShare is downloading. ×
 	Bringing the open web and APIs to mobile devices with Firefox OS - Whisky Web, Scotland
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

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

1,022
views

Published on

Published in: Technology, Design

0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,022
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
21
Comments
0
Likes
5
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Bringing the Open Web & APIs to mobile devices with Firefox OS
  • 2. @robertnyman
  • 3. Firefox OS Using HTML5, CSS and JavaScript together with a number of APIs to build apps and customize the UI.
  • 4. Open Web Apps
  • 5. https://developer.mozilla.org/docs/Apps/Getting_Started
  • 6. Steps to Take
  • 7. Develop Web App using1. HTML5, CSS, & Javascript2. Create an app manifest file3. Publish/install the app
  • 8. 1.Develop Web App usingHTML5, CSS & JavaScript
  • 9. 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.
  • 10. 2.Create an app manifest file
  • 11. Create a file with a .webapp extension
  • 12. { "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 difotoricettore!", "developer": { "url": "http://it.mozillalabs.com/" } } }, "default_locale": "en"}
  • 13. MANIFEST CHECKER http://appmanifest.org/
  • 14. Serve with Content-type/MIME type:application/x-web-app-manifest+json
  • 15. Apache - in mime.types:application/x-web-app-manifest+json webappApache - in .htaccess:AddType application/x-web-app-manifest+json webappNGinx - in mime.types:types { text/html html htm shtml; text/css css; text/xml xml; application/x-web-app-manifest+json webapp;}
  • 16. IIS:In IIS Manager, right-click the localcomputer, and click Properties.Click the MIME Types button.Click New.In the Extension box, type the file nameextension.In the MIME type box, type a descriptionthat exactly matches the file type definedon the computer.Click OK.
  • 17. curl -I http://mozillalabs.com/manifest.webapp
  • 18. 3.Publish/install the app
  • 19. Firefox Marketplace
  • 20. https://marketplace.firefox.com/
  • 21. https://marketplace.firefox.com/developers/
  • 22. Installing/hosting the app
  • 23. 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}
  • 24. Packaged vs. Hosted Apps
  • 25. 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.
  • 26. Can be privileged apps with more API access than hosted appsResources are accessed from the zip file, which is stored on the device where theapp is installed)Enforce a specific Content Security Policy for all application contentCan embed remote content in iframes, but that content will not have access toprivileged APIs nor will it have the default CSP applied to it
  • 27. https://developer.mozilla.org/docs/Apps/ For_Web_developers
  • 28. WebAPIs
  • 29. https://wiki.mozilla.org/WebAPI
  • 30. Security Levels
  • 31. Web Content Certified Web AppRegular web content Device-critical applicationsInstalled Web AppA regular web appPrivileged Web AppMore access, more responsibility
  • 32. https://wiki.mozilla.org/WebAPI#Planned_for_initial_release_of_B2G_. 28aka_Basecamp.29
  • 33. "permissions": { "contacts": { "description": "Required for autocompletion in the share screen", "access": "readcreate" }, "alarms": { "description": "Required to schedule notifications" }}
  • 34. PERMISSIONS
  • 35. 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
  • 36. BATTERY STATUSAPI
  • 37. 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);}
  • 38. NOTIFICATION
  • 39. var notification = navigator.mozNotification;notification.createNotification( "See this", "This is a notification", iconURL);
  • 40. SCREENORIENTATION API
  • 41. // Portrait mode:screen.mozLockOrientation("portrait");/* Possible values: "landscape" "portrait" "landscape-primary" "landscape-secondary" "portrait-primary" "portrait-secondary"*/
  • 42. VIBRATION API
  • 43. // 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);
  • 44. WEB PAYMENTS
  • 45. var pay = navigator.mozPay(paymentToken);pay.onsuccess = function (event) { // Weee! Money!};
  • 46. NETWORKINFORMATION API
  • 47. var connection = window.navigator.mozConnection, online = connection.bandwidth > 0, metered = connection.metered;
  • 48. DEVICEPROXIMITY
  • 49. 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);});
  • 50. AMBIENT LIGHTEVENTS
  • 51. window.addEventListener("devicelight", function (event) { // The level of the ambient light in lux console.log(event.value);});
  • 52. window.addEventListener("lightlevel", function (event) { // Possible values: "normal", "bright", "dim" console.log(event.value);});
  • 53. 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);});
  • 54. Device Storage APIBrowser APITCP Socket APIContacts APIsystemXHR PRIVILEGED APIS
  • 55. DEVICE STORAGEAPI
  • 56. var deviceStorage = navigator.getDeviceStorage("videos");
  • 57. // "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]);
  • 58. 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; }};
  • 59. CONTACTS API
  • 60. 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")};
  • 61. WebTelephony WebBluetoothWebSMS Permissions APIIdle API Network Stats APISettings API Camera APIPower Management API Time/Clock APIMobile Connection API Attention screenWiFi Information API Voicemail CERTIFIED APIS
  • 62. WEBTELEPHONY
  • 63. // 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);
  • 64. // Place a callvar cal = tel.dial(“123456789”);
  • 65. // 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 theirchanged statustel.oncallschanged = function (event) { tel.calls.forEach(function (call) { // Log the state of each call console.log(call.state); });};
  • 66. WEBSMS
  • 67. // SMS objectvar sms = navigator.mozSMS;// Send a messagesms.send("123456789", "Hello world!");
  • 68. // Recieve a messagesms.onreceived = function (event) { // Read message console.log(event.message);};
  • 69. WEB ACTIVITIES
  • 70. { "activities": { "share": { "filters": { "type": ["image/png", "image/gif"] } "href": "sharing.html", "disposition": "window" } }}
  • 71. 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!");};
  • 72. var register = navigator.mozRegisterActivityHandler({ name: "view", disposition: "inline", filters: { type: "image/png" }});register.onerror = function () { console.log("Failed to register activity");}
  • 73. 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});
  • 74. Future APIs
  • 75. Resource lock API Spellcheck APIUDP Datagram Socket API LogAPIPeer to Peer API Keyboard/IME APIWebNFC WebRTCWebUSB FileHandle APIHTTP-cache API Sync APICalendar API
  • 76. Web Apps from Mozilla
  • 77. Dialer Alarm ClockContacts CameraSettings NotesSMS First Run ExperienceWeb browser NotificationsGallery Home ScreenVideo Player Mozilla MarketplaceMusic Player System UpdaterE-mail (POP, IMAP) Localization SupportCalendar
  • 78. https://hacks.mozilla.org/2013/01/hacking-gaia-for-firefox- os-part-1/
  • 79. Get started
  • 80. https://addons.mozilla.org/firefox/addon/firefox-os- simulator/
  • 81. FIREFOX OS BOILERPLATE APPhttps://github.com/robnyman/Firefox-OS-Boilerplate-App
  • 82. WebRTC
  • 83. 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}
  • 84. 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();}
  • 85. Getting help
  • 86. https://lists.mozilla.org/listinfo/dev-webapps irc://irc.mozilla.org/ #openwebapps
  • 87. Trying things out
  • 88. Robert Nymanrobertnyman.comrobert@mozilla.comMozilla @robertnyman