Xmpp: Angularjs + Strophe.js
I have a basic XMPP client working on strophe.js. On login I create handlers such as connect = new Strophe.Connection('http://localhost/http-bind'); ... ... connect.addHandler
Solution 1:
Wrap Strophe in an Angular Service. Angular Services are meant to be use as singletons, so you will be able to instantiate the Strophe Service once, and use it everywhere (using Dependency Injection).
Solution 2:
As suggested above (or bellow) I wrapped strophe in a service so my login "mechanism" looks like this:
.controller('loginCtrl', function(xmppAuth) {
xmppAuth.auth(login, password);
})
any my service:
.service('xmppAuth', function() {
return {
auth: function(login, password) {
connect = newStrophe.Connection('http://mydomain.net/http-bind');
connect.connect(login, password, function (status) {
if (status === Strophe.Status.CONNECTED) {
// we are in, addHandlers and stuff
}
}
}
}
})
Solution 3:
Or may be you can create a module for Strophe and then include the module in your app, and then include strophe as a variable where ever you want to use it.
Post a Comment for "Xmpp: Angularjs + Strophe.js"