Skip to content

Commit

Permalink
Use the debug library for Advertiser logging (#909)
Browse files Browse the repository at this point in the history
  • Loading branch information
Supereg committed Nov 5, 2021
1 parent 6bd6ad9 commit 2d00c07
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/lib/Advertiser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ import { InterfaceName, IPAddress } from "@homebridge/ciao/lib/NetworkManager";
import assert from "assert";
import bonjour, { BonjourHAP, BonjourHAPService, MulticastOptions } from "bonjour-hap";
import crypto from 'crypto';
import createDebug from "debug";
import { EventEmitter } from "events";
import { AccessoryInfo } from './model/AccessoryInfo';

const debug = createDebug('HAP-NodeJS:Advertiser');

/**
* This enum lists all bitmasks for all known status flags.
* When the bit for the given bitmask is set, it represents the state described by the name.
Expand Down Expand Up @@ -115,15 +118,15 @@ export class CiaoAdvertiser extends EventEmitter implements Advertiser {
});
this.advertisedService.on(ServiceEvent.NAME_CHANGED, this.emit.bind(this, AdvertiserEvent.UPDATED_NAME));

console.log(`Preparing Advertiser for '${this.accessoryInfo.displayName}' using ciao backend!`);
debug(`Preparing Advertiser for '${this.accessoryInfo.displayName}' using ciao backend!`);
}

public initPort(port: number): void {
this.advertisedService.updatePort(port);
}

public startAdvertising(): Promise<void> {
console.log(`Starting to advertise '${this.accessoryInfo.displayName}' using ciao backend!`);
debug(`Starting to advertise '${this.accessoryInfo.displayName}' using ciao backend!`);
return this.advertisedService!.advertise();
}

Expand Down Expand Up @@ -199,7 +202,7 @@ export class BonjourHAPAdvertiser extends EventEmitter implements Advertiser {
this.serviceOptions = serviceOptions;

this.bonjour = bonjour(responderOptions);
console.log(`Preparing Advertiser for '${this.accessoryInfo.displayName}' using bonjour-hap backend!`);
debug(`Preparing Advertiser for '${this.accessoryInfo.displayName}' using bonjour-hap backend!`);
}

public initPort(port: number): void {
Expand All @@ -212,7 +215,7 @@ export class BonjourHAPAdvertiser extends EventEmitter implements Advertiser {
throw new Error("Tried starting bonjour-hap advertisement without initializing port!");
}

console.log(`Starting to advertise '${this.accessoryInfo.displayName}' using bonjour-hap backend!`);
debug(`Starting to advertise '${this.accessoryInfo.displayName}' using bonjour-hap backend!`);

if (this.advertisement) {
this.destroy();
Expand Down

0 comments on commit 2d00c07

Please sign in to comment.