web apis you (probably) didn't know existed

98
web apis you didn’t know existed probably @zenorocha

Upload: zeno-rocha

Post on 06-Jan-2017

151 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: Web APIs you (probably) didn't know existed

web apis you didn’t know

existed

probably

@zenorocha

Page 2: Web APIs you (probably) didn't know existed

2008

Page 3: Web APIs you (probably) didn't know existed

2008

Page 4: Web APIs you (probably) didn't know existed

2009

Page 5: Web APIs you (probably) didn't know existed

2009

Page 6: Web APIs you (probably) didn't know existed

2010

Page 7: Web APIs you (probably) didn't know existed

2010

Page 8: Web APIs you (probably) didn't know existed

2011

Page 9: Web APIs you (probably) didn't know existed

2011

Page 10: Web APIs you (probably) didn't know existed

2012

Page 11: Web APIs you (probably) didn't know existed

2012

Page 12: Web APIs you (probably) didn't know existed

2013

Page 13: Web APIs you (probably) didn't know existed

2013

Page 14: Web APIs you (probably) didn't know existed

2014

Page 15: Web APIs you (probably) didn't know existed

2014

Page 16: Web APIs you (probably) didn't know existed
Page 17: Web APIs you (probably) didn't know existed

canvassvg

geolocation

local storage

web sockets

audio

videodrag & drop

web rtc

Page 18: Web APIs you (probably) didn't know existed

pagevisibility

Page 19: Web APIs you (probably) didn't know existed

Provides an API to ask whether the current page is visible or not.

page visibility

Page 20: Web APIs you (probably) didn't know existed

window.addEventListener('visibilitychange', () => { if (document.hidden) { console.log('Tab is hidden'); } else { console.log('Tab is focused'); }});

page visibility

Page 21: Web APIs you (probably) didn't know existed
Page 22: Web APIs you (probably) didn't know existed

window.addEventListener('visibilitychange', () => { switch(document.visibilityState) { case 'prerender': console.log('Tab is pre-rendering'); break; case 'hidden': console.log('Tab is hidden'); break; case 'visible': console.log('Tab is focused'); break; }});

Page 23: Web APIs you (probably) didn't know existed

caniuse.com/#feat=pagevisibility

BROWSERsupport

Page 24: Web APIs you (probably) didn't know existed

whereto use it?

Page 25: Web APIs you (probably) didn't know existed
Page 26: Web APIs you (probably) didn't know existed

stateonline

Page 27: Web APIs you (probably) didn't know existed

Exposes a network connection availability information to the web.

online state

Page 28: Web APIs you (probably) didn't know existed

console.log(navigator.onLine ? 'online' : 'offline')

online state

Page 29: Web APIs you (probably) didn't know existed

window.addEventListener('offline', networkStatus);window.addEventListener('online', networkStatus);

function networkStatus(e) {console.log(e.type);

}

online state

Page 30: Web APIs you (probably) didn't know existed

caniuse.com/#feat=online-status

BROWSERsupport

Page 31: Web APIs you (probably) didn't know existed
Page 32: Web APIs you (probably) didn't know existed

whereto use it?

Page 33: Web APIs you (probably) didn't know existed
Page 34: Web APIs you (probably) didn't know existed

VIBRATION

Page 35: Web APIs you (probably) didn't know existed

Provides access to a form of tactile feedback.

vibration

Page 36: Web APIs you (probably) didn't know existed

// Vibrate for 1 secondnavigator.vibrate(1000);

// Vibrate with a patternnavigator.vibrate([400, 300, 300, 200, 500]);

// Turn off vibrationnavigator.vibrate(0);

VIBRATION

vibrate wait vibrate wait vibrate

Page 37: Web APIs you (probably) didn't know existed

// Super Marionavigator.vibrate([125,75,125,275,200,275,125,75,125,275,200,600,200,600]);

// Star Warsnavigator.vibrate([500,110,500,110,450,110,200,110,170,40,450,110,200,110,170,40,500]);

// Go Go Power Rangersnavigator.vibrate([150,150,150,150,75,75,150,150,150,150,450]);

VIBRATION

https://goo.gl/bX4ZQv

Page 38: Web APIs you (probably) didn't know existed

caniuse.com/#feat=vibration

BROWSERsupport

Page 39: Web APIs you (probably) didn't know existed

whereto use it?

Page 40: Web APIs you (probably) didn't know existed
Page 41: Web APIs you (probably) didn't know existed
Page 42: Web APIs you (probably) didn't know existed

DEVICEorientation

Page 43: Web APIs you (probably) didn't know existed

Provides access to device's physical orientation.

device orientation

Page 44: Web APIs you (probably) didn't know existed

device orientationwindow.addEventListener('deviceorientation', (e) => { console.log(‘Gamma:’, e.gamma); console.log(‘Beta:’, e.beta); console.log(‘Alpha:’, e.alpha);});

Page 45: Web APIs you (probably) didn't know existed

device orientationlet logo = document.querySelector(‘img');

window.addEventListener('deviceorientation', (e) => { let tiltLR = e.gamma; let tiltFB = e.beta;

logo.style.transform = `rotate(${tiltLR}deg) rotate3d(1,0,0, ${tiltFB * -1}deg)`;});

Page 46: Web APIs you (probably) didn't know existed
Page 47: Web APIs you (probably) didn't know existed

caniuse.com/#feat=deviceorientation

BROWSERsupport

Page 48: Web APIs you (probably) didn't know existed

whereto use it?

Page 49: Web APIs you (probably) didn't know existed
Page 50: Web APIs you (probably) didn't know existed

clipboardcopy & paste

Page 51: Web APIs you (probably) didn't know existed

Standard APIs for interacting with the clipboard (copy/cut/paste).

clipboard

Page 52: Web APIs you (probably) didn't know existed
Page 53: Web APIs you (probably) didn't know existed

// 1. User interaction is required

let button = document.querySelector('button');

button.addEventListener('click', () => { select(); copy();});

clipboard

Page 54: Web APIs you (probably) didn't know existed

// 2. Programmatically select an element

function select() { let input = document.querySelector('input');

input.focus(); input.setSelectionRange(0, input.value.length);}

clipboard

Page 55: Web APIs you (probably) didn't know existed

// 3. Copy selected element text

function copy() { try { document.execCommand('copy'); } catch (err) { console.error(err); }}

clipboard

Page 56: Web APIs you (probably) didn't know existed

document.addEventListener('copy', (e) => { console.log(e.target.value);});

document.addEventListener('cut', (e) => { console.log(e.target.value);});

document.addEventListener('paste', (e) => { console.log(e.clipboardData.getData('text/plain'));});

clipboard

Page 57: Web APIs you (probably) didn't know existed
Page 58: Web APIs you (probably) didn't know existed
Page 59: Web APIs you (probably) didn't know existed

caniuse.com/#feat=clipboard

BROWSERsupport

Page 60: Web APIs you (probably) didn't know existed

whereto use it?

Page 61: Web APIs you (probably) didn't know existed
Page 62: Web APIs you (probably) didn't know existed
Page 63: Web APIs you (probably) didn't know existed

lightambient

Page 64: Web APIs you (probably) didn't know existed

Exposes sensor data that captures the light intensity.

ambient light

Page 65: Web APIs you (probably) didn't know existed

window.addEventListener('devicelight', (e) => { console.log(`${e.value} lux`);});

ambient light

Page 66: Web APIs you (probably) didn't know existed
Page 67: Web APIs you (probably) didn't know existed
Page 68: Web APIs you (probably) didn't know existed

let sensor = new AmbientLightSensor();

sensor.start();

sensor.onchange = (e) => { console.log(e.reading.illuminance);};

sensor.stop();

ambient light sensor

Page 69: Web APIs you (probably) didn't know existed

BROWSER

caniuse.com/#feat=ambient-light

support

Page 70: Web APIs you (probably) didn't know existed

whereto use it?

Page 71: Web APIs you (probably) didn't know existed
Page 72: Web APIs you (probably) didn't know existed
Page 73: Web APIs you (probably) didn't know existed

STATUSbattery

Page 74: Web APIs you (probably) didn't know existed

Allows a web page to access battery information from desktop and mobile devices.

battery status

Page 75: Web APIs you (probably) didn't know existed

navigator.getBattery().then((battery) => { console.log(`${battery.level * 100}%`);

battery.addEventListener('levelchange', () => { console.log(`${this.level * 100}%`); });});

battery status

Page 76: Web APIs you (probably) didn't know existed

caniuse.com/#feat=battery-status

BROWSERsupport

Page 77: Web APIs you (probably) didn't know existed

whereto use it?

Page 78: Web APIs you (probably) didn't know existed
Page 79: Web APIs you (probably) didn't know existed
Page 80: Web APIs you (probably) didn't know existed

web components

templates

custom elements

shadow domhtml imports

Page 81: Web APIs you (probably) didn't know existed

progressive web apps

service workers

push notificationsoffline support

app manifest

background sync

Page 82: Web APIs you (probably) didn't know existed

WEBassembly

Page 83: Web APIs you (probably) didn't know existed

WebAssembly, or wasm, is a low-level programming language for the client-side.

web assembly

Page 84: Web APIs you (probably) didn't know existed

under development

BROWSERsupport

Page 85: Web APIs you (probably) didn't know existed
Page 86: Web APIs you (probably) didn't know existed

WEBVR

Page 87: Web APIs you (probably) didn't know existed

Experimental API that provides access to Virtual Reality devices, such as the Oculus Rift or Google Cardboard.

web VR

Page 88: Web APIs you (probably) didn't know existed

BROWSERsupportchromestatus.com/features#webvr

Page 89: Web APIs you (probably) didn't know existed
Page 90: Web APIs you (probably) didn't know existed

gamepad

Page 91: Web APIs you (probably) didn't know existed

Gives access to a game controller via USB.

gamepad

Page 92: Web APIs you (probably) didn't know existed

window.addEventListener('gamepadconnected', () => { let gp = navigator.getGamepads()[0];

console.log(‘ID:’, gp.id); console.log(‘Axes:’, gp.axes.length); console.log(‘Buttons:’, gp.buttons.length);});

gamepad

Page 93: Web APIs you (probably) didn't know existed

window.addEventListener('gamepadconnected', gameLoop);

function gameLoop() { let gp = navigator.getGamepads()[0];

if (gp.buttons[0].pressed) { console.log('X'); }

requestAnimationFrame(gameLoop);}

game loop

Page 94: Web APIs you (probably) didn't know existed
Page 95: Web APIs you (probably) didn't know existed

caniuse.com/#feat=gamepad

BROWSERsupport

Page 96: Web APIs you (probably) didn't know existed
Page 97: Web APIs you (probably) didn't know existed
Page 98: Web APIs you (probably) didn't know existed

thank you

@zenorochaso much