List of rooms

Hi all,

A bit new at this Xiff thing and don’'t know what to do.

What I am trying to do is show a list of the available rooms on the server, so that you could click on a room in the list and enter it.

Any idea’'s on how to do this???

I would do something like that:

var browser = new Browser( connection );

// Event handler

var iqHandler = new Object();

iqHandler.handleEvent = function( iq:IQ )

{

trace(“iqHandler.handleEvent:”+iq);

var itemExt:ItemDiscoExtension =iq.getAllExtensions()[0];

for( var i=0; i< itemExt.items.length; i++) {

trace( "jid:"itemExt.items.jid);

trace( "name:"itemExt.items.name);

}

}

browser.getServiceItems(chatRoom.conferenceServer, “handleEvent”, iqHandler);

Hope this helps.

Pat.

Thanks for that, will give it a try. Is quite different from what I tried.

Thanks again.

Hey, did it work for you?

Let us know.

Thanks.

Pat.

Hey cappelaere,

this forum uses the (without the spaces) as an italic tag,

so the code looks incorrect:

here’'s a correct one ( and it works for me )

var browser = new Browser( connection );
// Event handler
var iqHandler = new Object();
iqHandler.handleEvent = function( iq:IQ )
{
trace("iqHandler.handleEvent:"+iq); var itemExt:ItemDiscoExtension =iq.getAllExtensions()[0];
for( var i=0; i< itemExt.items.length; i++) {
trace( "jid:"+itemExt.items[ i ].jid);
trace( "name:"+itemExt.items[ i ].name);
}

Gepatto, I can’‘t make it work! I’'m doing the following:

  1. Create a blank flash document

  2. in the frame script, I paste this code:


cut here----


import org.jivesoftware.xiff.core.XMPPConnection;

import org.jivesoftware.xiff.core.Browser;

import org.jivesoftware.xiff.conference.Room;

import org.jivesoftware.xiff.im.Roster;

import org.jivesoftware.xiff.data.IQ;

import org.jivesoftware.xiff.data.disco.ItemDiscoExtension;

//get rooms

var browser = new Browser(connection);

// Event handler

var iqHandler = new Object();

iqHandler.handleEvent = function(iq:IQ) {

trace(“iqHandler.handleEvent:”+iq);

var itemExt:ItemDiscoExtension = iq.getAllExtensions()[0];

for (var i = 0; i<itemExt.items.length; i++) {

trace(“jid:”+itemExt.items[ i ].jid);

trace(“name:”+itemExt.items[ i ].name);

}

};


cut here----


but no luck, the “handleEvent” function never executes. Any idea?

Thanx!

It works in my chat… I hope it will in yours

I have a datagrid called roomList


CUT----


var listeChann=new Array();

roomList.dataProvider=listeChann;

bro=new Browser(connection);

function browse_result( resultIQ:IQ ):Void{

var ext:BrowseExtension = resultIQ.getAllExtensionsByNS( BrowseExtension.NS )[0];

var newItems = ext.items;

listeChann.removeAll(); //Clean all

for( var i=0; i < newItems.length; i++ ){ //For each room

var item = newItems[i];

listeChann.addItem({Name:item.name.split(" “)[0],Occupation:item.name.split(” ")[1],Type:item.type});

}

roomList.sortItemsBy(“Name”);

};

//The button that launches the query

myButton.onPress=function(){

bro.browseItem(conference,“browse_result”,_root); //List the rooms

}


CUT----


You can try this on my chat: http://usuc.dyndns.org/tv/Jabber/novachat.php

Hey Werewolf,

Your piece of code seems to be missing a couple of things:

you can try this:

put a v2 button component on the stage and give it an instance name of btn_browse:

then put the following code on the first frame.


import org.jivesoftware.xiff.core.XMPPConnection;

import org.jivesoftware.xiff.core.Browser;

import org.jivesoftware.xiff.data.IQ;

import org.jivesoftware.xiff.data.disco.ItemDiscoExtension;

import mx.utils.Delegate;

// XMPPConnection

var connection = new XMPPConnection();

connection.username = “username”;

connection.password = “password”;

connection.server = “localhost”;

var chatserver:String = “conference.” + connection.server;

connection.connect( “flash” );

var browser = new Browser( connection );

var iqHandler = new Object();

iqHandler.handleEvent = function( iq:IQ )

{

var itemExt:ItemDiscoExtension =iq.getAllExtensions()[0];

for( var i=0; i< itemExt.items.length; i++) {

trace( “Room:”+itemExt.items[ i ].name + "[ " + itemExt.items[ i ].jid + " ] ");

}

}

function getRooms(){

browser.getServiceItems(chatserver, “handleEvent”, iqHandler);

}

root.btnbrowse.onPress = Delegate.create(this,getRooms);

/code


the button is there to make sure you call browser.getServiceItems after the connection was made.

(in an application you should listen to the login event of the connection object, but hey, this is just a simple test

HEY GEPATTO! IT WORKS SMOOTHLY!! YOU ARE THE BEST!!!

Hi again. Just one more thing:

There is a way to add “awarnes” to the room listing? I mean, if somebody creates a new room, the room list refresh automatically, instead of check it continuously.

Thanx again.

Hi Werewolf,

I might be wrong but I don’‘t think that’'s possible, since roombrowsing is a ‘‘discovery service’’. I think you would have to build a special servercomponent that sends a message to all (or a selected group of) connected clients when a room is created.

Can you tell why you would want this?

Of course!, I’‘m building a “Game Lobby” like yahoo based in jabber. You can enter in a game lobby(IE. Pool, or chess) and see if there is a table (room) created, and if it’'s free. If there is at least one, you can join it. But if there is no “Table” or no one is free, you can create one and wait another player to join and play with you.

If you are just “looking arround” or you dont want to create a table, the table list(with its state) must show the actual state all the time.

I don’'t know if the “most natural solution” to this problem is refresh the table avery 5 seconds(or less). May be I can create a “subscription”(does anything like that exist?) or broadcast a special message to the group avery time a table is created.

Any idea?

in the other hand, how much information you can get from a room? Can you create rooms that can only be viwed for users from a certain group?, I mean the chatroom “MASTERS OF POOL” must be viewed just for the users of the group “POOL”.