XMPP: AngularJs + Strophe.js
Ich habe einen grundlegenden XMPP-Client, der an strophe.js arbeitet.
Beim Einloggen erstelle ich Handler wie
connect = new Strophe.Connection('http://localhost/http-bind');
...
...
connect.addHandler(on_message, null, "message", "chat");
connect.addHandler(on_presence, null, "presence");
...
...
und dann "höre" ich denen zu
function on_presence(presence) {
// handling presence
}
function on_message(presence) {
// handling presence
}
Also versuche ich, es in AngularJS "umzuwandeln". Der erste Teil ist ziemlich einfach. Ich habe einen Controller, der den Login-Teil gut handhabt:
angular.module('app').controller('loginCtrl', function($scope) {
connect = new Strophe.Connection('http://website.com/http-bind');
connect.connect(data.jid, data.password, function (status) {
if (status === Strophe.Status.CONNECTED) {
connect.addHandler(on_message, null, "message", "chat");
connect.addHandler(on_presence, null, "presence");
}
}
})
Aber wie beginne ich tatsächlich, diese Ereignisse (on_message, on_presence) im Kontext von Angular auf allen Controllern, die ich habe, abzuhören?