Problem: muc.getOccupants()

Hi all available Helper …

As an admin, I manually created 2 public rooms (with very basic configuration and no password) in the OpenFire server … then I write a code in client app using Smack to join that rooms like below:

MultiUserChat muc = panel.getMuc();

if(muc != null){

System.out.println("Join status: " + muc.isJoined()); //----


Checking my JOIN status -


//

Iterator<String> it = muc.getOccupants();

while(it.hasNext()){

String participant = it.next();

String username = participant.substring(participant.indexOf("/") + 1, participant.length());

if(panel.getMainPanel().getRosterHandler().getContactByUsername(username + Config.getDomainPrefix()) != null){

Contact con = panel.getMainPanel().getRosterHandler().getContactByUsername(username + Config.getDomainPrefix());

panel.getListParticipantModel().addElement(con.getNickname());

} else {

panel.getListParticipantModel().addElement(username);

}

}

}

*The funny part is: My Join status check (code: muc.isJoined()

)… returned = TRUE but I cannot retrieve the occupants … WHY???*

If anybody out there had simillar problem before and already got enlightment … please help me on this … Thanks alot in advance

Bromo

That is a common problem people have with that method. Keep in mind that the results of that method are only a snapshot in time of occupants at the exact moment when you make the call. Many times people join the room and then call that method immediately before the list of occupants has been returned by the server. So at the time you are calling it the result is none, but a few milliseconds later it would likely return the correct results. The way to avoid this problem is to use listeners to monitor the occupant changes as they happen. I suggest you look at the Spark code to see an example of monitoring chat room occupants.

Chris

Your message

To: Bhopu

Subject: New message: “Re: Problem: muc.getOccupants()”

Sent: Thu, 6 Sep 2007 20:40:24 -0400

did not reach the following recipient(s):