1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-12-22 20:47:57 +01:00

Merge pull request #229 from fuentesj11/update-disco-doc

Update disco doc
This commit is contained in:
Florian Schmaus 2018-04-04 14:50:20 +02:00 committed by GitHub
commit f8f70bc5fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,7 +3,7 @@ Service Discovery
[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.
* Manage XMPP entity features
@ -92,14 +92,19 @@ ServiceDiscoveryManager that will provide information concerning a node named
ServiceDiscoveryManager.getInstanceFor(connection).setNodeInformationProvider(
"http://jabber.org/protocol/muc#rooms",
new NodeInformationProvider() {
public List getNodeItems() {
ArrayList answer = new ArrayList();
Iterator rooms = MultiUserChat.getJoinedRooms(connection);
public List<DiscoverItems.Item> getNodeItems() {
MultiUserChatManager mucManager = MultiUserChatManager.getInstanceFor(connection);
List<DiscoverItems.Item> answer = new ArrayList<>();
Iterator<Jid> rooms = mucManager.getJoinedRooms().iterator();
while (rooms.hasNext()) {
answer.add(new DiscoverItems.Item((String)rooms.next()));
answer.add(new DiscoverItems.Item(rooms.next()));
}
return answer;
}
public List<String> getNodeFeatures() {...}
public List<DiscoverInfo.Identity> getNodeIdentities() {...}
public List<ExtensionElement> getNodePacketExtensions() {...}
});
```
@ -131,7 +136,7 @@ ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(co
// This example gets the items associated with online catalog service
DiscoverItems discoItems = discoManager.discoverItems("plays.shakespeare.lit");
// 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
while (it.hasNext()) {
DiscoverItems.Item item = (DiscoverItems.Item) it.next();
@ -175,7 +180,7 @@ ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(co
// This example gets the information of a conference room
DiscoverInfo discoInfo = discoManager.discoverInfo("balconyscene@plays.shakespeare.lit");
// 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
while (it.hasNext()) {
DiscoverInfo.Identity identity = (DiscoverInfo.Identity) it.next();
@ -203,7 +208,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
entity you have to first create an instance of _**DiscoverItems**_ and
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
that will persist the items and discoverItems contains the items to publish.
@ -214,13 +219,17 @@ In this example we can see how to publish new items:
```
// Obtain the ServiceDiscoveryManager associated with my XMPPConnection
ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection);
// Create a DiscoverItems with the items to publish
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.setNode("romeo/avatar");
itemToPublish.setAction(DiscoverItems.Item.UPDATE_ACTION);
itemsToPublish.addItem(itemToPublish);
// Publish the new items by sending them to the server
discoManager.publishItems("host", itemsToPublish);
Jid jid2 = JidCreate.from("host");
discoManager.publishItems(jid2, itemsToPublish);
```