@@ -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