I’m doing a chat application accessible via native apps on the iPhone and Android. I’ve spent some time researching how it would be done, but I sill don’t have quite a good grasp of it yet. For example, I’ve seen and followed the tutorial on mobile tuts here (http://mobile.tutsplus.com/tutorials/iphone/building-a-jabber-client-for-ios-server-setup/)
However, let’s say that I want my chat apps to be able to go beyond the login/check & send messages, how would I do that?
For example, one feature I would like to add is to be able to search the userbase for criteria such as:
- users online now
- users who meet certain critera (location, age, etc)
If, for example, I am using ejabberd or Openfire as my xmpp server, how do I add these new custom APIs that would be accessible from iPhone/Android?
I’m just making a rough example here, but maybe it would be nice to be able to do something like this:
-(NSArray*) findUsersInCity:(NSString *)cityName
How would I be able to make the xmpp server pass me back a list of those users who match the cityname criteria?
Thank you in advance!!
There are several different ways to extend an XMPP server:
XMPP Component
Components exist separately to the XMPP server. You can write them in pretty much any language and they connect to the XMPP server following a protocol (http://xmpp.org/extensions/xep-0114.html). A component registers to handle a subdomain of a server and any messages/IQ’s addressed to that component are passed straight from the XMPP server to your code, for you to process and respond. For instance, a message could be addressed to
user@search.domain.com/resourceinstead ofuser@domain.com/resource.The benefit of a Component is that it should work with any XMPP server (that supports components anyway, which are most of the main ones). Should you change from Openfire to ejabberd for instance, you shouldn’t have to do any work. The downside is that they can’t access data within the server itself. Fine if you want to provide access to external data (say your own database) but might not be sufficient.
Plugin/Module
These are server-specific and must be written in the same language as the server. Openfire has plugins, ejabberd has modules. These can integrate with the XMPP server and give you far more options. Switching XMPP servers would require starting development from scratch however. If you want to make a plugin for Openfire, have a look at the Plugin Guide and the Openfire API: API Docs. The API is extensive and you can get at most of the data available to the server.
Modify Source Code
Not a good option but possibly worth mentioning – you could download the source code for Openfire, make your modifications and re-build it. I would only do this if you were certain the API can’t give you what you need.