[SOLVED] Leave a Room & Responses in JS

All Union Platform questions, comments, feature requests, and bug reports.

Leave a Room & Responses in JS

Postby jream » Fri 30 Nov 2012 15:48

Hey Guys,

I have a question about leaving a room and responses. I'm using the JS framework and wondering how to leave a room, eg:


Code: Select all
// I have a room called Test Room I can see via UnionAdmin, and I call this but Its not correct:
orbiter.getRoomManager().leave('Test Room');


I also didn't understand how to get the results of an event, because the leave() method returns void, but there are these constants:
http://unionplatform.com/docs/orbiter/a ... AVE_RESULT

Is there a common method for fetch leave.leave_result(), or any result for that matter, eg:
orbiter.getClassName().result(CONSTANT);


Thanks
Jesse
jream
 
Posts: 19
Joined: Thu 16 Aug 2012 15:33

Re: Leave a Room & Responses in JS

Postby jream » Wed 05 Dec 2012 16:51

I figured it out.

Everything ties into the events, so I create a room:

Create a room (Once orbiter is instantiated)
Code: Select all
orbiter.getRoomManager().createRoom('fake');


Call methods on the room:
Code: Select all
var thisRoom = $.orbiter.getRoomManager().getRoom('fake');
var occupants = thisRoom.getNumOccupants();

Handling the Events, each section has its own Object of Events, so Room/RoomEvent, RoomManager/RoomManagerEvent

Code: Select all
orbiter.getRoomManager().addEventListener(net.user1.orbiter.RoomManagerEvent.ROOM_REMOVED, roomRemovedListener, this);


or

Code: Select all
roomInstance.addEventListener(net.user1.orbiter.RoomEvent.JOIN, function(e) {
    $("#chat-box .posted-messages").html('<p>Connected to chat..</p>');
});
jream
 
Posts: 19
Joined: Thu 16 Aug 2012 15:33

Re: Leave a Room & Responses in JS  

Postby colin » Sat 08 Dec 2012 14:01

hi jream,
to leave a room:
Code: Select all
orbiter.getRoomManager().getRoom("YourRoomID").leave();


as you discovered, most of the Orbiter and OrbiterMicro APIs are event-listener based, not event-callback based, so you write most event code like this:

Code: Select all
someObject.addEventListener(eventName, listenerFunction, optionalThisArg);


where someObject is the object that dispatches the event (e.g., Room), eventName is the string name of the event (normally a constant such as net.user1.orbiter.RoomEvent.LEAVE), listenerFunction is the function you want to run when the event occurs, and optionalThisArg is the object on which you want listenerFunction invoked.

for the record, your example:
Code: Select all
roomInstance.addEventListener(net.user1.orbiter.RoomEvent.JOIN, function(e) {
    $("#chat-box .posted-messages").html('<p>Connected to chat..</p>');
});


is perfectly valid. registering an inline anonymous function and no "this arg" (as in the preceding JOIN example) is a common way to code when you don't ever want to remove your event listener.

colin
colin
 
Posts: 232
Joined: Mon 17 Oct 2011 18:47


Return to Union Platform

Online

Users browsing this forum: No registered users and 1 guest