The WebGL Samples Sync Server

Description

This is a very simple server written entirely in JavaScript using node.js. It serves the resources to the browser like a normal webserver as well as provides a WebSocket based server to keep various settings in sync across machines. The WebSocket parts of the server are implemented using WebSocket-Node.

Starting the server

The server is meant to be run from the root folder of the samples. Assuming the samples were installed with:

cd
hg clone https://webglsamples.googlecode.com/hg/ webglsamples

You would run the server with:

cd ~/webglsamples
node server/server.js --port 8080

or any open port. At that point you can run any of the samples by going to http://address_of_server:8080/path_to_sample. For example if you are running a browser on the same machine you should be able to go to http://localhost:8080/aquarium/aquarium.html.

Syncing

Usage for syncing settings is fairly straight forward. Using tdl.sync, create a SyncManager

<script type="text/javascript" src="../tdl/base.js"></script>
<script type="text/javascript">
tdl.require('tdl.sync');

var objectToKeepInSync = {};
g_syncManager = new tdl.sync.SyncManager(objectToKeepInSync);
g_syncManager.init(serverURL, slave);

where objectToKeepInSync is a JavaScript object that will contain the various settings you want to keep in sync. slave is a true if this browser instance is a slave or false if it is the master.

After that you can send settings with SyncManager.setSettings(settings). Example:

g_syncManager.setSettings({
    foo: { a: 123, b: "hello" },
    bar: { d: 4.5 },
    baf: 789
  });

Those settings will automatically propogate to all browsers so inspecting objectsToKeepInSync will show that for example objectToKeepInSync.foo.b == "hello"

Note that if you do not call SyncManager.init then settings will be set locally only which means you don't have to change any code for a synced vs local version.

Working Example

The Aquarium uses this syncing method for a working example.

Running the Aquarium on Liquid Galaxy

If you have a Liquid Galaxy setup, assuming the files in trunk/gnu_linux/home/lg/bin are in your path, and assuming you have Chrome unzipped in ~/chrome/chrome-linux, you can run the aquarium with

~/webglsamples/server/bin/run-aquarium.sh
You can kill the aquarium with
~/webglsamples/server/bin/kill-app.sh

run-aquarium.sh just passes the URL of the page to run-chrome-across-machines.sh which first launches node.js on the main machine and then launches chrome across the 8 LG machines. kill.app.sh kills node.js and chrome across machines.