1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-22 20:12:07 +01:00

Update disco.md

This commit is contained in:
Jesus Fuentes 2018-04-03 07:15:16 -05:00
parent a9ca1a0989
commit 32f8c345fb

View file

@ -3,7 +3,7 @@ Service Discovery
[Back](index.md) [Back](index.md)
The service discovery extension allows to discover items and information about The service discovery extension allows one to discover items and information about
XMPP entities. Follow these links to learn how to use this extension. XMPP entities. Follow these links to learn how to use this extension.
* Manage XMPP entity features * Manage XMPP entity features
@ -92,14 +92,18 @@ ServiceDiscoveryManager that will provide information concerning a node named
ServiceDiscoveryManager.getInstanceFor(connection).setNodeInformationProvider( ServiceDiscoveryManager.getInstanceFor(connection).setNodeInformationProvider(
"http://jabber.org/protocol/muc#rooms", "http://jabber.org/protocol/muc#rooms",
new NodeInformationProvider() { new NodeInformationProvider() {
public List getNodeItems() { public List<DiscoverItems.Item> getNodeItems() {
ArrayList answer = new ArrayList(); List<DiscoverItems.Item> answer = new ArrayList<>();
Iterator rooms = MultiUserChat.getJoinedRooms(connection); Iterator rooms = MultiUserChat.getJoinedRooms(connection);
while (rooms.hasNext()) { while (rooms.hasNext()) {
answer.add(new DiscoverItems.Item((String)rooms.next())); answer.add(new DiscoverItems.Item((String)rooms.next()));
} }
return answer; return answer;
} }
public List<String> getNodeFeatures() {...}
public List<DiscoverInfo.Identity> getNodeIdentities() {...}
public List<ExtensionElement> getNodePacketExtensions() {...}
}); });
``` ```
@ -131,7 +135,7 @@ ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(co
// This example gets the items associated with online catalog service // This example gets the items associated with online catalog service
DiscoverItems discoItems = discoManager.discoverItems("plays.shakespeare.lit"); DiscoverItems discoItems = discoManager.discoverItems("plays.shakespeare.lit");
// Get the discovered items of the queried XMPP entity // Get the discovered items of the queried XMPP entity
Iterator it = discoItems.getItems(); Iterator it = discoItems.getItems().iterator();
// Display the items of the remote XMPP entity // Display the items of the remote XMPP entity
while (it.hasNext()) { while (it.hasNext()) {
DiscoverItems.Item item = (DiscoverItems.Item) it.next(); DiscoverItems.Item item = (DiscoverItems.Item) it.next();
@ -175,7 +179,7 @@ ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(co
// This example gets the information of a conference room // This example gets the information of a conference room
DiscoverInfo discoInfo = discoManager.discoverInfo("balconyscene@plays.shakespeare.lit"); DiscoverInfo discoInfo = discoManager.discoverInfo("balconyscene@plays.shakespeare.lit");
// Get the discovered identities of the remote XMPP entity // Get the discovered identities of the remote XMPP entity
Iterator it = discoInfo.getIdentities(); Iterator it = discoInfo.getIdentities().iterator();
// Display the identities of the remote XMPP entity // Display the identities of the remote XMPP entity
while (it.hasNext()) { while (it.hasNext()) {
DiscoverInfo.Identity identity = (DiscoverInfo.Identity) it.next(); DiscoverInfo.Identity identity = (DiscoverInfo.Identity) it.next();
@ -203,7 +207,7 @@ Once you have your ServiceDiscoveryManager you will be able to publish items
to some kind of persistent storage. To publish the items of a given XMPP to some kind of persistent storage. To publish the items of a given XMPP
entity you have to first create an instance of _**DiscoverItems**_ and entity you have to first create an instance of _**DiscoverItems**_ and
configure it with the items to publish. Then you will have to send configure it with the items to publish. Then you will have to send
**publishItems(String entityID, DiscoverItems discoverItems)** to your **publishItems(Jid entityID, DiscoverItems discoverItems)** to your
_**ServiceDiscoveryManager**_ where entityID is the address of the XMPP entity _**ServiceDiscoveryManager**_ where entityID is the address of the XMPP entity
that will persist the items and discoverItems contains the items to publish. that will persist the items and discoverItems contains the items to publish.
@ -214,13 +218,17 @@ In this example we can see how to publish new items:
``` ```
// Obtain the ServiceDiscoveryManager associated with my XMPPConnection // Obtain the ServiceDiscoveryManager associated with my XMPPConnection
ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection); ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection);
// Create a DiscoverItems with the items to publish // Create a DiscoverItems with the items to publish
DiscoverItems itemsToPublish = new DiscoverItems(); DiscoverItems itemsToPublish = new DiscoverItems();
DiscoverItems.Item itemToPublish = new DiscoverItems.Item("pubsub.shakespeare.lit"); Jid jid = JidCreate.from("pubsub.shakespeare.lit");
DiscoverItems.Item itemToPublish = new DiscoverItems.Item(jid);
itemToPublish.setName("Avatar"); itemToPublish.setName("Avatar");
itemToPublish.setNode("romeo/avatar"); itemToPublish.setNode("romeo/avatar");
itemToPublish.setAction(DiscoverItems.Item.UPDATE_ACTION); itemToPublish.setAction(DiscoverItems.Item.UPDATE_ACTION);
itemsToPublish.addItem(itemToPublish); itemsToPublish.addItem(itemToPublish);
// Publish the new items by sending them to the server // Publish the new items by sending them to the server
discoManager.publishItems("host", itemsToPublish); Jid jid2 = JidCreate.from("host");
discoManager.publishItems(jid2, itemsToPublish);
``` ```