Skip to content

Commit

Permalink
Workaround avahi issues on synology platform (#1003)
Browse files Browse the repository at this point in the history
  • Loading branch information
Supereg committed Apr 30, 2023
1 parent f1cb68b commit 6df7ecb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
7 changes: 6 additions & 1 deletion src/lib/Accessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1430,7 +1430,12 @@ export class Accessory extends EventEmitter {

this._advertiser!.startAdvertising()
.then(() => this.emit(AccessoryEventTypes.ADVERTISED))
.catch(reason => console.error("Could not create mDNS advertisement. The HAP-Server won't be discoverable: " + reason));
.catch(reason => {
console.error("Could not create mDNS advertisement. The HAP-Server won't be discoverable: " + reason);
if (reason.stack) {
debug("Detailed error: " + reason.stack);
}
});

this.emit(AccessoryEventTypes.LISTENING, port, hostname);
}
Expand Down
19 changes: 14 additions & 5 deletions src/lib/Advertiser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,11 +412,6 @@ export class AvahiAdvertiser extends EventEmitter implements Advertiser {

debug(`Starting to advertise '${this.accessoryInfo.displayName}' using Avahi backend!`);

if (!this.avahiServerInterface) {
this.avahiServerInterface = await AvahiAdvertiser.avahiInterface(this.bus, "Server");
this.avahiServerInterface.on("StateChanged", this.stateChangeHandler);
}

this.path = await AvahiAdvertiser.avahiInvoke(this.bus, "/", "Server", "EntryGroupNew") as string;
await AvahiAdvertiser.avahiInvoke(this.bus, this.path, "EntryGroup", "AddService", {
body: [
Expand All @@ -433,6 +428,20 @@ export class AvahiAdvertiser extends EventEmitter implements Advertiser {
signature: "iiussssqaay",
});
await AvahiAdvertiser.avahiInvoke(this.bus, this.path, "EntryGroup", "Commit");

try {
if (!this.avahiServerInterface) {
this.avahiServerInterface = await AvahiAdvertiser.avahiInterface(this.bus, "Server");
this.avahiServerInterface.on("StateChanged", this.stateChangeHandler);
}
} catch (error) {
// We have some problem on Synology https://github.com/homebridge/HAP-NodeJS/issues/993
console.warn("Failed to create listener for avahi-daemon server state. The system will not be notified about restarts of avahi-daemon " +
"and will therefore stay undiscoverable in those instances. Error message: " + error);
if (error.stack) {
debug("Detailed error: " + error.stack);
}
}
}

/**
Expand Down

0 comments on commit 6df7ecb

Please sign in to comment.