public void connectionCreated(final Connection connection) { // Set on every established connection that this client supports the Multi-User // Chat protocol. This information will be used when another client tries to // discover whether this client supports MUC or not. ServiceDiscoveryManager.getInstanceFor(connection).addFeature(discoNamespace); // Set the NodeInformationProvider that will provide information about the // joined rooms whenever a disco request is received ServiceDiscoveryManager.getInstanceFor(connection).setNodeInformationProvider( discoNode, new NodeInformationProvider() { public List<DiscoverItems.Item> getNodeItems() { List<DiscoverItems.Item> answer = new ArrayList<DiscoverItems.Item>(); Iterator<String> rooms=MultiUserChat.getJoinedRooms(connection); while (rooms.hasNext()) { answer.add(new DiscoverItems.Item(rooms.next())); } return answer; } public List<String> getNodeFeatures() { return null; } public List<DiscoverInfo.Identity> getNodeIdentities() { return null; } }); }
public void connectionCreated(final Connection connection) { // Set on every established connection that this client // supports the Multi-User // Chat protocol. This information will be used when // another client tries to // discover whether this client supports MUC or not. ServiceDiscoveryManager.getInstanceFor(connection) .addFeature(discoNamespace); // Set the NodeInformationProvider that will provide // information about the // joined rooms whenever a disco request is received ServiceDiscoveryManager.getInstanceFor(connection) .setNodeInformationProvider(discoNode, new NodeInformationProvider() { public List<DiscoverItems.Item> getNodeItems() { List<DiscoverItems.Item> answer = new ArrayList<DiscoverItems.Item>(); Iterator<String> rooms = MultiUserChat .getJoinedRooms(connection); while (rooms.hasNext()) { answer.add(new DiscoverItems.Item( rooms.next())); } return answer; } public List<String> getNodeFeatures() { return null; } public List<DiscoverInfo.Identity> getNodeIdentities() { return null; } }); }
public void connectionCreated(final Connection connection) { // Set on every established connection that this client supports the Multi-User // Chat protocol. This information will be used when another client tries to // discover whether this client supports MUC or not. ServiceDiscoveryManager.getInstanceFor(connection).addFeature(discoNamespace); // Set the NodeInformationProvider that will provide information about the // joined rooms whenever a disco request is received ServiceDiscoveryManager.getInstanceFor(connection).setNodeInformationProvider( discoNode, new NodeInformationProvider() { public List<DiscoverItems.Item> getNodeItems() { List<DiscoverItems.Item> answer = new ArrayList<DiscoverItems.Item>(); Iterator<String> rooms=MultiUserChat.getJoinedRooms(connection); while (rooms.hasNext()) { answer.add(new DiscoverItems.Item(rooms.next())); } return answer; } public List<String> getNodeFeatures() { return null; } public List<DiscoverInfo.Identity> getNodeIdentities() { return null; } @Override public List<PacketExtension> getNodePacketExtensions() { return null; } }); }
private AdHocCommandManager(Connection connection) { this.connection = new WeakReference<Connection>(connection); this.serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(connection); // Register the new instance and associate it with the connection instances.put(connection, this); // Add the feature to the service discovery manage to show that this // connection supports the AdHoc-Commands protocol. // This information will be used when another client tries to // discover whether this client supports AdHoc-Commands or not. ServiceDiscoveryManager.getInstanceFor(connection).addFeature( DISCO_NAMESPACE); // Set the NodeInformationProvider that will provide information about // which AdHoc-Commands are registered, whenever a disco request is // received ServiceDiscoveryManager.getInstanceFor(connection) .setNodeInformationProvider(discoNode, new NodeInformationProvider() { public List<DiscoverItems.Item> getNodeItems() { List<DiscoverItems.Item> answer = new ArrayList<DiscoverItems.Item>(); Collection<AdHocCommandInfo> commandsList = getRegisteredCommands(); for (AdHocCommandInfo info : commandsList) { DiscoverItems.Item item = new DiscoverItems.Item( info.getOwnerJID()); item.setName(info.getName()); item.setNode(info.getNode()); answer.add(item); } return answer; } public List<String> getNodeFeatures() { return null; } public List<Identity> getNodeIdentities() { return null; } @Override public List<PacketExtension> getNodePacketExtensions() { return null; } }); // The packet listener and the filter for processing some AdHoc Commands // Packets PacketListener listener = new PacketListener() { public void processPacket(Packet packet) { AdHocCommandData requestData = (AdHocCommandData) packet; processAdHocCommand(requestData); } }; PacketFilter filter = new PacketTypeFilter(AdHocCommandData.class); connection.addPacketListener(listener, filter); sessionsSweeper = null; }
/** * Updates the local user Entity Caps information with the data provided * * If we are connected and there was already a presence send, another * presence is send to inform others about your new Entity Caps node string. * * @param discoverInfo * the local users discover info (mostly the service discovery * features) * @param identityType * the local users identity type * @param identityName * the local users identity name * @param extendedInfo * the local users extended info */ public void updateLocalEntityCaps() { Connection connection = weakRefConnection.get(); DiscoverInfo discoverInfo = new DiscoverInfo(); discoverInfo.setType(IQ.Type.RESULT); discoverInfo.setNode(getLocalNodeVer()); if (connection != null) discoverInfo.setFrom(connection.getUser()); sdm.addDiscoverInfoTo(discoverInfo); currentCapsVersion = generateVerificationString(discoverInfo, "sha-1"); addDiscoverInfoByNode(ENTITY_NODE + '#' + currentCapsVersion, discoverInfo); if (lastLocalCapsVersions.size() > 10) { String oldCapsVersion = lastLocalCapsVersions.poll(); sdm.removeNodeInformationProvider(ENTITY_NODE + '#' + oldCapsVersion); } lastLocalCapsVersions.add(currentCapsVersion); caps.put(currentCapsVersion, discoverInfo); if (connection != null) jidCaps.put(connection.getUser(), new NodeVerHash(ENTITY_NODE, currentCapsVersion, "sha-1")); final List<Identity> identities = new LinkedList<Identity>(ServiceDiscoveryManager.getInstanceFor(connection).getIdentities()); sdm.setNodeInformationProvider(ENTITY_NODE + '#' + currentCapsVersion, new NodeInformationProvider() { List<String> features = sdm.getFeaturesList(); List<PacketExtension> packetExtensions = sdm.getExtendedInfoAsList(); @Override public List<Item> getNodeItems() { return null; } @Override public List<String> getNodeFeatures() { return features; } @Override public List<Identity> getNodeIdentities() { return identities; } @Override public List<PacketExtension> getNodePacketExtensions() { return packetExtensions; } }); // Send an empty presence, and let the packet intercepter // add a <c/> node to it. // See http://xmpp.org/extensions/xep-0115.html#advertise // We only send a presence packet if there was already one send // to respect ConnectionConfiguration.isSendPresence() if (connection != null && connection.isAuthenticated() && presenceSend) { Presence presence = new Presence(Presence.Type.available); connection.sendPacket(presence); } }
/** * Updates the local user Entity Caps information with the data provided * * If we are connected and there was already a presence send, another * presence is send to inform others about your new Entity Caps node string. * * @param discoverInfo * the local users discover info (mostly the service discovery * features) * @param identityType * the local users identity type * @param identityName * the local users identity name * @param extendedInfo * the local users extended info */ public void updateLocalEntityCaps() { Connection connection = weakRefConnection.get(); DiscoverInfo discoverInfo = new DiscoverInfo(); discoverInfo.setType(IQ.Type.RESULT); discoverInfo.setNode(getLocalNodeVer()); if (connection != null) discoverInfo.setFrom(connection.getUser()); sdm.addDiscoverInfoTo(discoverInfo); currentCapsVersion = generateVerificationString(discoverInfo, "sha-1"); addDiscoverInfoByNode(ENTITY_NODE + '#' + currentCapsVersion, discoverInfo); if (lastLocalCapsVersions.size() > 10) { String oldCapsVersion = lastLocalCapsVersions.poll(); sdm.removeNodeInformationProvider(ENTITY_NODE + '#' + oldCapsVersion); } lastLocalCapsVersions.add(currentCapsVersion); caps.put(currentCapsVersion, discoverInfo); if (connection != null) jidCaps.put(connection.getUser(), new NodeVerHash(ENTITY_NODE, currentCapsVersion, "sha-1")); sdm.setNodeInformationProvider(ENTITY_NODE + '#' + currentCapsVersion, new NodeInformationProvider() { List<String> features = sdm.getFeaturesList(); List<Identity> identities = new LinkedList<Identity>(ServiceDiscoveryManager.getIdentities()); List<PacketExtension> packetExtensions = sdm.getExtendedInfoAsList(); @Override public List<Item> getNodeItems() { return null; } @Override public List<String> getNodeFeatures() { return features; } @Override public List<Identity> getNodeIdentities() { return identities; } @Override public List<PacketExtension> getNodePacketExtensions() { return packetExtensions; } }); // Send an empty presence, and let the packet intercepter // add a <c/> node to it. // See http://xmpp.org/extensions/xep-0115.html#advertise // We only send a presence packet if there was already one send // to respect ConnectionConfiguration.isSendPresence() if (connection != null && connection.isAuthenticated() && presenceSend) { Presence presence = new Presence(Presence.Type.available); connection.sendPacket(presence); } }