我尝试使用strophe + ejabberd制作类似网络聊天的内容。
我已经做了什么:
POST: <body rid='406266360' xmlns='http://jabber.org/protocol/httpbind' sid='9c66aa19123e96dc2925c24d4f985d458763eb67'><presence xmlns='jabber:client'><priority>-1</priority></presence><presence to='localhost/m' xmlns='jabber:client'><x xmlns='http://jabber.org/protocol/muc'/></presence></body>
RESP: <body xmlns='http://jabber.org/protocol/httpbind'><success xmlns='urn:ietf:params:xml:ns:xmpp-sasl'/></body>
之后,连接挂起:
POST: <body rid='406266361' xmlns='http://jabber.org/protocol/httpbind' sid='9c66aa19123e96dc2925c24d4f985d458763eb67'/>
当我尝试发送消息时(当它被绞死):
POST: <body rid='406266362' xmlns='http://jabber.org/protocol/httpbind' sid='175e45333109f74c36f9dffbe4e3cc6cffc80df4'><message to='localhost' type='groupchat' xmlns='jabber:client'><body>yrdy</body></message></body>
我得到了:
RESP: <body type='terminate' condition='remote-stream-error' xmlns='http://jabber.org/protocol/httpbind' xmlns:stream='http://etherx.jabber.org/streams'><stream:error><xml-not-well-formed xmlns='urn:ietf:params:xml:ns:xmpp-streams'/></stream:error></body>
什么错了?奇怪的是,在几秒钟后请求被中止,下一个请求再次挂起。当我尝试发送消息时,没有错误,但响应是:
RESP: <body xmlns='http://jabber.org/protocol/httpbind'/>
没有错误(连接仍然连接和验证,但似乎没有传递消息)。
我用来发送消息的代码:
var body = $('#input_text').val(); | // make sure this presence is for the right room
var msg_body = { | if (room === Groupie.room) {
to: Chat.room, | var nick = Strophe.getResourceFromJid(from);
type: 'groupchat' |
} | if ($(presence).attr('type') === 'error' &&
var msg = $msg(msg_body).c('body').t(body); | !Groupie.joined) {
| // error joining room; reset app
Chat.connection.send(msg);
答案 0 :(得分:0)
您可以使用Strophe.js进行附加:
Chat.connection = new Strophe.Connection(Chat.BOSH_SERVICE_URL);
Chat.connection.attach(jid, sid, rid, onConnectHandler);
一旦成功连接,就会调用onConnectHandler 。从那时起,您不必再担心SID和RID(直到页面重新加载)。
另外,您是否了解MUC strophe plugin?
如果你想要一些示例代码来使用/学习,我写了类似于你为Plone做的事情,名为collective.xmpp.chat
javascript可单独重复使用:converse.js