我尝试创建一个Ionic 3移动聊天。我的代码如下所示:
onRoster(a) {
console.log("onRoster");
return true;
}
onRosterChanged(a) {
console.log("onRosterChanged");
return true;
}
onPresence(a) {
console.log("onPresence");
return true;
}
onMessage(a) {
console.log("onMessage");
return true;
}
login(jid, sid, rid) {
console.log("chat login");
if(!this.chat) {
console.log('creo connessione chat');
this.chat = new Strophe.Connection(Configurazione.chatUrl);
}
let chatObj = this;
//this.chat.connect(username + "@" + Configurazione.chatHost, password, chatObj.verificaConnessioneXMPP);
this.chat.attach(jid, sid, rid, chatObj.verificaConnessioneXMPP)
}
verificaConnessioneXMPP(stato) {
let chatObj = this;
switch(stato) {
case Strophe.Status.ATTACHED:
case Strophe.Status.CONNECTED:
console.log("logged");
let iq = $iq({type: 'get'}).c('query', {xmlns: 'jabber:iq:roster'});
console.log(iq);
console.log("send iq");
this.chat.sendIQ(iq, function(iq) { chatObj.onRoster(iq); }, function() { chatObj.onRoster(0); }, 1000);
this.chat.addHandler(chatObj.onRosterChanged, "jabber:iq:roster", "iq", "set");
this.chat.addHandler(chatObj.onMessage, null, "message", "chat");
break;
case Strophe.Status.DISCONNECTED:
console.log("not logged");
break;
default:
console.log("Altro stato: " + stato);
break;
}
return true;
}
我可以登录我的XMPP服务器,但我无法发送IQ(this.chat.sendIQ),我的回调函数永远不会被调用。 问题是什么?我无法找到