DeviceOrientationEvent - Demo
This is a demo of the deviceorientation event API as defined by W3C.
What does the demo do?
The demo uses the deviceorientation event API to collect orientation data on the iPhone. The data is sent to a mirror-server using websockets. The data is then used to move an
#image or a
#cursor in the browser (you will need to manually edit the code to switch between an image or a cursor). The image used is melbjs's logo.
- The demo is built to run with Chrome on Mac OSX Mountain Lion and an iPhone 4. I haven't extensively tested it on other browsers or devices, but it should still work… let me know how you go @hadi_michael.
- Both devices need to share the same wireless network.
- Port :3000 should not be blocked by your router or firewall - if it is, modify server.js to listen on a different (available) port.
- Download and install node.js from: http://nodejs.org/.
- Once you have node, use the "node package manager" in terminal to install "express" using
$ npm install expressand "socket.io" using
$ npm install socket.io.
Read about the packages used:
This demo also uses jQuery.
Running the demo
- In terminal, start the server:
$ node /path/to/server.js
- In Chrome, navigate to:
http://localhost:3000- if you have replaced the port number in server.js, then replace it here as well.
- Connect to the server in Safari on your iPhone by navigating to
my.macs.ip.address:3000. If you're on a small local home network, it is likely that your IP address will be something like
192.168.0.1. If you don't know it, use
$ ifconfigto get it.
Copyright (C) 2012 Hadi Michael
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.