Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

Commit

Permalink
fix: ensure event handlers are removed on MulticastDNS.stop (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hubertus Hohl authored Aug 7, 2020
1 parent 9186dbf commit 9fea1f6
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class MulticastDNS extends EventEmitter {
this.peerMultiaddrs = options.libp2p.multiaddrs || []
this._queryInterval = null
this._onPeer = this._onPeer.bind(this)
this._onMdnsQuery = this._onMdnsQuery.bind(this)
this._onMdnsResponse = this._onMdnsResponse.bind(this)

if (options.compat !== false) {
this._goMdns = new GoMulticastDNS({
Expand All @@ -44,8 +46,8 @@ class MulticastDNS extends EventEmitter {
if (this.mdns) return

this.mdns = multicastDNS({ port: this.port })
this.mdns.on('query', (event) => this._onMdnsQuery(event))
this.mdns.on('response', (event) => this._onMdnsResponse(event))
this.mdns.on('query', this._onMdnsQuery)
this.mdns.on('response', this._onMdnsResponse)

this._queryInterval = query.queryLAN(this.mdns, this.serviceTag, this.interval)

Expand Down Expand Up @@ -85,7 +87,7 @@ class MulticastDNS extends EventEmitter {
}

this.mdns.removeListener('query', this._onMdnsQuery)
this.mdns.removeListener('query', this._onMdnsResponse)
this.mdns.removeListener('response', this._onMdnsResponse)
this._goMdns && this._goMdns.removeListener('peer', this._onPeer)

clearInterval(this._queryInterval)
Expand Down

0 comments on commit 9fea1f6

Please sign in to comment.