Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add systemd-resolved mDNS advertiser support #965

Merged
merged 9 commits into from
Oct 31, 2022
Prev Previous commit
Next Next commit
Properly serialize TXT records
dbus-native doesn't support JavaScript objects, so we have to to
destructure them into key-value pairs.
  • Loading branch information
elyscape committed Oct 3, 2022
commit cd3cf54c96c02858703ada53aa28e691c9533dac
16 changes: 5 additions & 11 deletions src/lib/Advertiser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,7 @@ export class AvahiAdvertiser extends EventEmitter implements Advertiser {
}
}

type ResolvedServiceTxt = {
[key: string]: Buffer;
}
type ResolvedServiceTxt = Array<Array<string | Buffer>>;

/**
* Advertiser based on the systemd-resolved D-Bus library.
Expand All @@ -451,13 +449,9 @@ export class ResolvedAdvertiser extends EventEmitter implements Advertiser {
}

private createTxt(): ResolvedServiceTxt {
const result: ResolvedServiceTxt = {};

for (const [key, val] of Object.entries(CiaoAdvertiser.createTxt(this.accessoryInfo, this.setupHash))) {
result[key] = Buffer.from(val.toString());
}

return result;
return Object
.entries(CiaoAdvertiser.createTxt(this.accessoryInfo, this.setupHash))
.map((el: Array<string>) => [el[0].toString(), Buffer.from(el[1].toString())]);
}

public initPort(port: number): void {
Expand All @@ -482,7 +476,7 @@ export class ResolvedAdvertiser extends EventEmitter implements Advertiser {
this.port, // service_port
0, // service_priority
0, // service_weight
this.createTxt(), // txt_datas
[this.createTxt()], // txt_datas
],
signature: "sssqqqaa{say}",
});
Expand Down