powered by Jive Software

Simple Example of Joining a Room?

Does anyone have a simple example of joining a room? assuming that I know the room name?

Also, are there any docs for the project? All I can find are the old AS2 docs, which appear to be out of date.

mike

I’ve been working with XIFF quite a bit lately, but here is an example:

xmpp = new XMPPSocketConnection();
room = new Room(xmpp);
xmpp.username = "username";
xmpp.password = "password";
xmpp.server   = "jabber.server.com";
xmpp.connect("standard");

Then after receiving the login event:

room.roomJID = new JID("someroom@conference.jabber.server.com");
room.join();

Then that will fire a RoomEvent.ROOM_JOIN on a successful connect.

Thanks, that makes sense, but the build of the library I have (3.0.0-beta1) which is link from the site, shows the join api with the following signature:

public function join( createReserved:Boolean = false, joinPresenceExtensions:Array = null ):Boolean

i.e. it takes a Boolean and not a JID.

Any suggestions? Do I have an old build (this is the one linked from the XIFF page).

mike

public function join( createReserved:Boolean = false, joinPresenceExtensions:Array = null ):Boolean

Notice the “= false” and “= null” ?

They are optional arguments. Just leave them blank.

But if I leave them blank, how do I specify the JID?

your example was:

room.join(new JID("someroom@conference.jabber.server.com"));

But that doesnt compile in beta 3.

Severity and Description PathResource LocationCreation Time Id

3590: org.jivesoftware.xiff.core:JID used where a Boolean value was expected. The expression will be type coerced to Boolean. FPC/srcFPCClass.as line 301218748559239 1205

mike

Oh! I’m so sorry! I posted the wrong code… Here you go

room.roomJID = new JID("default@conference.jabber.citrusbyte.com");
room.join();

EDIT: I also edited my above post to fix this…

Thanks.I had just figured that out too.

Thanks for the help.

mike

Hi Mitchel,

I saw the advice that you gave to Mike Chambers and was hoping that you’d be able to expand upon that a bit if you have a moment. In creating a chat room in the way that you outlined does indeed create a room but all entries in the room are attributed to the JID…

For instance, if I create a chat room called allchat@conference.jabber.org, log several users in, all of their input shows up like:

allchat [14:33] : what up?
allchat [14:33] : not much just waiting for the dealeo to begin…
allchat [14:34] : but how do I add my username instead of this crap…

How do I go about having different users enter a room as themselves? I.E. if I have a user named ‘billybob’ and a user named ‘philisajerk’ how do I get the output to appear like:

philisajerk [14:33] : what up?
billybob[14:33] : not much just waiting for the dealeo to begin…
philisajerk[14:34] : but how do I add my username instead of this crap…

The code that I’m using to create the room after establishing a connection and logging in is as follows:

room= new Room(connection);
room.roomJID = new JID("allchat@conference.example.com");
room.addEventListener(RoomEvent.ROOM_JOIN, onRoomJoin);
room.join();

Any input would be appreciated because this is driving me bonkers…

Thanks,
Phil

The message.type will detemine if the message is for a room or for a private chat.

Use this with Message.GROUPCHAT_TYPE to see whether a message is for a room.

Then according to that information you can get the nickname from the JID.

var user:String = from.node;
if (message.type == Message.GROUPCHAT_TYPE) {
user = from.resource;
}

The situation is also explained here:

http://paazio.nanbudo.fi/tutorials/flash/xiff-chat-part-3-chat-room

Thank you very much! I actually wound up writing a parser last night to get the proper name to show but this is exactly what I was looking for and will switch to it…

XIFF seems like a great project - just wish that it had more documentation…

BTW: Your examples have been VERY helpful - thank you for providing them.

Thank you,

Phil

And if I want to get some information about a room before actually join? Like room name, subject, ecc.

You can get a list of rooms by sending an IQ to your chat server:

var browser:Browser = new Browser( connection );

browser.getServiceItems( chatServer, onGetServiceItems );

This list will have each room’s name and jid.

To get the subject and number of room occupants, if your server supports it, you can then send an IQ to each room:

private function onGetServiceItems( iq:IQ ):void
{
     var extensions:Array = iq.getAllExtensions();
     var disco:ItemDiscoExtension = extensions.length > 0 ? extensions[ 0 ] : null;
     
     if( disco )
     {
          if( disco.items.length > 0 )
          {
               var browser:Browser = new Browser( connection );
               browser.getNodeInfo( chatServer, new UnescapedJID( disco.items[ 0 ].jid ).node, onGetRoomInfo );
          }
     }
}

Note that this will only return subject and number of room occupants if your chat server is configured to do that.

Thanks much