From c3c611ef1bcc89ce1d602a3bae7b360f877eda9b Mon Sep 17 00:00:00 2001 From: apexad <1437332+apexad@users.noreply.github.com> Date: Thu, 8 Apr 2021 07:20:43 -0700 Subject: [PATCH] fix: stop mdns browser as soon as possible, timeout is last resort --- src/platformAccessory.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/platformAccessory.ts b/src/platformAccessory.ts index 54504cf..25f7a5e 100644 --- a/src/platformAccessory.ts +++ b/src/platformAccessory.ts @@ -57,13 +57,22 @@ export default class ExamplePlatformAccessory { if (data.txt.includes('model=AirPort10,115') && foundSerialNumber && this.serialNumber === foundSerialNumber) { this.platform.log.debug(`txt record contents: ${data.txt}`) this.setMediaState(this.convertMediaState(data.txt)); + mdnsBrowser.stop(); } } } catch(error) { this.platform.log.error(`Error in mDNS check, found invalid record`); this.platform.log.debug(error); + mdnsBrowser.stop(); } - setTimeout(() => mdnsBrowser.stop(), 5000); + setTimeout(() => { + try { + // make sure mdnsBrowser was stopped if it was not stopped above + mdnsBrowser.stop(); + } catch(err) { + this.platform.log.debug(`mdns browser for stop via timeout error: ${err}`); + } + }, 5000); }); }