Skip to content

Commit f367ae2

Browse files
committed
Fix multiple network interfaces not updated on Windows
There was only one interval timer shared by all browser instances, so only the last added browser was being updated.
1 parent c86bd68 commit f367ae2

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
99
### Fixed
1010
- Stop button does not kill all child processes
1111
- Activate extension on command palette command
12+
- Fix multiple network interfaces not updated on Windows when scanning for devices
1213
### Added
1314
- ev3dev remote debugger is now a default debugger for Python files
1415

src/dnssd/bonjour.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ class BonjourBrowser extends events.EventEmitter implements dnssd.Browser {
133133
private readonly browsers = new Array<{
134134
bClient: bonjour.Bonjour,
135135
browser: bonjour.Browser,
136-
services: BonjourService[]
136+
services: BonjourService[],
137+
updateInterval: NodeJS.Timer,
137138
}>();
138-
private updateInterval: NodeJS.Timer | undefined;
139139

140140
constructor(private readonly client: BonjourClient, private readonly opts: dnssd.BrowseOptions) {
141141
super();
@@ -176,21 +176,19 @@ class BonjourBrowser extends events.EventEmitter implements dnssd.Browser {
176176
const [service] = services.splice(index, 1);
177177
this.emit('removed', service, false);
178178
});
179-
this.browsers.push({ bClient: bClient, browser: browser, services: services });
179+
this.browsers.push({
180+
bClient: bClient, browser: browser, services: services, updateInterval: setInterval(() => {
181+
// poll again every 1 second
182+
browser.update();
183+
}, 1000)
184+
});
180185
browser.start();
181-
this.updateInterval = setInterval(() => {
182-
// poll again every 1 second
183-
browser.update();
184-
}, 1000);
185186
}
186187

187188
private removeBrowser(bClient: bonjour.Bonjour): void {
188-
if (this.updateInterval) {
189-
clearInterval(this.updateInterval);
190-
this.updateInterval = undefined;
191-
}
192189
const i = this.browsers.findIndex(v => v.bClient === bClient);
193190
const [removed] = this.browsers.splice(i, 1);
191+
clearInterval(removed.updateInterval);
194192
removed.browser.stop();
195193
for (const s of removed.services) {
196194
this.emit('removed', s);

0 commit comments

Comments
 (0)