Websockets and DeviceOrientation on iOS 4.2

Here’s a quick demo I made today. Go to this url on your iOS device and in SAFARI on a PC (OS doesn’t matter, just Safari). Enter the # that you see on your iOS device into the textbox in Safari. Then move the device around and watch the monitor.

I just discovered the DeviceOrientation API today. I’ve been doing Websocket work for a while, but I instantly knew how to merge the two. If someone is good at making canvas games, then this would be a great oppurtunity to use an iOS device as a controller.

http://whoisryannystrom.com/tests/webcontrol/

The code is fairly simple. All it does is send the username, acceleration X, and acceleration Y to whoever is listening. The browser on the PC then calculates the appropriate angles (I didn’t go full 180 degrees because then it would just get wild). The rotateY and rotateX commands were a little funky because they don’t match up to the acceleration x and y values.

There is a lot of potential for what you could do with this new technology.