On Github monteslu / phxjs2015
navigator.getUserMedia(constraints, successCallback, errorCallback);
function success(stream) { var video = document.querySelector('video'); video.src = window.URL.createObjectURL(stream); video.onloadedmetadata = function(e) { // Do something with the video here. }; }
navigator.geolocation.getCurrentPosition(myCallback);
window.addEventListener("deviceorientation", handleOrientation, true);
var myContext = new AudioContext();
var five = require("johnny-five"); var board = new five.Board(); board.on("ready", function() { var led = new five.Led(13); // "blink" the led in 500ms on-off phase periods led.blink(500); });
navigator.bluetooth;
<link rel="manifest" href="/manifest.json">
{ "short_name": "Luis's Amaze App", "name": "Luis's magic unicorn app.", "icons": [ { "src": "launcher-icon-2x.png", "sizes": "96x96", "type": "image/png" }, ... ], "start_url": "/index.html", "display": "standalone", "orientation": "landscape" }
if ('serviceWorker' in navigator) { navigator.serviceWorker.register('myServiceWorker.js') .then(function(reg) { console.log('Yey serivceworker!', reg); }).catch(function(err) { console.log('Boo no serviceWorker!', err); }); }
self.addEventListener('install', function(event) { event.waitUntil( caches.open('static-v1') .then(function(cache) { return cache.addAll([ '/', '/myScript.js', '/css/styles.css', new Request('//storage.googleapis.com/code.getmdl.io/1.0.4/material.indigo-pink.min.css', {mode: 'no-cors'}) ]); }) ); });
self.addEventListener('fetch', function(event) { event.respondWith( caches.match(event.request).then(function(response) { return response || fetch(event.request); }) ); });
"gcm_sender_id": "123456789012", "gcm_user_visible_only": true
if ('serviceWorker' in navigator) { navigator.serviceWorker.register('myServiceWorker.js') .then(function(registration) { return registration.pushManager.subscribe({userVisibleOnly: true}); }) .then(function(subscription){ isPushEnabled = true; sendSubscriptionToServer(subscription); }); }
self.addEventListener('push', function(event) { var title = 'Yay a message.'; var body = 'We have received a push message.'; var icon = '/images/icon-192x192.png'; var tag = 'simple-push-demo-notification-tag'; event.waitUntil( self.registration.showNotification(title, { body: body, icon: icon, tag: tag }) ); });