Skip to content

Commit

Permalink
Merge branch 'master' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
donavanbecker authored Oct 28, 2023
2 parents 95c5c12 + 93a9743 commit e72d3b5
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 60 deletions.
132 changes: 89 additions & 43 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hap-nodejs",
"version": "0.11.0",
"version": "0.11.1",
"description": "HAP-NodeJS is a Node.js implementation of HomeKit Accessory Server.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -53,7 +53,7 @@
],
"dependencies": {
"@homebridge/ciao": "^1.1.5",
"@homebridge/dbus-native": "^0.5.0",
"@homebridge/dbus-native": "^0.5.1",
"bonjour-hap": "~3.6.4",
"debug": "^4.3.4",
"fast-srp-hap": "~2.0.4",
Expand Down
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
24 changes: 17 additions & 7 deletions src/lib/Advertiser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// <reference path="../../@types/bonjour-hap.d.ts" />
import ciao, { CiaoService, MDNSServerOptions, Responder, ServiceEvent, ServiceTxt, ServiceType } from "@homebridge/ciao";
import { InterfaceName, IPAddress } from "@homebridge/ciao/lib/NetworkManager";
import dbus, { DBusInterface, InvokeError, MessageBus } from "@homebridge/dbus-native";
import dbus, { DBusInterface, MessageBus } from "@homebridge/dbus-native";
import assert from "assert";
import bonjour, { BonjourHAP, BonjourHAPService, MulticastOptions } from "bonjour-hap";
import crypto from "crypto";
Expand Down Expand Up @@ -303,7 +303,8 @@ function messageBusConnectionResult(bus: MessageBus): Promise<void> {
export class DBusInvokeError extends Error {
readonly errorName: string;

constructor(errorObject: InvokeError) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
constructor(errorObject: { name: string, message: any }) {
super();

Object.setPrototypeOf(this, DBusInvokeError.prototype);
Expand Down Expand Up @@ -412,11 +413,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 +429,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
8 changes: 1 addition & 7 deletions src/types/dbus-native.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,11 @@ declare module "@homebridge/dbus-native" {

function systemBus(): MessageBus;

export class InvokeError {
name: string;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
message: any;
}

export class MessageBus {
connection: BusConnection;

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types,@typescript-eslint/no-explicit-any
public invoke(message: any, callback: (error: InvokeError | undefined, value: any) => void): void;
public invoke(message: any, callback: (error: { name: string, message: any } | undefined, value: any) => void): void;

public getService(name: string): DBusService;
}
Expand Down

0 comments on commit e72d3b5

Please sign in to comment.