【发布时间】:2015-08-28 08:49:57
【问题描述】:
我将 strophe js 与 xmpp 服务器一起使用。我从 strophe 客户端向另一个客户端发送消息。客户端接收消息。从客户端我只能向 strophe 客户端发送一条消息。Strophe 客户端只接收一条消息。为什么?这里是我的代码:
var connection = new Strophe.Connection('http://localhost:5280/http-bind/');
connection.connect('marian112@localhost', 'secret', function (status)
{
if (status == Strophe.Status.CONNECTED)
{
console.log('Connected to server')
//connection.jid='marian12@localhost'
connection.addHandler(on_chat_message, null, 'message', 'chat',null,null);
connection.send($pres().c("priority").t("10"));
connection.addHandler(on_presence, null, 'presence');
connection.addHandler(on_error_iq, null, 'iq', 'error');
connection.send($pres().tree());
console.log(connection.jid);
var sendMessageQuery = $msg({to: 'marian@localhost/BBXFRONT', type: 'chat'}).c('body').t('AAAAAA');
connection.send(sendMessageQuery);
}
});
var on_chat_message=function(msg) {
var sendMessageQuery = $msg({to: 'marian@localhost/BBXFRONT', type: 'chat'}).c('body').t('bbbb');
connection.send(sendMessageQuery);
console.log(msg);
console.log('You have received a message!');
var to = msg.getAttribute('to');
var from = msg.getAttribute('from');
var type = msg.getAttribute('type');
console.log(to+' '+from+' '+type);
var elems = msg.getElementsByTagName('body');
var message=Strophe.getText(body);
console.log(message);
return true;
}
var on_presence=function(stanza) {
console.log(stanza);
return true;
}
var on_error_iq=function(stanza) {
console.log(stanza);
return true;
}
【问题讨论】:
标签: javascript strophe