如何使用JsJac实现群聊(MUC)?

发布于 2024-08-28 19:57:19 字数 49 浏览 3 评论 0原文

我正在寻找使用 XMPP javascript 库 JSJac 实现群聊的示例代码。

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寄风 2024-09-04 19:57:19

刚刚使用 XMPP 与 muckl 4.4 和 OpenFire 完成了一次群聊。关键问题是让反向代理启动并运行。由于 JSJac 在很多情况下使用 http-bind,因此您必须与 http-bind 服务器进行通信。这些服务器通常与提供 JavaScript 文件的 Web 服务器位于不同的端口。

这样就会造成跨域违规,而且行不通。这是一个很好的链接来讨论它:
http://www.enavigo.com/ 2008/10/14/setting-up-jsjac-with-openfire-352/

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/

岁月静好 2024-09-04 19:57:19

假设您已经连接到 jabber (con),这里有一个有关如何连接到群聊的快速示例。

//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()); });

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()); });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文