The WebGL Samples Sync Server


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:

hg clone 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.


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">

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:

    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 == "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

You can kill the aquarium with
~/webglsamples/server/bin/ just passes the URL of the page to which first launches node.js on the main machine and then launches chrome across the 8 LG machines. kills node.js and chrome across machines.