Phone Server - Audience Interaction

From ETC Public Wiki
Jump to: navigation, search

What is the Phone Server for Audience Interaction?

The phone server is a Node.js/SocketIO based server that guests can send input to (via smartphone, laptop, pc, anything with a browser) that can be accessed from Unity. Creating a phone server world is divided into two parts: the Javascript client and the Unity game. The server itself acts as middleware. You are free to "fork" the code and write your own server AT YOUR OWN RISK (the TAs have committed to supporting the default server, not yours).

Getting Phone Server Setup

Installing Phone Server

These steps are only necessary if you need to setup a server, not to use a setup server

There are a few parts to install for Phone Server:

  1. You'll need Redis. On Linux get the package through your package manager. On windows there are binaries available here: https://github.com/MSOpenTech/redis/tree/2.6/bin/release
  2. Then you'll have to install Node.js. Their site has a big install button.
  3. Drop in the configured server available here: Phone AI Node.js Server
  4. You'll have to update the packages through Node.js via npm install in a cmd window navigated to the server directory.

Running on Phone Server

Luckily, you don't have to do the above to develop on phone server. There is a PC in the platform room on which the server is already setup. If the server is running and no world is running, navigating to http://bvw.mobi/ will display a purple page indicating the phone server is available. If a world is running you'll get their client application which will be closed when you run the command to start your world.

Launch Phone Server

In the case that the server is not already running you'll have to go to the platform room and start it yourself. The process is easy:

  1. Open the Redis server (there should be a link on the desktop)
  2. Open a command line window (Start > Run > "cmd")
  3. Run the command "node [path to node server]" (you can get this path by dragging it from the server folder to the cmd window)

Installing and Launching a Client

To add your client to the server, place a folder with your HTML and Javascript into the world directory of the server (there is a shortcut to this directory on the desktop).

To run your world access: http:/bvw.mobi/admin/run/{your world's folder name} This will disable the currently running world (if applicable), clear the database, and start serving your world. I suggest you include a BAT script with your world's client that starts Redis, Node, and calls your run link so that it can all be done in one step.

Writing a Javascript Client

For the actual client interaction you'll have to create a HTML5 / Javascript application. (Or anything that can talk to Socket.IO).

The sample client has examples of attaching data to the live data object and emitting custom messages.

If your application only needs to emit messages remove the submission of livedata! (Lines 140 to 144 in Sample Client, Lines 94 to 138 can also be removed then) Removing the continuous submission will reduce load on the phone and the server making your application faster. Do not remove livedata if you want to collect real time data such as tilt within Unity.

Clients do not yet have their own asset folder.

Using Phone Server with Unity

Install Unity Packages

Unity has web fetching built in (through WWW) so you will only need to add the SimpleJSON package for parsing the JSON data passed by the phone server.


Scenes

  • '... - This scene shows...

Scripts

  • '... - This is the script that...

Accessing Server Data

There are a few important URLs: /api/live.json and /api/fetch.json and /api/guests.json

/api/live.json

This is the current state of the live data on the server. Fetching this file is non-destructive. Anything you attach to the live data object will show up in here. Each client should only have one live data object representing its state at the moment of the fetch request. Use this for detecting if a button is being pressed now.

/api/fetch.json

This is the backlog of messages on the server. Fetching this file is destructive. Items will be removed from the server when the file is created and sent. Messages will stay on the server until fetched. Use this for detecting if a button has ever been pressed. You can name your messages however you like and consequentially parsing messages is entirely up to you.

/api/guests.json

This is mostly useful for debugging and counting connected clients. Assuming your code follows the connection process in the sample client then your users will submit a JSON dictionary of their browser capabilities to the server which is stored in the db under the key of their socket id.


Update Log

2014 JAN 23 - Added Server Zip 2013 OCT 16 - Rough Outline

Contact

If you have any question or if you are interested in further development, please contact Regis Frey.

Example Client

Phone AI Client Sample

Unity Demo Project

Phone AI Unity Demo

Phone AI Server

Phone AI Node.js Server

External Resource

NodeJS
Socket.IO

This End Up: Device Orientation Tutorial

Modernizr