这是我在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);
}
}
我只能发送和接收一条消息,之后我无法发送或收到任何消息。
感谢。
答案 0 :(得分:4)
我认为您需要在return true
的末尾使用onMsgReceive
。如果你没有返回true
,它将完成这个处理程序