Skip to content

Instantly share code, notes, and snippets.

@mikekoro
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikekoro/4cf6a29e58e37ce4d322 to your computer and use it in GitHub Desktop.
Save mikekoro/4cf6a29e58e37ce4d322 to your computer and use it in GitHub Desktop.
angular
.module('app')
.service('xmpp', function($rootScope, $state) {
return {
auth: function(jid, sid, rid) {
// I am using attach instead of connect so you don't need any jid, sid or rid
connect = new Strophe.Connection('http://site.com/http-bind');
connect.attach(jid, sid, rid, function(status) {
if (status === Strophe.Status.ATTACHED) {
//add "Hooks", or Listeners if you will
connect.addHandler(on_presence, null, "presence");
connect.addHandler(on_message, null, "message", "chat");
connect.send($pres());
$state.go('contacts')
} else if (status === Strophe.Status.AUTHENTICATING) {
console.log("AUTHENTICATING");
} else if (status === Strophe.Status.AUTHFAIL) {
console.log("AUTHFAIL");
} else if (status === Strophe.Status.CONNECTING) {
console.log("CONNECTING");
} else if (status === Strophe.Status.DISCONNECTED) {
console.log("DISCONNECTED");
}
});
// "Hooks"
function on_presence(presence) {
// handle presence
return true
} // end of presence
function on_message(message) {
// handle incoming messages
// I have an array $rootScope.messages which is available throghout the whole app.
// e.g. $rootScope.messages.push(message);
return true
} // end of on_messsage
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment