本文整理汇总了Java中org.jivesoftware.smackx.ServiceDiscoveryManager类的典型用法代码示例。如果您正苦于以下问题:Java ServiceDiscoveryManager类的具体用法?Java ServiceDiscoveryManager怎么用?Java ServiceDiscoveryManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ServiceDiscoveryManager类属于org.jivesoftware.smackx包,在下文中一共展示了ServiceDiscoveryManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getHostRooms
import org.jivesoftware.smackx.ServiceDiscoveryManager; //导入依赖的package包/类
/**
* 获取用户的所有聊天室
* @param xmppConnection
* @return
*/
public static List<HostedRoom> getHostRooms(XMPPConnection xmppConnection){
List<HostedRoom> roominfos = new ArrayList<HostedRoom>();
try {
new ServiceDiscoveryManager(xmppConnection);
Collection<HostedRoom> hostrooms = MultiUserChat.getHostedRooms(xmppConnection,xmppConnection.getServiceName());
for (HostedRoom entry : hostrooms) {
roominfos.add(entry);
Log.i("room", "名字:" + entry.getName() + " - ID:" + entry.getJid());
}
Log.i("room", "服务会议数量:" + roominfos.size());
} catch (XMPPException e) {
Log.e("getHostRooms",e.getMessage());
e.printStackTrace();
}
return roominfos;
}
示例2: testPrivateIQ
import org.jivesoftware.smackx.ServiceDiscoveryManager; //导入依赖的package包/类
/**
* Tests that IQ packets can be sent to/from room occupants. This case will try to discover
* information about other room occupants.
*/
public void testPrivateIQ() {
try {
// User2 joins the new room
MultiUserChat muc2 = new MultiUserChat(getConnection(1), room);
muc2.join("testbot2");
// User2 discovers information about User1
DiscoverInfo info = ServiceDiscoveryManager.getInstanceFor(getConnection(1))
.discoverInfo(room + "/testbot", null);
assertNotNull("No info was discovered from room occupant", info);
assertEquals("Wrong IQ type", IQ.Type.result, info.getType());
assertEquals("Wrong IQ sender", room + "/testbot", info.getFrom());
// User2 leaves the room
muc2.leave();
}
catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
示例3: publishCommands
import org.jivesoftware.smackx.ServiceDiscoveryManager; //导入依赖的package包/类
/**
* Publish the commands to an specific JID.
*
* @param jid the full JID to publish the commands to.
* @throws XMPPException if the operation failed for some reason.
*/
public void publishCommands(String jid) throws XMPPException {
ServiceDiscoveryManager serviceDiscoveryManager = ServiceDiscoveryManager
.getInstanceFor(connection);
// Collects the commands to publish as items
DiscoverItems discoverItems = new DiscoverItems();
Collection<AdHocCommandInfo> xCommandsList = getRegisteredCommands();
for (AdHocCommandInfo info : xCommandsList) {
DiscoverItems.Item item = new DiscoverItems.Item(info.getOwnerJID());
item.setName(info.getName());
item.setNode(info.getNode());
discoverItems.addItem(item);
}
serviceDiscoveryManager.publishItems(jid, discoNode, discoverItems);
}
示例4: getJoinedRooms
import org.jivesoftware.smackx.ServiceDiscoveryManager; //导入依赖的package包/类
/**
* Returns an Iterator on the rooms where the requested user has joined. The Iterator will
* contain Strings where each String represents a room (e.g. [email protected]).
*
* @param connection the connection to use to perform the service discovery.
* @param user the user to check. A fully qualified xmpp ID, e.g. [email protected]
* @return an Iterator on the rooms where the requested user has joined.
*/
public static Iterator<String> getJoinedRooms(Connection connection, String user) {
try {
ArrayList<String> answer = new ArrayList<String>();
// Send the disco packet to the user
DiscoverItems result =
ServiceDiscoveryManager.getInstanceFor(connection).discoverItems(user, discoNode);
// Collect the entityID for each returned item
for (Iterator<DiscoverItems.Item> items=result.getItems(); items.hasNext();) {
answer.add(items.next().getEntityID());
}
return answer.iterator();
}
catch (XMPPException e) {
e.printStackTrace();
// Return an iterator on an empty collection
return new ArrayList<String>().iterator();
}
}
示例5: getServiceNames
import org.jivesoftware.smackx.ServiceDiscoveryManager; //导入依赖的package包/类
/**
* Returns a collection with the XMPP addresses of the Multi-User Chat services.
*
* @param connection the XMPP connection to use for discovering Multi-User Chat services.
* @return a collection with the XMPP addresses of the Multi-User Chat services.
* @throws XMPPException if an error occured while trying to discover MUC services.
*/
public static Collection<String> getServiceNames(Connection connection) throws XMPPException {
final List<String> answer = new ArrayList<String>();
ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection);
DiscoverItems items = discoManager.discoverItems(connection.getServiceName());
for (Iterator<DiscoverItems.Item> it = items.getItems(); it.hasNext();) {
DiscoverItems.Item item = it.next();
try {
DiscoverInfo info = discoManager.discoverInfo(item.getEntityID());
if (info.containsFeature("http://jabber.org/protocol/muc")) {
answer.add(item.getEntityID());
}
}
catch (XMPPException e) {
// Trouble finding info in some cases. This is a workaround for
// discovering info on remote servers.
}
}
return answer;
}
示例6: getReservedNickname
import org.jivesoftware.smackx.ServiceDiscoveryManager; //导入依赖的package包/类
/**
* Returns the reserved room nickname for the user in the room. A user may have a reserved
* nickname, for example through explicit room registration or database integration. In such
* cases it may be desirable for the user to discover the reserved nickname before attempting
* to enter the room.
*
* @return the reserved room nickname or <tt>null</tt> if none.
*/
public String getReservedNickname() {
try {
DiscoverInfo result =
ServiceDiscoveryManager.getInstanceFor(connection).discoverInfo(
room,
"x-roomuser-item");
// Look for an Identity that holds the reserved nickname and return its name
for (Iterator<DiscoverInfo.Identity> identities = result.getIdentities();
identities.hasNext();) {
DiscoverInfo.Identity identity = identities.next();
return identity.getName();
}
// If no Identity was found then the user does not have a reserved room nickname
return null;
}
catch (XMPPException e) {
e.printStackTrace();
return null;
}
}
示例7: setServiceEnabled
import org.jivesoftware.smackx.ServiceDiscoveryManager; //导入依赖的package包/类
/**
* Enable the Jabber services related to file transfer on the particular
* connection.
*
* @param connection The connection on which to enable or disable the services.
* @param isEnabled True to enable, false to disable.
*/
public static void setServiceEnabled(final Connection connection,
final boolean isEnabled) {
ServiceDiscoveryManager manager = ServiceDiscoveryManager
.getInstanceFor(connection);
List<String> namespaces = new ArrayList<String>();
namespaces.addAll(Arrays.asList(NAMESPACE));
namespaces.add(InBandBytestreamManager.NAMESPACE);
if (!IBB_ONLY) {
namespaces.add(Socks5BytestreamManager.NAMESPACE);
}
for (String namespace : namespaces) {
if (isEnabled) {
if (!manager.includesFeature(namespace)) {
manager.addFeature(namespace);
}
} else {
manager.removeFeature(namespace);
}
}
}
示例8: isServiceEnabled
import org.jivesoftware.smackx.ServiceDiscoveryManager; //导入依赖的package包/类
/**
* Checks to see if all file transfer related services are enabled on the
* connection.
*
* @param connection The connection to check
* @return True if all related services are enabled, false if they are not.
*/
public static boolean isServiceEnabled(final Connection connection) {
ServiceDiscoveryManager manager = ServiceDiscoveryManager
.getInstanceFor(connection);
List<String> namespaces = new ArrayList<String>();
namespaces.addAll(Arrays.asList(NAMESPACE));
namespaces.add(InBandBytestreamManager.NAMESPACE);
if (!IBB_ONLY) {
namespaces.add(Socks5BytestreamManager.NAMESPACE);
}
for (String namespace : namespaces) {
if (!manager.includesFeature(namespace)) {
return false;
}
}
return true;
}
示例9: publishCommands
import org.jivesoftware.smackx.ServiceDiscoveryManager; //导入依赖的package包/类
/**
* Publish the commands to an specific JID.
*
* @param jid
* the full JID to publish the commands to.
* @throws XMPPException
* if the operation failed for some reason.
*/
public void publishCommands(String jid) throws XMPPException {
ServiceDiscoveryManager serviceDiscoveryManager = ServiceDiscoveryManager
.getInstanceFor(connection);
// Collects the commands to publish as items
DiscoverItems discoverItems = new DiscoverItems();
Collection<AdHocCommandInfo> xCommandsList = getRegisteredCommands();
for (AdHocCommandInfo info : xCommandsList) {
DiscoverItems.Item item = new DiscoverItems.Item(info.getOwnerJID());
item.setName(info.getName());
item.setNode(info.getNode());
discoverItems.addItem(item);
}
serviceDiscoveryManager.publishItems(jid, discoNode, discoverItems);
}
示例10: getJoinedRooms
import org.jivesoftware.smackx.ServiceDiscoveryManager; //导入依赖的package包/类
/**
* Returns an Iterator on the rooms where the requested user has joined. The
* Iterator will contain Strings where each String represents a room (e.g.
* [email protected]).
*
* @param connection
* the connection to use to perform the service discovery.
* @param user
* the user to check. A fully qualified xmpp ID, e.g.
* [email protected]
* @return an Iterator on the rooms where the requested user has joined.
*/
public static Iterator<String> getJoinedRooms(Connection connection,
String user) {
try {
ArrayList<String> answer = new ArrayList<String>();
// Send the disco packet to the user
DiscoverItems result = ServiceDiscoveryManager.getInstanceFor(
connection).discoverItems(user, discoNode);
// Collect the entityID for each returned item
for (Iterator<DiscoverItems.Item> items = result.getItems(); items
.hasNext();) {
answer.add(items.next().getEntityID());
}
return answer.iterator();
} catch (XMPPException e) {
e.printStackTrace();
// Return an iterator on an empty collection
return new ArrayList<String>().iterator();
}
}
示例11: getServiceNames
import org.jivesoftware.smackx.ServiceDiscoveryManager; //导入依赖的package包/类
/**
* Returns a collection with the XMPP addresses of the Multi-User Chat
* services.
*
* @param connection
* the XMPP connection to use for discovering Multi-User Chat
* services.
* @return a collection with the XMPP addresses of the Multi-User Chat
* services.
* @throws XMPPException
* if an error occured while trying to discover MUC services.
*/
public static Collection<String> getServiceNames(Connection connection)
throws XMPPException {
final List<String> answer = new ArrayList<String>();
ServiceDiscoveryManager discoManager = ServiceDiscoveryManager
.getInstanceFor(connection);
DiscoverItems items = discoManager.discoverItems(connection
.getServiceName());
for (Iterator<DiscoverItems.Item> it = items.getItems(); it.hasNext();) {
DiscoverItems.Item item = it.next();
try {
DiscoverInfo info = discoManager.discoverInfo(item
.getEntityID());
if (info.containsFeature("http://jabber.org/protocol/muc")) {
answer.add(item.getEntityID());
}
} catch (XMPPException e) {
// Trouble finding info in some cases. This is a workaround for
// discovering info on remote servers.
}
}
return answer;
}
示例12: getReservedNickname
import org.jivesoftware.smackx.ServiceDiscoveryManager; //导入依赖的package包/类
/**
* Returns the reserved room nickname for the user in the room. A user may
* have a reserved nickname, for example through explicit room registration
* or database integration. In such cases it may be desirable for the user
* to discover the reserved nickname before attempting to enter the room.
*
* @return the reserved room nickname or <tt>null</tt> if none.
*/
public String getReservedNickname() {
try {
DiscoverInfo result = ServiceDiscoveryManager.getInstanceFor(
connection).discoverInfo(room, "x-roomuser-item");
// Look for an Identity that holds the reserved nickname and return
// its name
for (Iterator<DiscoverInfo.Identity> identities = result
.getIdentities(); identities.hasNext();) {
DiscoverInfo.Identity identity = identities.next();
return identity.getName();
}
// If no Identity was found then the user does not have a reserved
// room nickname
return null;
} catch (XMPPException e) {
e.printStackTrace();
return null;
}
}
示例13: setServiceEnabled
import org.jivesoftware.smackx.ServiceDiscoveryManager; //导入依赖的package包/类
/**
* Enable the Jabber services related to file transfer on the particular
* connection.
*
* @param connection
* The connection on which to enable or disable the services.
* @param isEnabled
* True to enable, false to disable.
*/
public static void setServiceEnabled(final Connection connection,
final boolean isEnabled) {
ServiceDiscoveryManager manager = ServiceDiscoveryManager
.getInstanceFor(connection);
List<String> namespaces = new ArrayList<String>();
namespaces.addAll(Arrays.asList(NAMESPACE));
namespaces.add(InBandBytestreamManager.NAMESPACE);
if (!IBB_ONLY) {
namespaces.add(Socks5BytestreamManager.NAMESPACE);
}
for (String namespace : namespaces) {
if (isEnabled) {
if (!manager.includesFeature(namespace)) {
manager.addFeature(namespace);
}
} else {
manager.removeFeature(namespace);
}
}
}
示例14: isServiceEnabled
import org.jivesoftware.smackx.ServiceDiscoveryManager; //导入依赖的package包/类
/**
* Checks to see if all file transfer related services are enabled on the
* connection.
*
* @param connection
* The connection to check
* @return True if all related services are enabled, false if they are not.
*/
public static boolean isServiceEnabled(final Connection connection) {
ServiceDiscoveryManager manager = ServiceDiscoveryManager
.getInstanceFor(connection);
List<String> namespaces = new ArrayList<String>();
namespaces.addAll(Arrays.asList(NAMESPACE));
namespaces.add(InBandBytestreamManager.NAMESPACE);
if (!IBB_ONLY) {
namespaces.add(Socks5BytestreamManager.NAMESPACE);
}
for (String namespace : namespaces) {
if (!manager.includesFeature(namespace)) {
return false;
}
}
return true;
}
示例15: getSpaceConfiguration
import org.jivesoftware.smackx.ServiceDiscoveryManager; //导入依赖的package包/类
/**
* Retrieves the configuration of the space.
* @param space The space to get the configuration for.
* @return The parsed result or, if there was an error, null.
* @throws SpaceManagementException Thrown when no response was received from the server.
*/
private SpaceConfiguration getSpaceConfiguration(Space space) throws SpaceManagementException{
if (space == null){
throw new IllegalArgumentException("The given space must not be null");
}
ServiceDiscoveryManager discoveryManager = ServiceDiscoveryManager.getInstanceFor(connection);
DiscoverInfo info;
try {
info = discoveryManager.discoverInfo(SERVICE_PREFIX + space.getDomain(), space.getId());
} catch (XMPPException e) {
if (e.getXMPPError().getCode() == 404) {
return null;
} else {
throw new SpaceManagementException("The Server didn't respond.", Type.OTHER, e);
}
}
Element config = parsePacketToElement(info);
return parseSpaceConfiguration(config);
}