2015-08-28 5 views
0

Я использую strophe js с сервером xmpp. Я отправляю от клиента strophe сообщение другому клиенту. Клиент получает сообщение.FromCLient я могу отправить только одно сообщение для строфа клиента. Клиент-клиент получает только один message.Why Вот мой код:Strophe js получает только одно сообщение

var connection = new Strophe.Connection('http://localhost:5280/http-bind/'); 

    connection.connect('[email protected]', 'secret', function (status) 
     { 
      if (status == Strophe.Status.CONNECTED) 
      { 
       console.log('Connected to server') 
       //connection.jid='[email protected]' 
       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: '[email protected]/BBXFRONT', type: 'chat'}).c('body').t('AAAAAA'); 
       connection.send(sendMessageQuery); 
      } 
     }); 
    var on_chat_message=function(msg) { 
     var sendMessageQuery = $msg({to: '[email protected]/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; 
} 

ответ

-1

Каждая вещь в порядке, но и может изменить ниже упоминания строку этой connection.addHandler (on_chat_message, нулевой 'сообщение', NULL, NULL, NULL);

свою работу contiue

2

Я знаю, что это старый нить, но у меня была проблема с XMPP, так что я наткнулся на ваш мир кода. Я проверил это, и проблема здесь

var elems = msg.getElementsByTagName('body'); 
var message=Strophe.getText(body); 

Вы определяете elems, а затем получить текст из тела элемента и тело элемент не определен в этой точке. Поскольку getElementsByTagName возвращает массив, этот кусок кода Шоуда выглядеть так:

var body = msg.getElementsByTagName('body'); 
var message=Strophe.getText(body[0]); 

Я знаю, что это не имеет значения больше, но это может помочь кому-то, кто имеет проблемы с XMPP/строфы иметь работу пример.

Смежные вопросы