Adnan
Adnan

Reputation: 2996

How to implement group chat (MUC) using JsJac?

I am looking for sample code to implement group chat using XMPP javascript library JSJac.

Upvotes: 0

Views: 1970

Answers (2)

Jason Palmer
Jason Palmer

Reputation: 731

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: [email protected]_domain/my_username
var full_room_id = "[email protected]_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()); });

Upvotes: 1

International Spectrum
International Spectrum

Reputation: 271

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/

Upvotes: 1

Related Questions