开发者

How to implement group chat (MUC) using JsJac?

I am looking for sample code to implement group chat using XMPP javascript library开发者_开发技巧 JSJac.


Just completed an group chat using XMPP with muckl 4.4 and OpenFire. The key issue is getting the Reverse Proxy up and running. Since JSJac uses http-bind in many cases, you have to communicate with a http-bind server. These servers are usually on a different port than your web server providing your javascript files.

This causes cross-domain violations, and it won't work. Here is a good link that talks about it: http://www.enavigo.com/2008/10/14/setting-up-jsjac-with-openfire-352/


Assuming you already have a connection to jabber (con) here is a quick example for how to connect to a group chat.

//Set the JID with resource
//Example: my_username@my_domain/my_chat_client
var u_jid = "my_username@my_domain/my_chat_client"

//Set the Full Room ID with your username as the resource
//Example: room_name@conference.my_domain/my_username
var full_room_id = "room_name@conference.my_domain/my_username";

var joinPacket = new JSJaCPresence();
joinPacket.setTo(full_room_id);

//Build item affiliation element
var inode = joinPacket.buildNode("item");
inode.setAttribute("affiliation","none");
inode.setAttribute("jid",u_jid);
inode.setAttribute("role","participant");

//Build X Element (with item affiliation child)
var xnode = joinPacket.buildNode("x", [inode]);
xnode.setAttribute("xmlns", "http://jabber.org/protocol/muc#user");

//Append new nodes to join packet
joinPacket.appendNode(xnode);

//Set status in room
joinPacket.setStatus('available');

var success = con.send(joinPacket, function(data) { console.log(data.getDoc()); });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜