我有基于this link的基于AngularJS的基本XMPP客户端。 [email protected]
发送消息时成功,但[email protected]
仍然不能接收消息console.log("message")
当[email protected]
发送消息时。AngularJs + Strophe.js接收消息
对于我如何编写addHandler
和onMessage
函数是否正确?
<html>
<head>
<script type="text/javascript" src="bower_components/angular/angular.min.js"></script>
<script type="text/javascript" src="strophe.min.js"></script>
</head>
<body ng-app="myApp">
<div ng-controller="init">
</div>
<script type="text/javascript">
BOSH_SERVICE = 'http://localhost/http-bind';
xmpp_user = "user";
xmpp_domain = "user.local";
xmpp_userdomain = "[email protected]";
xmpp_password = "userpassword";
angular.
module('myApp', []).
controller('init', function(xmppAuth){
xmppAuth.auth(xmpp_userdomain,xmpp_password);
}).
service('xmppAuth', function() {
return {
auth: function(login, password) {
connect = new Strophe.Connection(BOSH_SERVICE);
connect.connect(login, password, function (status) {
if (status === Strophe.Status.CONNECTED) {
console.log("auth pass");
//try send helo
var message = "helo";
var to = "[email protected]";
if(message && to){
var reply = $msg({
to: to,
type: 'chat'
})
.cnode(Strophe.xmlElement('body', message)).up()
.c('active', {xmlns: "http://jabber.org/protocol/chatstates"});
connect.send(reply);
console.log('I sent ' + to + ': ' + message);
}
//addhandler receive messg
connect.addHandler(onMessage, null, "message", null, null, null);
var onMessage = function (message){
console.log('message');
return true;
}
}
})
}
}
})
</script>
</body>
</html>
感谢您的代码。 – Senthil 2015-03-02 18:40:51