Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Commit

Permalink
fix: move try..catch into mdns update function
Browse files Browse the repository at this point in the history
  • Loading branch information
apexad committed Jan 14, 2021
1 parent 982cd58 commit acee65e
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/platformAccessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,21 @@ 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) {
this.log.debug(`txt record contents: ${data.txt}`)
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) {
Expand Down

0 comments on commit acee65e

Please sign in to comment.