Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XEP-0080 User Location in Smack Library

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.

like image 830
Kristof Avatar asked Mar 05 '10 14:03

Kristof


2 Answers

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.

like image 157
Bill Barnhill Avatar answered Oct 18 '22 18:10

Bill Barnhill


I covered a pure PEP based approach as an alternative method in detail for Android here: https://stackoverflow.com/a/26719158/406920.

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

like image 41
dbotha Avatar answered Oct 18 '22 17:10

dbotha