Carsten Sandtner (@casarock) 2014 - muxCamp Worms 2014
Carsten Sandtner
Head of Development at //mediaman GmbH
Mozilla representative
Javascript enthusiast and web developer since 1998.
The full Safari engine is inside of iPhone. And so, you can write amazing Web 2.0 and Ajax apps that look exactly and behave exactly like apps on the iPhone. And these apps can integrate perfectly with iPhone services. They can make a call, they can send an email, they can look up a location on Google Maps. And guess what? There’s no SDK that you need!
Invented by Palm. Aimed at smartphones and tablets.
A Linux distribution where Google Chrome is the "UI" layer
Not the OS, but First Class Apps in HTML5.
Fully open mobile operating system based on web standards
Low level OS of Firefox OS. Linux based on Android Open SourceProject
Well known rendering engine by Mozilla
UI level of Firefox OS
Only interface to the underlying operating system and hardware
Every HTML5, Javascript, CSS based Apps for Firefox OS
Using WebAPIs and Web Activities
Just Open Web Apps
Definition in webapp.manifest
{
"name": "My Awesome App",
"description": "My elevator pitch goes here",
"launch_path": "/",
"icons": {
"128": "/img/icon-128.png"
},
"developer": {
"name": "Your Name",
"url": "http://your-homepage-here.tld"
},
"default_locale": "en"
}
{
"name": "My Awesome Privileged App",
....
"type": "privileged",
"fullscreen": "true",
"permissions": {
"contacts": {
"description": "Required for autocompletion in the share screen",
"access": "readcreate"
}
},
"default_locale": "en",
...
}
Open API specifications to access the hardware of devices
Created with and submitted to standards bodies and other browser makers
Secured by three layer security model
Example: Battery API
var battery = navigator.battery,
info = {
charging: battery.charging,
chargingTime: parseInt(battery.chargingTime / 60, 10),
dischargingTime: parseInt(battery.dischargingTime / 60, 10),
level: Math.round(battery.level * 100)
};
navigator.geolocation.getCurrentPosition(handleLocation);
function handleLocation(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
/*
coords.altitude
coords.accuracy
coords.altitudeAccuracy
coords.heading
coords.speed
timestamp
*/
}
*Ok, ok, not really a new one!
var pattern = [200, 100, 200, 200, 100],
vibrating = navigator.vibrate(pattern);
Needs permissions granted by users! (e.g. webapp.manifest)
"permissions": {
"desktop-notification": {
"description": "Allows to display notifications on the user's desktop."
}
}
// At first, let's check if we have permission for notification
// If not, let's ask for it
if (Notification && Notification.permission !== "granted") {
Notification.requestPermission(function (status) {
if (Notification.permission !== status) {
Notification.permission = status;
}
});
}
if (Notification && Notification.permission === "granted") {
var n = new Notification("Hi!");
}
Get information about current connection
var connection = window.navigator.mozConnection,
data = {
online: connection.bandwidth,
metered: connection.metered
}
Get current Lux of ambient light
var resElement = document.querySelector("#results");
window.ondevicelight = function (event) {
// Read out the lux value
var lux = event.value;
};
Read/Write/Delete Contacts - Permission required!
"permissions": {
"contacts":{
"description": "Contacts permissions is required to write contact from Google to your Firefox OS phone",
"access": "readwrite" }
}
}
var contactData = {
givenName: ["John"],
familyName: ["Doe"]
};
var person = new mozContact(contactData); // Firefox OS 1.3 takes a parameter
// save the new contact
var saving = navigator.mozContacts.save(person);
saving.onsuccess = function() {
console.log('new contact saved');
};
saving.onerror = function(err) {
console.error(err);
};
Save/Read from sdcard, photo, music, video ...
"permissions": {
"device-storage:pictures":{ "access": "readwrite" },
"device-storage:sdcard":{ "access": "readwrite" }
}
var sdcard = navigator.getDeviceStorage("sdcard"),
file = new Blob(["This is a text file."], {type: "text/plain"}),
request = sdcard.addNamed(file, "my-file.txt");
request.onsuccess = function () {..}
request.onerror = function () {..}
var pics = navigator.getDeviceStorage('pictures');
// browse all the images available
var cursor = pics.enumerate();
cursor.onsuccess = function () {
var file = this.result;
console.log("File found: " + file.name);
// check if there is other results
if (!this.done) {
// Then we move to the next result, which call the cursor
// success with the next file as result.
this.continue();
}
}
New ones: f.e type: “websms/sms” or “webcontacts/contact”
var getphoto = new MozActivity({
name: "pick",
data: {
type: ["image/png",
"image/jpg",
"image/jpeg"]
}
});
getphoto.onsuccess = function() {
var img = document.createElement("img");
if (this.result.blob.type.indexOf("image") != -1) {
img.src = window.URL.createObjectURL(this.result.blob);
}
};
getphoto.onerror = function() { // error
};
Carsten Sandtner
@casarock