<!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 Occupant List</title> <!--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 chatRoom; var occupantlist; //============================================================================== // 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); // The occupant listbox occupantlist = document.getElementById("occupantlist"); occupantlist.style.width = "120px"; // Connect to Union Server orbiter.connect("tryunion.com", 80); } //============================================================================== // ORBITER EVENT LISTENERS //============================================================================== function readyListener (e) { chatRoom = orbiter.getRoomManager().createRoom("chatRoom"); chatRoom.addEventListener(net.user1.orbiter.RoomEvent.ADD_OCCUPANT, addOccupantListener); chatRoom.addEventListener(net.user1.orbiter.RoomEvent.REMOVE_OCCUPANT, removeOccupantListener); chatRoom.join(); } // Triggered when the connection is closed function closeListener (e) { } //============================================================================== // ROOM EVENT LISTENERS //============================================================================== // Triggered when a client joins the room function addOccupantListener (e) { addListOption("User" + e.getClientID(), e.getClientID()); } // Triggered when a client leaves the room function removeOccupantListener (e) { removeListOption(e.getClientID()); } //============================================================================== // SELECT MANAGEMENT //============================================================================== function addListOption (name, value) { var option; option = document.createElement("option"); option.text = name; option.value = value; occupantlist.add(option); } function removeListOption (value) { for (var i = 0; i < occupantlist.length; i++) { if (occupantlist.options[i].value == value) { occupantlist.remove(i); return; } } } </script> </head> <body onload="init()"> <!--Contains the room occupants--> <select id="occupantlist" size="10" multiple="multiple"> </select> </body> </html>