Last active
August 29, 2015 14:05
-
-
Save mikekoro/4cf6a29e58e37ce4d322 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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