26. Everything changes...
We want ...
... access to hardware features
... access Calendar, Addressbook
etc.
We got it!
But: Lessons learned from the past
Standards!
35. Definition
“WebAPI is a term used to refer to a suite of device
compatibility and access APIs that allow Web apps
and content to access device hardware (such as
battery status or the device vibration hardware), as
well as access to data stored on the device (such as
the calendar or contacts list).
By adding these APIs, we hope to expand what the
Web can do today and only proprietary platforms
were able to do in the past.”
43. Network Connection
Information about the system's connection
varconnection=navigator.connection||
navigator.mozConnection||
navigator.webkitConnection;
vartype=connection.type;
functionupdateConnectionStatus(){
console.log("Connectiontypeischangefrom"+type+"to"+connection.type);
type=connection.type;
}
connection.addEventListener('typechange',updateConnectionStatus);
Firefox 12+, Firefox Mobile, Firefox OS, Android 2.2+
44. IndexedDB
“IndexedDB is an API for client-side storage of
significant amounts of structured data and for high
performance searches on this data using indexes. ”
NoSQL DB for Browsers...
Deserves an own talk... too complex for this one...
Supported by: Every major Browser on Desktop and every major mobile
browser ...
... excepted: Safari on iOS < 8
46. Light Events
Get current ambient light intensity
window.ondevicelight=function(event){
//Readouttheluxvalue
console.log(event.value);
};
Current lux: 0
Desktop: Firefox 22+
Mobile: Firefox Mobile
47. Battery Status
Information about the system's battery charge level and lets you be
notified by events that are sent when the battery level changes
varbattery=navigator.battery||
navigator.mozBattery||
navigator.webkitBattery,
info={
charging:battery.charging,
chargingTime:parseInt(battery.chargingTime/60,10),
dischargingTime:parseInt(battery.dischargingTime/60,10),
level:Math.round(battery.level*100)
};
functionupdateBatteryStatus(){
batterylevel.innerHTML=battery.level*100+"%";
batterystatus.innerHTML=battery.charging?"":"not";
}
battery.addEventListener("chargingchange",updateBatteryStatus);
battery.addEventListener("levelchange",updateBatteryStatus);
Battery: Level is and it's charging.
Desktop: Firefox 10+ Mobile: Firefox Mobile 10+
48. Proximity Events
The proximity events are a handy way to know when a user is close to a
device
window.addEventListener('userproximity',function(event){
if(event.near){
console.log('Phoneprobablyonusersear...');
}else{
console.log('phoneinyourhand...');
}
});
49. Detecting device orientation
Detection orientation and motion events
window.addEventListener("deviceorientation",handleOrientation,true);
functionhandleOrientation(event){
varalpha =event.alpha;//Z-Axis
varbeta =event.beta;//Y-Axis
vargamma =event.gamma;//X-Axis
//Dostuffwiththeneworientationdata
}
window.addEventListener("devicemotion",handleMotion,true);
functionhandleMotion(event){
varx=event.accelerationIncludingGravity.x;
vary=event.accelerationIncludingGravity.y;
varz=event.accelerationIncludingGravity.z;
varr=event.rotationRate;
}
Information about the speed of changes for the device's position and
orientation.
Desktop: Chrome 7+, 3.6+
Mobile: Android 3.0, Firefox Mobile 3.6+, Safari Mobile 4.2+
50. Vibration API
Rumble in your pocket!
varpattern=[200,100,200,200,100],
goodVibration=navigator.vibrate(pattern);
Mobile: Android, Firefox Mobile 11+
52. Pointer Lock
Request pointer lock on an element
canvas.requestPointerLock=canvas.requestPointerLock||
canvas.mozRequestPointerLock||
canvas.webkitRequestPointerLock;
canvas.requestPointerLock();
Listen for changes
document.addEventListener('pointerlockchange',lockChangeAlert,false);
document.addEventListener('mozpointerlockchange',lockChangeAlert,false);
document.addEventListener('webkitpointerlockchange',lockChangeAlert,false);
Exit pointer lock
document.exitPointerLock=document.exitPointerLock ||
document.mozExitPointerLock||
document.webkitExitPointerLock;
//Attempttounlock
document.exitPointerLock();
Desktop: Chrome, Firefox
53. Page visibility
The Page Visibility API lets you know when a webpage is visible or in
focus
if(document.hidden){
//stopvideoetc.
}
document.addEventListener("visibilitychange",handleVisibilityChange,false);
functionhandleVisibilityChange(){
if(document.hidden){
//stopsomething.e.g.stopavideo,audioetc...
}else{
//dosomethingelse;)playvideo,audio...yougotit?
}
}
Currently prefixed (moz, webkit, ms)
Desktop: Chrome, Firefox 30+, Safari 7+, Opera 24+, IE10+
Mobile: Chrome Android, Android 4.4+, Firefox Mobile, Firefox OS