XMPP: AngularJS + Strophe

692 views
Skip to first unread message

Mohsin Patel

unread,
Aug 7, 2014, 12:33:30 AM8/7/14
to str...@googlegroups.com

The basic XMPP with strophe and javascript wants to convert to AngularJS.

.controller('loginCtrl', function(xmppAuth) {
     xmppAuth
.auth(login, password);
})

and in service:

.service('xmppAuth', function() {
   
.return {
        auth
: function(login, password) {
            connect
= new Strophe.Connection(domain);
            connect
.connect(login, password, function (status) {
               
if (status === Strophe.Status.CONNECTED) {
                    connect
.addHandler(on_roster_changed,"jabber:iq:roster", "iq", "set");
                    connect
.addHandler(on_iq, null, "iq","");
                    connect
.addHandler(on_presence, null, "presence");
                    connect
.addHandler(on_message, null, 'message', '');
               
}
           
}
       
}
     
}
});

in js file

var on_presence = function(presence){
   
//code
}

when i run this there is no error. But all handling events like on_presence() method called only once. this is handler event of Strophe Connection object. Is there is any remain in this code or what should i do for handling strophes event with angularJS?

I refered This Link but it not works. In stackOverflow this quetion is on http://stackoverflow.com/questions/25161935/xmpp-angularjs-strophe this link.

Michael Weibel

unread,
Aug 7, 2014, 12:41:27 AM8/7/14
to str...@googlegroups.com
I replied to you on StackOverflow - the handlers need to return true in order to be invoked again.

I think the docs regarding this on http://strophe.im/strophejs/doc/1.1.3/files/strophe-js.html#Strophe.Connection.addHandler are really not that good, a lot of people struggle with that initially. 

Maybe the relevant docs „The handler should return true if it is to be invoked again; returning false will remove the handler after it returns.“ should be written in bold.

- Michael
-- 
Michael Weibel
--
You received this message because you are subscribed to the Google Groups "Strophe" group.
To unsubscribe from this group and stop receiving emails from it, send an email to strophe+u...@googlegroups.com.
To post to this group, send email to str...@googlegroups.com.
Visit this group at http://groups.google.com/group/strophe.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages