1
0
Fork 0
mirror of https://gitlab.com/futo-org/fcast.git synced 2025-06-24 21:25:23 +00:00
fcast/receivers/common/web/DiscoveryService.ts

48 lines
1.6 KiB
TypeScript
Raw Normal View History

import mdns from 'modules/@futo/mdns-js';
2025-05-01 10:37:21 -05:00
import { Logger, LoggerType } from 'common/Logger';
import { getAppName, getAppVersion, getComputerName } from 'src/Main';
import { PROTOCOL_VERSION } from 'common/Packets';
2025-05-01 10:37:21 -05:00
const logger = new Logger('DiscoveryService', LoggerType.BACKEND);
2024-12-09 00:56:55 -06:00
export class DiscoveryService {
private serviceTcp: any;
private serviceWs: any;
start() {
if (this.serviceTcp || this.serviceWs) {
return;
}
const name = getComputerName();
2025-05-01 10:37:21 -05:00
logger.info(`Discovery service started: ${name}`);
2024-12-09 00:56:55 -06:00
// Note that txt field must be populated, otherwise certain mdns stacks have undefined behavior/issues
// when connecting to the receiver. Also mdns-js internally gets a lot of parsing errors when txt records
// are not defined.
this.serviceTcp = mdns.createAdvertisement(mdns.tcp('_fcast'), 46899, { name: name, txt: {
version: PROTOCOL_VERSION,
appName: getAppName(),
appVersion: getAppVersion(),
} });
2024-12-09 00:56:55 -06:00
this.serviceTcp.start();
this.serviceWs = mdns.createAdvertisement(mdns.tcp('_fcast-ws'), 46898, { name: name, txt: {
version: PROTOCOL_VERSION,
appName: getAppName(),
appVersion: getAppVersion(),
} });
2024-12-09 00:56:55 -06:00
this.serviceWs.start();
}
stop() {
if (this.serviceTcp) {
this.serviceTcp.stop();
this.serviceTcp = null;
}
if (this.serviceWs) {
this.serviceWs.stop();
this.serviceWs = null;
}
}
}