Permalink
Browse files

Added demo of the vibration API

  • Loading branch information...
1 parent 6d44881 commit 644db780dd195d78167ca5b40a00c34c4205342a trygve committed Mar 8, 2012
Showing with 59 additions and 0 deletions.
  1. +27 −0 src/www/remote_vibration/receiver.html
  2. +32 −0 src/www/remote_vibration/remote.html
@@ -0,0 +1,27 @@
+<!document html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, maximum-scale=1.0">
+ <title>Remote Vibration - Receiver</title>
+ <script>
+ var ws = new WebSocket( 'ws://' + window.location.host );
+
+ ws.onmessage = function( obj ){
+
+ if ( typeof obj.data !== 'object' ) {
+ var dataObj = JSON.parse( obj.data );
+ if (dataObj.demo.type === "vibrate") {
+ navigator.mozVibrate( Math.max( dataObj.demo.x, dataObj.demo.y, dataObj.demo.z ) * 10 );
+ }
+ }
+
+ };
+
+ window.addEventListener('DOMContentLoaded', load, false);
+ </script>
+ </head>
+ <body>
+ <h1>Remote vibration</h1>
+ </body>
+</html>
@@ -0,0 +1,32 @@
+<!doctype html>
+<html>
+<head>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, maximum-scale=1.0">
+ <title>Remote Vibration - Remote</title>
+ <script>
+ var ws = new WebSocket( 'ws://' + window.location.host );
+
+ var el;
+
+ function onShake (event){
+ var acceleration = {"demo" : {
+ type : "vibrate",
+ x : Math.abs( event.acceleration.x ),
+ y : Math.abs( event.acceleration.y ),
+ z : Math.abs( event.acceleration.z )
+ }};
+
+ if ( ( acceleration.demo.x || acceleration.demo.y || acceleration.demo.z ) > 9 ){
+ ws.send( JSON.stringify( acceleration ) );
+ }
+ }
+
+ window.addEventListener('devicemotion', onShake, true);
+ </script>
+</head>
+<body>
+ <h1>Remote vibration</h1>
+ <p>Shake your device to send remote vibration...</p>
+</body>
+</html>

0 comments on commit 644db78

Please sign in to comment.