我尝试使用 strophe + ejabberd 来制作类似网络聊天的东西。
我已经做了什么:
- 当我登录网站时,我还向 ejabberd 进行身份验证(以实现 RID 和 SID),
- 登录完成后,我附加从上下文处理器获得的 RID 和 SID,
- 连接状态似乎是:连接建立,日志:
.
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);