- Code: Select all
function init () {
orbiter = new net.user1.orbiter.Orbiter();
orbiter.getConnectionMonitor().setAutoReconnectFrequency(15000);
orbiter.getLog().setLevel(net.user1.logger.Logger.DEBUG);
orbiter.addEventListener(net.user1.orbiter.OrbiterEvent.READY, readyListener, this);
orbiter.addEventListener(net.user1.orbiter.OrbiterEvent.CLOSE, closeListener, this);
occupantlist = document.getElementById("occupantlist");
occupantlist.style.width = "100%";
orbiter.connect("tryunion.com", 80);
}
//==============================================================================
// ORBITER EVENT LISTENERS
//==============================================================================
function readyListener (e) {
chatRoom = orbiter.getRoomManager().createRoom("{{Str::slug(Session::get('rescue_name')).'-'.Session::get('org_id')}}");
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) {
}
function addOccupantListener (e) {
addListOption("{{Session::get('first_name')}} {{Session::get('last_name')}}", e.getClientID());
}
function removeOccupantListener (e) {
alert('Elvis has left the building');
removeListOption(e.getClientID());
}
function addListOption (name, value) {
var ul = document.getElementById("occupantlist");
var li = document.createElement("li");
li.setAttribute("id", value);
li.appendChild(document.createTextNode(name));
ul.appendChild(li);
}
function removeListOption (value) {
var elem = document.getElementById(value);
elem.parentNode.removeChild(elem);
}
Thanks and let me know if you can tell me how to create a list of each person logged in.