Skip to content

Instantly share code, notes, and snippets.

@robwormald robwormald/ctrl.js Secret
Last active Aug 29, 2015

Embed
What would you like to do?
BonjourService.resolve(someComputer).then(function(resolvedComputer){
//do stuff..
})
(function() {
var app = angular.module('apptui');
app.service('BonjourService', ['$timeout', '$rootScope', function($timeout, $rootScope) {
var service = {
computers: [],
browse: function() {
$timeout(function() {
Bonjour.browse(
'_apptui-http._tcp',
'local',
foundNewComputer,
lostComputer
);
}, 1000);
},
resolve: function(computer) {
var deferredResolution = $q.defer();
Bonjour.resolve(computer.serviceName, computer.regType, computer.domain, function(resolvedComputer) {
deferredResolution.resolve(resolvedComputer);
});
return deferredResolution.promise;
})
}
};
var foundNewComputer = function(newComputer) {
service.computers.push(newComputer);
console.log(this.computers);
};
var lostComputer = function(computer) {
console.log(computer);
};
return service;
}]);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.