hadean-old/src/mDNS.ts

43 lines
681 B
TypeScript
Raw Normal View History

2021-06-15 20:05:07 -04:00
import bonjour from 'bonjour';
import log from './log.js';
import os from 'os'
import * as uuid from 'uuid';
const mdns = bonjour();
const ID = uuid.v4();
let devices = [];
2021-06-15 20:19:39 -04:00
class Player {
name: string;
address: string;
port: number;
toString() {
return ` ${this.name}`;
}
2021-06-15 20:05:07 -04:00
}
const network = {
get players() {
return devices;
}
}
export default network;
export function ready() {
mdns.publish({
type: 'dfi',
name: os.hostname() + '-' + ID,
port: 6969
});
}
mdns.find({
type: 'dfi'
}, (service) => {
log.info('found network device', service);
2021-06-15 20:19:39 -04:00
const p = new Player();
p.name = service.fqdn;
devices.push(p);
2021-06-15 20:05:07 -04:00
});