My XMPP client in AngularJS, inspired by this stackoverflow link.
<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5d282e382f1d282e382f7331323e3c31">[email protected]</a>
can send messages successfully, but <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="87f2f4e2f5c7f2f4e2f5a9ebe8e4e6eb">[email protected]</a>
doesn't receive them as expected when messaging from <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="94f5fafbe0fcf1e6d4e1e7f1e6baf8fbf7f5f8">[email protected]</a>
.
I'm unsure if I've implemented the addHandler
and onMessage
functions correctly. Can anyone offer assistance?
<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 = "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="add8dec8dfedd8dec8df83c1c2cecc91d3c4c8cac7">[email protected]</a>";
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("Connection successful");
//trying to send message
var message = "Hello";
var to = "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d1b0bfbea5b9b4a391a4a2b493dfaabda9bab295d7a0acaead">[email protected]</a>";
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('Sent message to ' + to + ': ' + message);
}
//adding handler for receiving messages
connect.addHandler(onMessage, null, "message", null, null, null);
var onMessage = function (message){
console.log('Received message');
return true;
}
}
})
}
}
})
</script>
</body>
</html>