简体   繁体   中英

XMPP receive only one message at a time

This is my code in javascript:

var user = {};
var handlerReference = null;

var myMessages = myApp.messages('.messages', {
    autoLayout: true
});

function setListener(name, jid) {
    user.name = name;
    user.jid = jid;

    $("#chatScreenTitle").text(user.name);
    handlerReference = connection.addHandler(onMsgReceive, null, 'message', "chat", null, user.jid, {matchBare: true});
}

function onMsgReceive(stanza) {
    console.log($(stanza).children("body").text());
    myMessages.addMessage({
        text: $(stanza).children("body").text(),
        type: "received"
    }, 'append', true);
}

function sendMessage(message) {
    if (message.length == 0) {
        myApp.alert("please enter some text", "alert");
    }
    else {
        var uniqueID = connection.getUniqueId("my:code");             
        var reqChannelsItems = $msg({id: uniqueID, to: user.jid, from: xmpp_user + "@" + XMPP_DOMAIN, type: "chat"}).c("body").t(message);
        connection.send(reqChannelsItems.tree());

        myMessages.addMessage({
            text: message,
            type: "sent"
        }, 'append', true);
    }
}

I can only send and receive one message after that I am not able to send or receive any messsage.

Thanks.

I think you need to use return true at the end of onMsgReceive . If you don't return true it will finish this handler

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM