MultiUserChat.getOccupants() returns null, MUC.getParticipants() return 403

Hello all,

Sorry for all of the posting today.

I am trying to retrieve a listing of users that are currently in a MUC.

First I tried getOccupants() like so:

public String getAllUsers(Object muc)throws XMPPException

{

String allUsers = null;

MultiUserChat Muc = (MultiUserChat) muc;

System.out.println(Muc.getOccupantsCount());

Iterator it = Muc.getOccupants();

while(it.hasNext())

{

String allUser = (String)it.next();

}

return allUsers;

}

/code

This returns null.

Then I tried MUC.getParticipants() like so:

public String getAllUsers(Object muc)throws XMPPException

{

String allUsers = null;

MultiUserChat Muc = (MultiUserChat) muc;

System.out.println(Muc.getOccupantsCount()); //This returns the proper number

List list = (List) Muc.getParticipants();

Iterator it = list.iterator();

while(it.hasNext())

{

String allUser = (String)it.next();

System.out.println("allUsers = "+allUsers);

}

return allUsers;

}

/code

This returns a 403

(403)

at org.jivesoftware.smackx.muc.MultiUserChat.getOccupants(MultiUserChat.java:1762)

at org.jivesoftware.smackx.muc.MultiUserChat.getParticipants(MultiUserChat.java:17 29)

at chatPackage.WebConnect.getAllUsers(WebConnect.java:344)

Am I totally off base here in my code?

Any ideas?

Thanks!

I can’‘t tell where or how you are creating the object but my guess is likely that you aren’'t in the room. The only way you can get access to the list of users is by being part of that room.

Thanks,

Alex

I am getting the proper number of users when I call this line of code (which is directly above the line that is giving me trouble).

System.out.println(Muc.getOccupantsCount());

/code

I did find a post by Gaston that recommended the following(My code is inside the iteration all else is his):

public String getAllUser() throws XMPPException

{

String allUsers = null;

XMPPConnection connection = this.getConnx(“gforty”,“password”);

// Discover the list of items (i.e. occupants in this case) related to a room

DiscoverItems result = ServiceDiscoveryManager.getInstanceFor(connection).discoverItems("testroomMUC@conference.portal.XXXXX.com");

// Iterate on the result’'s items

for (Iterator items=result.getItems(); items.hasNext():wink: {

//System.out.println(items.next());

String s = (String) items.next();

allUsers +=s;

}

return allUsers;

}

/code

But this is giving me a class cast exception.

Now if I remove the String cast and just do a console.out like so:

public String getAllUser() throws XMPPException

{

String allUsers = null;

XMPPConnection connection = this.getConnx(“gforty”,“password”);

// Discover the list of items (i.e. occupants in this case) related to a room

DiscoverItems result = ServiceDiscoveryManager.getInstanceFor(connection).discoverItems("testroomMUC@conference.portal.arincpcb.com");

// Iterate on the result’'s items

for (Iterator items=result.getItems(); items.hasNext():wink: {

//System.out.println(items.next());

System.out.println(“HERE”+items.next()); //THIS WORKS FINE

allUsers = “DONT KNOW”;

}

return allUsers;

}

/code

I get the following which tells me I am close:

HEREorg.jivesoftware.smackx.packet.DiscoverItems$Item@c3e82b

HEREorg.jivesoftware.smackx.packet.DiscoverItems$Item@1bf7b23

Any more ideas?

TIA!

Anybody have an answer to this? I’'m having the same problem:

// con is a class of mine that joins an existing MultiUserChat, and returns it

m_chat = con.createMultiUserChat(roomName);

m_chat.addMessageListener(m_messageListener);

m_chat.addParticipantListener(m_presenceListener);

m_chat.join(con.getQualifiedUserName(), password);

@SuppressWarnings(“unchecked”)

Iterator i = m_chat.getOccupants();

And my Iterator has nothing in it, despite the fact that I have successfully joined and there is at least one other user in the room. I’'m really not excited about the prospect of trying the hack that Gaston suggested - that would break my encapsulation quite badly.

Anybody have any other suggestions for finding out who is in a room when I join?

To answer part of my question (already): getOccupants returns the proper values later. So I’‘m guessing that it’‘s populated asynchronously (without looking at the source). So, what do I have to do to get notified that it knows who has joined? using addParticipantListener isn’‘t doing the job - I’'m not notified of anybody who previously joined (or of when I joined).

Nor is ParticipantStatusListener doing the job. With ParticipantStatusListener, I’'m notified when I join, but still no kind of notification that the MUC figured out that somebody else is in the room.

Message was edited by: nojo

nothing to see here… above comments apply.

Message was edited by: nojo

Argh. This is frustrating. So I implemented the hack suggested above, which is working well to tell me who is in the room. But when I have this in place (in a method called updateRecipients), sometimes (but only when I’‘m not using a debugger) I don’'t get notified of any messages. So my code looks like this:

m_participantListener = new ChatSessionParticipantStatusListener(this);

try {

logger.debug("joining MultiUserChat, room: " + roomName);

m_chat = con.createMultiUserChat(roomName);

m_chat.addMessageListener(m_messageListener);

m_chat.addParticipantStatusListener(m_participantListener);

m_chat.join(con.getQualifiedUserName(), password);

updateRecipients(con);

setTopic(m_chat.getSubject());

} …

So updateRecipients uses ServiceDiscoverManager to query for the users in the room. If I run the code as-is, m_messageListener generally doesn’‘t get any notifications of messages. If I comment out updateRecipients(con), then it does, but I don’‘t know who is in the room. If I run as-is in a debugger, all works fine (so I can’‘t see what’‘s really going on). There’‘s definitely a possibility that I’‘m doing something wrong, but I just don’'t see what. Anybody with any suggestions??

Instead of initializing allUsers to null, try initializing it to “”.

-Angelo

I found the following post that finally helped me to retrieve all users in a chat room.

http://www.jivesoftware.org/community/thread.jspa?messageID=124149&#124149

My code is as follows:

//THIS WILL RETURN A LIST OF ALL USERS CURRENTLY IN A CHAT ROOM

public String getRoomOccupants(XMPPConnection conn, String roomName)throws XMPPException

{

StringBuffer sb = new StringBuffer();

ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(conn);

DiscoverItems items = discoManager.discoverItems(roomName+CONFERENCE_SERVICE_NAME);

for (Iterator it = items.getItems(); it.hasNext():wink:

{

DiscoverItems.Item item = (DiscoverItems.Item) it.next();

String occupant = parseEntityID(item.getEntityID());

sb.append(" &nbsp “occupant
");

}

return sb.toString();

}

/code

gforty, that general thing works for me, too. But in my mind that’‘s a hack. What’'s getOccupants() for if not to retrieve a list of the occupants?

Yea, I was wondering that same thing.

For that matter what does

getParticipants() ,getMembers() and getOccupants() do as If I recall I tried both.

As you can see from all of my postings , MUC is giving me grief.

My newest problem is with a persistent chat room.

newForm.setAnswer(“muc#roomconfig_persistentroom”,false);

gives me a locked room…

System.out = theChatRoom SAYS This room is locked from entry until configuration is confirmed. to gforty

set it to true and all is fine.

newForm.setAnswer(“muc#roomconfig_persistentroom”,true);

Does these forum pages take several minutes to load for anyone else?

Thanks.