Showing posts with label chat rooms. Show all posts
Showing posts with label chat rooms. Show all posts

Friday, 20 July 2012

XMPP CHAT ROOM MECHANISM # PART-2

In last we have seen how to get list of all available rooms in server. This post is about how to use those information to chat in a room.

Once user get list of all room. He needs to choose one room out of it to chat with. User will send presence to existing room. Here there is a little bit change in presence stanza. User needs to add nick name for the room. All other user will see him as his nick name rather than username. e.g.
<presence from='{user-jid}/{resource}' to='{room-id}@conference.domain/{nick-name}'></presence>
Server will send presence to all the members of the room. As if any user joins room later, he will also be sent the presence. This way server informs all users of chat room about joining and leaving event of any user.
<presence to='{user-jid}/{resource}' from='{room-id}@conference.domain/{nick-name}'>
<x xmlns='http://jabber.org/protocol/muc#user'>
<item role='participant' affiliation='none'></item>
</x>
</presence>
Once user gets successfull presence. I have mentioned "successfully", as there are some conditions when user can not enter in a room. In that case server will return a error presence stanza. You can get more details about such stanze from here. If some user have already sent some message the room. User will get all those message as following format whenever he will join a room.
<message to='{user-jid}/{resource}' from='{room-id}@conference.domain' type='groupchat'>
<subject>us.country</subject>
<delay stamp='2012-07-18T18:02:24.328Z' from='{room-id}@conference.domain' xmlns='urn:xmpp:delay'></delay>
<x stamp='20120718T18:02:24' from='{room-id}@conference.domain' xmlns='jabber:x:delay'></x>
</message>
Once user joins a room. He can start sending message to the room. Here user must provide type attribute for presence stanza having value as "groupchat". Describe as following xml.
<message type='groupchat' from = '{user-jid}/{resource}' to ='{room-id}@conference.domain'>
<body>dfdf</body>
</message>
Whatever message is being sent to chat room. Room will send that message to all current users of the room.
<message to='{user-jid}/{resource}' from='{room-id}@conference.domain/{nick-name}' type='groupchat'>
<body>dfdf</body>
</message>
Now when user gets tired of chatting with bunch of people. He would like to leave the room. He needs to send unavailable presence stanza to room's jid, including nickname also. Here nick name is important because a room identifies user based on their nick name. So when you join a room. It will lock that nick name for you. If you are leaving it, you need to make server to unlock the nick name.
<presence from='{user-jid}/{resource}' to='{room-id}@conference.domain/{nick-name}' type='unavailable'></presence>
Server will send user's presence details to all user who have joined the room. The user, who will join the room after that, will not get details about that user. Here if you notice. Server has added a role related information to stanza. Same type of information have been added when user sends presence stanza for joining. This role defines what can this user do with this room. I will post more details about that afterwards.
<presence to='{user-jid}/{resource}' type='unavailable' from='{room-id}@conference.domain/{nick-name}'>
<x xmlns='http://jabber.org/protocol/muc#user'>
<item role='none' affiliation='none'></item>
</x>
</presence>
Let me know if you have any queries regarding this post.

References : http://xmpp.org/extensions/xep-0045.html/

Thursday, 19 July 2012

XMPP Chat room mechanism # Part-1

XMPP protocol provides specification for multi-user chatting(MUC). It is about service provider to implement it. You need to enable MUC from server side. Provider would also give facility to create persistent chat rooms. In terms of XMPP, chat room is known as conference. User can also create a new conference from client program.

When user is loggin in, he needs to ask for available service on server side. User need to send following XML to server.

<iq type='get' from='{user-jid/resource}' to='domain' id='discoitem1'>
<query xmlns='http://jabber.org/protocol/disco#items'/>
</iq>

Server will send back all available services. Services will be sent as XML items. Each item contains service name and service JID.

<iq to='{user-jid/resource}' id='discoitem1' from='domain' type='result'>
<query xmlns='http://jabber.org/protocol/disco#items'>
<item name='User Search' jid='search.domain'></item>
<item name='Socks 5 Bytestreams Proxy' jid='proxy.domain'></item>
<item name='Public Chatrooms' jid='conference.domain'></item>
<item name='Publish-Subscribe service' jid='pubsub.domain'></item>
</query>
</iq>

Once user gets all available services. It needs to be confirm whether conference service is there or not. If it is available user can ask for available chat rooms. These are all persistent chat rooms on the server.

<iq from='{user-jid/resource}' id='discoRooms' to='conference.domain' type='get'>
<query xmlns='http://jabber.org/protocol/disco#items'/>
</iq>

Server will send back all back all available chat rooms in following XML format.

<iq to='{user-jid/resource}' id='discoRooms' from='conference.domain' type='result'>
<query xmlns='http://jabber.org/protocol/disco#items'>
<item name='university' jid='room1@conference.domain'></item>
<item name='country' jid='room2@conference.domain'></item>
</query>
</iq>

Now user is ready to join any room, he wants. User just needs to send one presence to the server. I will include more details about the same topic in next post. Stay in touch

Thursday, 12 July 2012

OpenFire Sub Group

XMPP has concept of chat rooms. A chat room is basically a conference room where users can discuss on some points. But Yahoo has provided room facility as social chatting rooms where any member can join the group and chat with other members. In this feature "nested chat rooms" are provided.

XMPP is not basically providing nested or child chat rooms. But twisting the logic little bit can make it possible with normal XMPP also.

Recall the concepts of domain name. Facebook has domain "facebook.com". Then they have started services of application. They bought sub domain. That became "apps.facebook.com".

Similarly in XMPP suppose you are creating chat room with name University. The JID will be something like "university@domain.com". Now you want different universities as sub chat room of this one. Just create sub University as "oxford.university@domain.com". The main logic that you need to take care is at the client side. You need to show this rooms in tree structure so that user will see it as sub chat room instead of independent chat room.

Creating chat rooms from admin panel is very easy. It is just a html form filling task. But for creating a chat room from client is real programming stuff. You can get information about it from this link. Remember in XMPP room has many types. If you want to keep the room alive forever. You will have to create persistent room. Other rooms will be removed as soon as the last occupant will leave the room.

Let me know if you have any queries regarding all this.