DreamSea

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

XEP-0080 User Location in Smack Library.

http://xmpp.org/extensions/xep-0080.html

http://stackoverflow.com/questions/2387319/xep-0080-user-location-in-smack-library


Hi,

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.

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 athttp://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):

more to see: http://fisheye.igniterealtime.org/browse/~raw,r=11613/svn-org/smack/trunk/documentation/extensions/pubsub.html

demo:http://fisheye.igniterealtime.org/browse/svn-org/smack/trunk/test/org/jivesoftware/smackx/pubsub/CarExtension.java?hb=true

project test pubsub https://github.com/squaremo/smackx-pubsub

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.

//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.

 

 

http://community.igniterealtime.org/message/202963#202963

Hi,

Â

I need some help. I'm completely new to developing on OpenFire (actualy any kind of server development) and to Smack API.

In my academic project I need to create a client-server application (client on Android) that enables server to track client geolocation. As I have gathered yet XEP-0080 would be the solution. I have to use XMPP protocol just for that, I don't need it for any chat, presence or other IM stuff.

I've googled much and know that there is no official support for XEP-0080. But I need some basic pointers for doing this.

On the client side I have to use SmackAPI, that I know. But what to I have to do on server side, on the OpenFire itself? Do I have to create a new plug-in for it? How do plug-ins work in general? I develop my own and integrate it on the server (install it) and it's always running or something else?

Â

I know these are really novice questions, but I really need some help, just a few starting pointers. I have experience in Java programming and developing apps for Android, but no experience in server side of things.

Â

Any kind of help is welcome, any kind at all.

Â

Thanks in advance

;

Answer

1:

Hi,

Â

as far as I understand XEP-0080 there's nothing which must be implemented on server side as long as the XMPP server supports Pubsub and PEP. Openfire supports this so it's only a client issue to implement XEP-0080.

Â

LG

2:

From what I can see, you can do this easily with the pubsub API in Smack by simply creating a UserLocation payload class that can be used both to publish and handle events.  This would simply be an extension of the PacketExtension class and then you would only need a provider class to parse the incoming events and reconstruct your UserLocation class.

Â

Some sample code can be seen here in the test cases for the pubsub extension in Smack.

Â

You could also use the existing SimplePayload class to both send and receive, as it will carry your xml data, but then you would have to parse that xml into something meaningful to actually use it.  This is why I recommend the first approach since it does that for you and you can avoid directly using xml altogether.

Â

This does require Smack from the source code though, since that API is not in the latest release version

3:

Hi,

Â

we at buddycloud.com do some geoloc stuff via pubsub! You may just join our groupchat atseehaus@channels.buddycloud.com

Â

It's actually the reason that asmack exists, so feel free to get some input on geoloc, pubsub and pep there :-) The server implementation is actually all about managing pubsub nodes....

收集另一个开源工程中包含geolocation 

Jitsi:  SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.

http://java.net/projects/jitsi/sources

net.java.sip.communicator.impl.protocol.jabber.extensions.geolocation.*


posted on 2011-07-28 09:43  DreamSea  阅读(1009)  评论(0编辑  收藏  举报