Skip to content

Commit

Permalink
Properly serialize TXT records
Browse files Browse the repository at this point in the history
dbus-native doesn't support JavaScript objects, so we have to to
destructure them into key-value pairs.
  • Loading branch information
elyscape committed Aug 31, 2022
1 parent 8ff163f commit 09601ab
Showing 1 changed file with 5 additions and 11 deletions.
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

0 comments on commit 09601ab

Please sign in to comment.