Node.js WebSocket Example

by adrianbautista

GitHub Readme.md

Background

A simple Node.js Express application that allows users to send their browser's deviceOrientation data using WebSockets. Other Websocket connected clients (e.g. an OpenFrameWorks application or Processing sketch) can then receive a collection of those orientation values for input use.

Try it out

Deploy

The original version of this repository that forwarded the WebSocket data as OSC messages can be found on the osc-server branch.

screenshot

Getting Started

  1. Clone the repo

  2. Install dependencies

npm install
  1. Check (and if needed change) the UDP_PORT and WEB_SOCKET_PORT values in app.js

  2. Start the server

npm start
  1. Visit the site on localhost:3000 in your web browser (note*: the Firefox desktop browser has deprecated the deviceorientation sensor)

  2. Start moving!

Variables

The interval at which the store of user device data is emitted back can be changed through an environment variable when starting the application:

USERS_INTERVAL=150 npm start

The interval at which a client (e.g. phone web browser) sends the orientation data to the server can be changed by changing the DEVICE_INTERVAL variable in public/browser.js.