XEP-0080 User Location in Smack Library
Asked Answered
P

3

7

I would like to create a simple XMPP client in java that shares his location (XEP-0080) with other clients. I already know I can use the smack library for XMPP and that it supports PEP, which is needed for XEP-0080. Does anyone have an example how to implement this or any pointers, i don't find anything using google.

thanks in advance.

Prejudicial answered 5/3, 2010 at 14:22 Comment(0)
I
8

Kristof's right, the doc's are sparse - but they are getting better. There is a good, albeit hard to find, set of docs on extensions though. The PubSub one is at http://www.igniterealtime.org/fisheye/browse/~raw,r=11613/svn-org/smack/trunk/documentation/extensions/pubsub.html.

After going the from scratch custom IQ Provider route with an extension I found it was easier to do it using the managers as much as possible. The developers that wrote the managers have abstracted away a lot of the pain points.

Example (modified-for-geoloc version of one rcollier wrote on the Smack forum):

ConfigureForm form = new ConfigureForm(FormType.submit);
form.setPersistentItems(false);
form.setDeliverPayloads(true);
form.setAccessModel(AccessModel.open);

PubSubManager manager 
      = new PubSubManager(connection, "pubsub.communitivity.com");
Node myNode = manager.createNode("http://jabber.org/protocol/geoloc", form);

StringBuilder body = new StringBuilder(); //ws for readability
body.append("<geoloc xmlns='http://jabber.org/protocol/geoloc' xml:lang='en'>");
body.append("   <country>Italy</country>");
body.append("   <lat>45.44</lat>");
body.append("   <locality>Venice</locality>");
body.append("   <lon>12.33</lon>");
body.append("   <accuracy>20</accuracy>");
body.append("</geoloc>");

SimplePayload payload = new SimplePayload(
                              "geoloc",
                              "http://jabber.org/protocol/geoloc", 
                              body.toString());
String itemId = "zz234";
Item<SimplePayload> item = new Item<SimplePayload>(itemId, payload);

// Required to recieve the events being published
myNode.addItemEventListener(myEventHandler);

// Publish item
myNode.publish(item);

Or at least that's the hard way :). Just remembered there's a PEPManager now...

PEPProvider pepProvider = new PEPProvider();
pepProvider.registerPEPParserExtension(
    "http://jabber.org/protocol/tune", new TuneProvider());
ProviderManager.getInstance().addExtensionProvider(
   "event", 
   "http://jabber.org/protocol/pubsub#event", pepProvider);
Tune tune = new Tune("jeff", "1", "CD", "My Title", "My Track");
pepManager.publish(tune);

You'd need to write the GeoLocProvider and GeoLoc classes.

Insinuate answered 10/3, 2010 at 17:2 Comment(3)
where can i find this TuneProvider and Tune class in smack or asmack ?Hurty
The example is from the smack documentation. Not sure what implementation of XEP-0118 they are referring too, as Smack still has an open bug to add XEP-0118 support, last update in May 2011. I had cobbled together my own version for an experiment, but don't have the code anymore. I'd throw it together again but don't have the time. There is now a good example of creating your own extension of PEPItem and publishing an item here: oneminutedistraction.wordpress.com/2010/08/26 . That just leaves the parsing part (in the TuneProvider, a PEPProvider).Insinuate
I'm using smack 4.2.0 and I can't find PEPProvider ?Lezlielg
C
1

I covered a pure PEP based approach as an alternative method in detail for Android here: https://mcmap.net/q/1621702/-using-xmpp-for-user-location.

This will be very close to what you'd need to do with regular Smack.

Cosma answered 3/11, 2014 at 17:11 Comment(0)
C
0

Take a look at the existing code for implementations of other extensions. This will be your best example of how to develop with the current library. Unfortunately, there is no developers guide that I know of, so I just poked around to understand some of the basics myself until I felt comfortable with the environment. Hint: Use the providers extension facility to add custom providers for the extension specific stanzas.

You can ask questions on the developer forum for Smack, and contribute your code back to the project from here as well. If you produce an implementation of this extension, then you could potentially get commit privileges yourself if you want it.

Condor answered 5/3, 2010 at 15:24 Comment(2)
First of all, thank you for that quick answer. Do you also know where I can find such implementations ?Prejudicial
They're all part of the existing Smack codebase here (for svn access) svn co svn.igniterealtime.org/svn/repos/smack/trunk smack or you can browse online here igniterealtime.org/fisheye/viewrep/svn-org/smackCondor

© 2022 - 2024 — McMap. All rights reserved.