<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Orbiter Client Snapshot</title> <!--CSS--> <style type="text/css"> #outPane { border: inset 2px; height: 100px; width: 400px; overflow: auto; padding: 5px; margin-bottom: 5px } </style> <!--Load the Orbiter JavaScript library (non-minified version). Use during development.--> <script type="text/javascript" src="http://unionplatform.com/cdn/Orbiter_latest.js"></script> <!--Load the Orbiter JavaScript library (minified version). Use for production.--> <!--<script type="text/javascript" src="http://unionplatform.com/cdn/Orbiter_latest_min.js"></script>--> <!--Application code--> <script type="text/javascript"> //============================================================================== // VARIABLES //============================================================================== var orbiter; var snapshot; var room; //============================================================================== // INITIALIZATION //============================================================================== function init () { // Create the Orbiter instance, used to connect to and communicate with Union, // then enable automatic reconnection (one attempt every 15 seconds) orbiter = new net.user1.orbiter.Orbiter(); orbiter.getConnectionMonitor().setAutoReconnectFrequency(15000); orbiter.getLog().setLevel(net.user1.logger.Logger.DEBUG); // Register for Orbiter's connection events orbiter.addEventListener(net.user1.orbiter.OrbiterEvent.READY, readyListener, this); orbiter.addEventListener(net.user1.orbiter.OrbiterEvent.CLOSE, closeListener, this); displayMessage("Connecting to Union..."); // Connect to Union Server orbiter.connect("tryunion.com", 80); } //============================================================================== // ORBITER EVENT LISTENERS //============================================================================== // Triggered when the connection is established and // Orbiter is ready to communicate with Union Server function readyListener (e) { displayMessage("Connected."); // Join an example room var room = orbiter.getRoomManager().createRoom("examples.clientSnapshotRoom"); room.join(); // For this example, get a snapshot for the current client ("self"), which is // always known to be online. An actual application would normally retrieve // snapshots for foreign clients, such as a member of a contacts list. snapshot = new net.user1.orbiter.snapshot.ClientSnapshot(orbiter.self().getClientID()); snapshot.addEventListener(net.user1.orbiter.snapshot.SnapshotEvent.LOAD, snapshotLoadListener, this); orbiter.updateSnapshot(snapshot); } // Triggered when the connection is closed function closeListener (e) { displayMessage("Disconnected."); } //============================================================================== // SNAPSHOT EVENT LISTENERS //============================================================================== // Triggered when the snapshot data has loaded and is ready for use function snapshotLoadListener (e) { // Display the snapshot's content displayMessage("Snapshot loaded: "); var roomIDs = snapshot.getOccupiedRoomIDs(); displayMessage("Rooms joined: " + roomIDs); } //============================================================================== // UI //============================================================================== // Displays a single message on screen function displayMessage (message) { // Make the new message element var msg = document.createElement("span"); msg.appendChild(document.createTextNode(message)); msg.appendChild(document.createElement("br")); // Append the new message to the output pane var outPane = document.getElementById("outPane"); outPane.appendChild(msg); // Trim the chat to 500 messages if (outPane.childNodes.length > 500) { outPane.removeChild(outPane.firstChild); } outPane.scrollTop = outPane.scrollHeight; } </script> </head> <body onload="init()"> <!--The output pane--> <div id="outPane"></div> </body> </html>