XEP-0080 User Location in the Smack Library

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

early.

+7
java pep xmpp smack
source share
3 answers

Christophe is right, the doc is rare, but they are getting better. However, there is a good, although difficult to find, set of documents on extensions. PubSub is located at http://www.igniterealtime.org/fisheye/browse/~raw,r=11613/svn-org/smack/trunk/documentation/extensions/pubsub.html .

After you sent an IQ Provider custom route from scratch with the extension, I found it was easier to do this using managers as much as possible. The developers who wrote the managers distracted a lot of pain points.

Example (the version of one rcollier modified for geolocation is written 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 it's the hard way :). Just remembered that now PEPManager ...

 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 will need to write the GeoLocProvider and GeoLoc classes.

+7
source share

As an alternative method for Android, here I have examined in detail a simple PEP-based approach: https://stackoverflow.com/a/416829/

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

+1
source share

Take a look at existing code to implement other extensions. This will be your best example of how to develop with the current library. Unfortunately, there is no developer guide that I know of, so I just tried to understand some of the basics until I felt comfortable with the environment. Hint. Use the provider extension tool to add custom providers for string extensions.

You can ask questions on the Smack developer forum and add your code back to the project from here. If you create an implementation of this extension, then you can potentially get commit privileges yourself if you want.

0
source share

All Articles