Add ability to specify multicast interface

When you have multiple network adapters/interfaces, the system can choose the wrong one. This allows you to be explicit about which one you broadcast on.
This commit is contained in:
2025-01-04 15:45:22 -06:00
parent 033627d698
commit 9e332038c6
4 changed files with 28 additions and 4 deletions

8
dist/finder.d.ts vendored
View File

@ -20,7 +20,13 @@ export declare class UnitInfo {
* * `"serverFound"` - fired immediately when an IntelliCenter unit has been located; receives a {@linkcode UnitInfo} argument
*/
export declare class FindUnits extends EventEmitter {
constructor();
broadcastInterface?: string | undefined;
/**
* Creates a new finder.
*
* @param broadcastInterface the address of the interface to send the broadcast to. If not specified, will use system selection. Only necessary if you have more than one network adapter/interface and want to search on a specific one.
*/
constructor(broadcastInterface?: string | undefined);
private finder;
private bound;
private message;

12
dist/finder.js vendored
View File

@ -31,8 +31,15 @@ export class UnitInfo {
* * `"serverFound"` - fired immediately when an IntelliCenter unit has been located; receives a {@linkcode UnitInfo} argument
*/
export class FindUnits extends EventEmitter {
constructor() {
broadcastInterface;
/**
* Creates a new finder.
*
* @param broadcastInterface the address of the interface to send the broadcast to. If not specified, will use system selection. Only necessary if you have more than one network adapter/interface and want to search on a specific one.
*/
constructor(broadcastInterface) {
super();
this.broadcastInterface = broadcastInterface;
// construct mDNS packet to ping for intellicenter controllers
this.message = Buffer.alloc(34);
let offset = 0;
@ -54,6 +61,9 @@ export class FindUnits extends EventEmitter {
this.finder = createSocket("udp4");
this.finder
.on("listening", () => {
if (this.broadcastInterface) {
this.finder.setMulticastInterface(this.broadcastInterface);
}
this.finder.setBroadcast(true);
this.finder.setMulticastTTL(128);
if (!this.bound) {

2
dist/finder.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -51,7 +51,12 @@ export class UnitInfo {
* * `"serverFound"` - fired immediately when an IntelliCenter unit has been located; receives a {@linkcode UnitInfo} argument
*/
export class FindUnits extends EventEmitter {
constructor() {
/**
* Creates a new finder.
*
* @param broadcastInterface the address of the interface to send the broadcast to. If not specified, will use system selection. Only necessary if you have more than one network adapter/interface and want to search on a specific one.
*/
constructor(public broadcastInterface?: string) {
super();
// construct mDNS packet to ping for intellicenter controllers
@ -76,6 +81,9 @@ export class FindUnits extends EventEmitter {
this.finder = createSocket("udp4");
this.finder
.on("listening", () => {
if (this.broadcastInterface) {
this.finder.setMulticastInterface(this.broadcastInterface);
}
this.finder.setBroadcast(true);
this.finder.setMulticastTTL(128);