But it returns no user’'s name in participants and throws this exception:
+(403)
at org.jivesoftware.smackx.muc.MultiUserChat.getOccupants(MultiUserChat.java:1704)
at org.jivesoftware.smackx.muc.MultiUserChat.getParticipants(MultiUserChat.java:16 71)+
I have tried to join the MUC before listing the participants but the result was the same… Did I do something wrong? Is there another way to obtain this list?
Thanks,
Seb
PS: sorry for being so inefficient this week… I have the feeling of flooding this poor forum with stupid questions!
The 403 error means that the required operation is forbidden for the user that tried to make it. The problem is that #getParticipants() is only allowed to be executed by room owners.
Anyway, #getParticipants() is not what you need to get the online users that have joined a MUC room. That method will return the list of users that have an affiliation of participant (no matter whether they are online or not).
To get the list of occupants you have two ways.
If the room is a Public room (i.e. is listed in the directory) then you can use Service Discovery to get the room occupants. You will need to execute something like this:
// Discover the list of items (i.e. occupants in this case) related to a room
DiscoverItems result = ServiceDiscoveryManager.getInstanceFor(connection).discoverItems("room@service");
// Iterate on the result''s items
for (Iterator items=result.getItems(); items.hasNext();) {
....
}
Join the room and then send #getOccupants() to get the list of occupants. Note that the list will contain not the real JID of the user but the room JID. So you can then send #getOccupantPresence(String) to get the real presence of the user which may (depending on the room configuration) include the real JID of the user.
It works better with your code . I have read the JEP-0045 and understood my mistake… These affiliation and role concepts are very tricky, it is not very simple to know what are a user’'s privileges.