简体   繁体   English

smack API在openfire服务器上获取所有公共房间

[英]smack api get all public rooms on openfire server

I am using the XMPP smack api to connect to an Openfire server. 我正在使用XMPP smack api连接到Openfire服务器。 I am trying to query the server to return all public rooms available without knowing this names of the rooms in advance. 我试图查询服务器以返回所有可用的公共房间,而无需事先知道这些房间的名称。 The goal of this is so that my client can display a list of all public rooms available and join them accordingly. 这样做的目的是使我的客户可以显示所有可用公共房间的列表,并相应地加入它们。 The Smack Extensions Documentation provides several examples of returning room information from the server however none of them seem to fit my need. Smack扩展文档提供了几个从服务器返回房间信息的示例,但是这些示例似乎都不符合我的需求。

One example requires you to know the name of the room beforehand, which is no good if you want to display available rooms that the client otherwise has no knowledge of. 一个示例要求您事先知道房间的名称,如果您想显示客户否则不知道的可用房间,这是不好的。 The code for this example is as follows. 此示例的代码如下。

 // Discover information about the room roomName@conference.myserver
  RoomInfo info = MultiUserChat.getRoomInfo(conn, "roomName@conference.myserver");
  System.out.println("Number of occupants:" + info.getOccupantsCount());
  System.out.println("Room Subject:" + info.getSubject());

Another example allows you to query the rooms that all of your contacts are currently in. This seems to be a very indirect way of getting room names and has the potential to leave some of the rooms out. 另一个示例使您可以查询所有联系人当前所在的房间。这似乎是获取房间名称的非常​​间接的方式,并且有可能将某些房间留在外面。 As XMPP is a server based protocol and not a p2p based protocol this does not seem like the most logical way of accomplishing this (although please correct me if I am wrong). 由于XMPP是基于服务器的协议,而不是基于p2p的协议,因此这似乎不是实现此目的的最合乎逻辑的方式(尽管如果我做错了,请更正我)。 This code example is as follows 此代码示例如下

 Iterator joinedRooms = MultiUserChat.getJoinedRooms(conn, "user3@host.org/Smack");

If someone could either please send me a link or provide an example of how to accomplish this it would be greatly appreciated. 如果有人可以给我发送链接或提供有关如何完成此操作的示例,将不胜感激。

看起来MultiUserChat.getHostedRooms()是您要寻找的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM