const back = require('androidjs').back;
const bonjour = require('bonjour')();

const services = {}

// Zeroconf/Bonjour service
function discoverServices() {
    bonjour.find({type: 'platypush-http'}, (service) => {
        services[service.fqdn] = service;
        back.send('services', service);
    });
}

back.on('get-services', () => {
    for (const service of Object.values(services)) {
        back.send('services', service);
    }
})

discoverServices()

