org.jivesoftware.smackx.ServiceDiscoveryManager Java Examples
The following examples show how to use
org.jivesoftware.smackx.ServiceDiscoveryManager.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XmppConnection.java From weixin with Apache License 2.0 | 6 votes |
/** * 初始化会议室列表 */ public List<HostedRoom> getHostRooms() { if (getConnection() == null) return null; Collection<HostedRoom> hostrooms = null; List<HostedRoom> roominfos = new ArrayList<HostedRoom>(); try { new ServiceDiscoveryManager(getConnection()); hostrooms = MultiUserChat.getHostedRooms(getConnection(), getConnection().getServiceName()); for (HostedRoom entry : hostrooms) { roominfos.add(entry); Log.i("room", "名字:" + entry.getName() + " - ID:" + entry.getJid()); } Log.i("room", "服务会议数量:" + roominfos.size()); } catch (XMPPException e) { e.printStackTrace(); } return roominfos; }
Example #2
Source File: XmppManager.java From weixin with Apache License 2.0 | 6 votes |
/** * 获取服务器上所有会议室 * * @return * @throws XMPPException */ public List<FriendRooms> getConferenceRoom() throws XMPPException { List<FriendRooms> list = new ArrayList<FriendRooms>(); new ServiceDiscoveryManager(getConnection()); if (!MultiUserChat.getHostedRooms(getConnection(), getConnection().getServiceName()).isEmpty()) { for (HostedRoom k : MultiUserChat.getHostedRooms(getConnection(), getConnection().getServiceName())) { for (HostedRoom j : MultiUserChat.getHostedRooms(getConnection(), k.getJid())) { RoomInfo info2 = MultiUserChat.getRoomInfo(getConnection(), j.getJid()); if (j.getJid().indexOf("@") > 0) { FriendRooms friendrooms = new FriendRooms(); friendrooms.setName(j.getName());//聊天室的名称 friendrooms.setJid(j.getJid());//聊天室JID friendrooms.setOccupants(info2.getOccupantsCount());//聊天室中占有者数量 friendrooms.setDescription(info2.getDescription());//聊天室的描述 friendrooms.setSubject(info2.getSubject());//聊天室的主题 list.add(friendrooms); } } } } return list; }
Example #3
Source File: MultiUserChatTest.java From Smack with Apache License 2.0 | 6 votes |
/** * 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()); } }
Example #4
Source File: XmppConnection.java From weixin with Apache License 2.0 | 5 votes |
/** * 查询用户 * * @param userName * @return * @throws XMPPException */ public List<HashMap<String, String>> searchUsers(String userName) { if (getConnection() == null) return null; HashMap<String, String> user = null; List<HashMap<String, String>> results = new ArrayList<HashMap<String, String>>(); try { new ServiceDiscoveryManager(getConnection()); UserSearchManager usm = new UserSearchManager(getConnection()); Form searchForm = usm.getSearchForm(getConnection().getServiceName()); Form answerForm = searchForm.createAnswerForm(); answerForm.setAnswer("userAccount", true); answerForm.setAnswer("userPhote", userName); ReportedData data = usm.getSearchResults(answerForm, "search" + getConnection().getServiceName()); Iterator<Row> it = data.getRows(); Row row = null; while (it.hasNext()) { user = new HashMap<String, String>(); row = it.next(); user.put("userAccount", row.getValues("userAccount").next().toString()); user.put("userPhote", row.getValues("userPhote").next().toString()); results.add(user); // 若存在,则有返回,UserName一定非空,其他两个若是有设,一定非空 } } catch (XMPPException e) { e.printStackTrace(); } return results; }
Example #5
Source File: Socks5ByteStreamTest.java From Smack with Apache License 2.0 | 5 votes |
/** * Socks5 feature should be added to the service discovery on Smack startup. * * @throws XMPPException should not happen */ public void testInitializationSocks5FeaturesAndListenerOnStartup() throws XMPPException { XMPPConnection connection = getConnection(0); assertTrue(ServiceDiscoveryManager.getInstanceFor(connection).includesFeature( Socks5BytestreamManager.NAMESPACE)); }
Example #6
Source File: MultiUserChatStateManager.java From saros with GNU General Public License v2.0 | 5 votes |
protected MultiUserChatStateManager(Connection connection, MultiUserChat muc) { log.setLevel(Level.TRACE); this.connection = connection; this.muc = muc; // intercepting incoming messages this.muc.addMessageListener(incomingMessageInterceptor); ServiceDiscoveryManager.getInstanceFor(connection).addFeature(CHATSTATES_FEATURE); }
Example #7
Source File: XMPPUtils.java From saros with GNU General Public License v2.0 | 4 votes |
/** * Returns whether the given JID can be found on the server. * * @blocking * @param connection * @throws XMPPException if the service discovery failed */ public static boolean isJIDonServer(Connection connection, JID jid, String resourceHint) throws XMPPException { if (isListedInUserDirectory(connection, jid)) return true; ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection); boolean discovered = sdm.discoverInfo(jid.getRAW()).getIdentities().hasNext(); if (!discovered && jid.isBareJID() && resourceHint != null && !resourceHint.isEmpty()) { discovered = sdm.discoverInfo(jid.getBase() + "/" + resourceHint).getIdentities().hasNext(); } return discovered; }