Best way to integrate an XMPP Server into Webapplication - xmpp

I'm working on a middle size community project, using php and the php framework symfony2 atm.
We are planning to integrate XMPP as a support chat and premium feature for our users. The users will be able to connect via a webclient and also via normal xmpp clients.
So here are my questions:
About the Rosters: I want to have the users from the friends list listed in the users contact list. I know that this can be done with rosters. But how can I implement this on a simple and stable way? Is there a good Server implementation that can get the users roster out of a sql database like pgsql?
What happens on the client when the roster datas are beeing changed while the user is logged in on the xmpp server?
Can I group the users that are listed in the roster of a user?
Which XMPP server project would you recommend for that kind of project?
Thanks for your help in advance!

most existing XMPP servers support all popular DBRMs. So this should be no problem.
probably nothing when you make the changes directly do the database. So have to find a server where you can initiate a roster push to all connected clients. See also the XMPP RFCs for roster updates.
yes, roster groups are a core feature of XMPP.
You can find a list of XMPP servers here: http://xmpp.org/xmpp-software/servers/ You have to check which servers support pgsql and allow you to update the roster and initiate the roster pushes to connected resources.

Related

How to integrate with OpenFire XMPP server to receive roster info for users?

I need to create small auxiliary server that is part/integrates with OpenFire server in order to get roster for a given user.
I was looking for some plugin/api call that given the user JID to return his contacts and their online status.
All-in-all I may end up changing OpenFire's code but I was hoping that there is a easier solution
All though the links provided by Manasi would work for you. However those links refers to user service plugin which has been depricated by openfire.
They recommend to use REST API plugin.
You'll see list of all plugins here.
You should read about retrieving user roster and their presence .
You could try using the user service plugin of openfire that returns a host of information of the user as well as its rosters.
for documentation click here.
You can get the roster information by this url.

Setup XMPP server to use other JSON API on webserver for user storage and authentication

We are developing a consumer hardware product. Each device is registered on a central webserver and the owner also have a user account to which the device is linked. The owner may also choose to share the device with other users.
Now, to solve the problem of getting through firewalls etc we are using XMPP: the user access his/her devices using an iOS/Android app. The app connects to the XMPP-server and so does the hardware devices. So the app can access the devices by sending custom XMPP stanzas.
Currently the device and the mobile app use the same JID, so the device will allow messages only from the same bare JID as itself uses. To allow for sharing devices we are planning to use the roster instead: the device will get its own JID ("hw381983829#thexmppserver.com") and will accept stanzas from all JID's in its roster.
The problem I'm having is that the users, devices and device-sharing data are stored on the webserver. I would like to use this same information on the XMPP-server: all users and devices on the webserver are allowed to login to XMPP and the roster of a device is the same as the users that may access it. This information can be accessed through a JSON API.
One way would be to mirror changes as they happen, but I don't like that idea since there are too many steps that could go wrong.
The best solution I can think of is to let the XMPP server use the JSON API instead of its builtin database. It would be read-only, but that is not a problem since all registration and sharing should be done on the webserver.
Any ideas on how to proceed? The functionality described above is more or less all that we need: we don't need S2S, offline messages, etc. We are currently using Ejabberd, but Prosody or Openfire are perhaps better alternatives?
For authentication, it looks like this ejabberd contribution does exactly what you need:
https://github.com/processone/ejabberd-contrib/tree/master/ejabberd_auth_http
For roster, it is easy to write a custom roster module that will be hitting your HTTP backend instead of query the database thanks to ejabberd API.
You can have a look at mod_roster as a guide to implement the methods: https://github.com/processone/ejabberd/blob/master/src/mod_roster.erl

How can we make ejabberd server use existing users data, instead of creating a new database for roster?

Suppose a website has already registered users, and has a way for them to add and remove friend from their own friendlist through website.
Now, I want to use ejabberd xmpp server for getting presence information in real-time, but I don't want to have xmpp server to create new database for roster.
Is there any way to configure ejabberd to avoid data duplication on both ejabberd server and website server?
If you don't want to write a custom ejabberd module, you can configure ejabberd to load rosters from a SQL database. If all your rosters modifications are done by your webapp, then from ejabberd point of view the DB is "read only", and you could write a SQL view that has the schema expected by ejabberd but uses the data tables you already have.
See table definitions https://github.com/processone/ejabberd/blob/master/src/odbc/mysql.sql , you need "rosterusers" and "rostergroups" table. Note that this approach has some limitations. Changes in roster won't be seen immediately by connected users unless your application informs ejabberd about that, so ejabberd can inform the clients. For this you probably need to write custom code anyway, and learn about roster push http://xmpp.org/rfcs/rfc3921.html#roster
Or you can write your own custom module to access your roster data.
By default Ejabberd use Mnesia database for Users and Roster etc.
You can configure Ejabberd with external database like SQL SERVER, MySQL, Postgress etc.
You have to configure the ejabberd to use external database (ex: odbc) instead of internal database.
Please see the below to configure Ejabberd with MySQL:
http://iohq.net/index.php?title=Building_an_Ejabberd_Server_with_MySql
After that right a sql script to transfer your existing users in "users" and "rosteruser" table with proper subscription value. Changes in roster done directly in "rosteruser" won't be seen immediately by connected users. To resolve this you can get the friend request confirmation event from application logic (php/asp.net/java) and than add roster through XMPP client. Using this process all roster updation events will be reflected on all connected.

Is there a way to determine which Mulit User Conferences (MUC) a user has joined?

I wonder if there is a way to query the XMPP server (passing user JID?) to find out what chat room(s) this user is currently in? If not, can we query jabber server to get a list of all active chat rooms?
BTW we're running ejabber enabled for multiuser chat. A solution using a java library (smack?) would be ideal.
As mentioned by Joe Hildebrand, there is no such a standard feature as it is a privacy violation to allow that over XMPP, so you cannot expect to do that from Smack. Maybe with admin privilege you could have a custom protocol extension that does that but that seems risky.
However, at the server level, you should be able to write a custom module for ejabberd that will query or index all rooms users are in. This is not standard and there is plugin development involved.
There are two (maybe three) XMPP entities that have that information:
the XMPP MUC component which provides the MUC room
the users XMPP client (or better the XMPP library used by the user)
maybe the XMPP server(s) (but let's ignore that)
At the time of writing this, there is no standardized way (in terms of XMPP XEPs) to query that information. As Joe Hildebrand pointed out, this would result in a information leak which is not what we want in most cases.
But you can either extend the MUC component to provide that information (remember XMPP is easily extendable) or the XMPP client library. The usual approach would be via an iq get query. For example:
<iq type='get' from='juliet#capulet.lit/balcony' to='capulet.lit' id='q1'>
<query xmlns='http://jabber.org/protocol/muc#joinedrooms'/>
</iq>
The entities which support that query would then report back the joined rooms of the requested entity. Also they would may announce the http://jabber.org/protocol/muc#joinedrooms feature in their service discovery information.
Note that this is a fictional protocol extension meant as example. I have never seen it in real use
If the MUC component provides this feature then it's not controllable by the client if this information is exposed. But if the client provides this feature then of course he can control who can retrieve this information. You may decide what's the better approach in your case.
Getting all chat rooms is no problem, just use this query.
There seems to be already a question on how to retrieve rooms with smack. Look here.

xmpp/jabber for chat for dating site?

we're in the process of adding text chat to our dating site and I'm considering using xmpp - specifically ejabberd on the server side, and we will be implementing an ajax client.
i'd like to hear from someone with good xmpp experience - is it architecturally suitable for chat on a dating site ? in chat on a dating site anybody can chat one-on-one with anybody - they don't have to be on your 'friends' list. Also we do not want a chat room - only one-on-one chat.
Or is xmpp more suitable for the model where someone has to add you to their friends list before you can with them ?
thanks in advance.
XMPP should work fine for you. Ejabberd, depending on the number of concurrent users you have, should be a fine starting point. Consider using a BOSH library like Strophe.js in your HTML client. If you use that library, you'll want a copy of Professional XMPP Programming with JavaScript and jQuery, which has examples of all of the code you'll need.
You do NOT need to have presence subscriptions in place to send chat messages between users, except in specific server implementations like GoogleTalk. Reducing the number of presence subscriptions will also drastically increase the number of users you can handle concurrently.