From acee65e19a03661537f90509663c062102dd4cfc Mon Sep 17 00:00:00 2001 From: apexad <1437332+apexad@users.noreply.github.com> Date: Thu, 14 Jan 2021 05:06:05 -0700 Subject: [PATCH] fix: move try..catch into mdns update function --- src/platformAccessory.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/platformAccessory.ts b/src/platformAccessory.ts index f45cbac..b2db99c 100644 --- a/src/platformAccessory.ts +++ b/src/platformAccessory.ts @@ -67,9 +67,9 @@ export default class AirportExpress implements AccessoryPlugin { updateMediaState() { this.log.debug(`Updating Airport Exrpess with serial number ${this.serialNumber}`); const mdnsBrowser = this.mdns.createBrowser(this.mdns.tcp("airplay")); - try { - mdnsBrowser.on('ready', () => mdnsBrowser.discover()); - mdnsBrowser.on('update', (data: mDNSReply) => { + mdnsBrowser.on('ready', () => mdnsBrowser.discover()); + mdnsBrowser.on('update', (data: mDNSReply) => { + try { const foundSerialNumber = data.txt.find((str) => str.indexOf('serialNumber') > -1)?.replace('serialNumber=', ''); if (data.txt.includes('model=AirPort10,115') && foundSerialNumber && this.serialNumber === foundSerialNumber) { @@ -77,11 +77,11 @@ export default class AirportExpress implements AccessoryPlugin { this.setMediaState(this.convertMediaState(data.txt)); mdnsBrowser.stop(); } - }); - } catch(error) { - this.log.error(`Unable to check mDNS for ${this.name}`); - this.log.debug(error); - } + } catch(error) { + this.log.error(`Error in mDNS check, found invalid record`); + this.log.debug(error); + } + }); } setMediaState(state: CharacteristicValue) {