'use strict'; /* App Controllers */ function ConnectCtl($scope, StropheSrv, $log, $rootScope) { function connect_callback(status){ if ( status == Strophe.Status.CONNECTING ) { $log.log('Strophe is connecting.'); } else if ( status == Strophe.Status.CONNFAIL ) { $log.log('Strophe failed to connect.'); } else if ( status == Strophe.Status.DISCONNECTING ) { $log.log('Strophe is disconnecting.'); } else if ( status == Strophe.Status.DISCONNECTED ) { $log.log('Strophe is disconnected.'); } else if ( status == Strophe.Status.CONNECTED ) { $log.log('Strophe is connected.'); $rootScope.$broadcast('connected', true); } }; $scope.login = function () { StropheSrv.login($scope.username, $scope.password, connect_callback); }; } ConnectCtl.$inject = ['$scope', 'StropheSrv', '$log', '$rootScope']; function RosterCtl($scope, StropheSrv, $log) { $scope.contacts = []; function onRoster(iq) { var elems = iq.getElementsByTagName('query'); var query = elems[0]; Strophe.forEachChild(query, 'item', function(item){ var jid = item.getAttribute('jid'); var name = item.getAttribute('name') || jid; $scope.contacts.push(name); }); }; $scope.$on('connected', function() {$scope.getRoster();}); $scope.getRoster = function () { var query = $iq({type : 'get'}).c('query', {xmlns : Strophe.NS.ROSTER}); StropheSrv.sendIQ(query, onRoster); }; } RosterCtl.$inject = ['$scope','StropheSrv','$log'];