Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bonjour

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bonjour - npm Package Compare versions

Comparing version 3.1.0 to 3.2.0

62

lib/browser.js

@@ -10,2 +10,3 @@ 'use strict'

var TLD = '.local'
var WILDCARD = '_services._dns-sd._udp' + TLD

@@ -22,2 +23,4 @@ module.exports = Browser

*
* If no type is given, a wild card search is performed.
*
* An internal list of online services is kept which starts out empty. When

@@ -30,13 +33,23 @@ * ever a new service is discovered, it's added to the list and an "up" event

function Browser (mdns, opts, onup) {
if (!opts.type) throw new Error('Required type not given')
if (typeof opts === 'function') return new Browser(mdns, null, opts)
EventEmitter.call(this)
if (onup) this.on('up', onup)
this._name = serviceName.stringify(opts.type, opts.protocol || 'tcp') + TLD
this._mdns = mdns
this._onresponse = null
this._serviceMap = {}
if (!opts || !opts.type) {
this._name = WILDCARD
this._wildcard = true
} else {
this._name = serviceName.stringify(opts.type, opts.protocol || 'tcp') + TLD
if (opts.name) this._name = opts.name + '.' + this._name
this._wildcard = false
}
this.services = []
if (onup) this.on('up', onup)
this.start()

@@ -50,11 +63,27 @@ }

// List of names for the browser to listen for. In a normal search this will
// be the primary name stored on the browser. In case of a wildcard search
// the names will be determined at runtime as responses come in.
var nameMap = {}
if (!this._wildcard) nameMap[this._name] = true
this._onresponse = function (packet) {
goodbyes(self._name, packet).forEach(self._removeService.bind(self))
if (self._wildcard) {
packet.answers.forEach(function (answer) {
if (answer.type !== 'PTR' || answer.name !== self._name || answer.name in nameMap) return
nameMap[answer.data] = true
self._mdns.query(answer.data, 'PTR')
})
}
var matches = buildServicesFor(self._name, packet)
if (matches.length === 0) return
Object.keys(nameMap).forEach(function (name) {
goodbyes(name, packet).forEach(self._removeService.bind(self))
matches.forEach(function (service) {
if (self._serviceMap[service.fqdn]) return
self._addService(service)
var matches = buildServicesFor(name, packet)
if (matches.length === 0) return
matches.forEach(function (service) {
if (self._serviceMap[service.fqdn]) return
self._addService(service)
})
})

@@ -98,3 +127,3 @@ }

.filter(function (rr) {
return dnsEqual(rr.name, name) && rr.type === 'PTR' && rr.ttl === 0
return rr.type === 'PTR' && rr.ttl === 0 && dnsEqual(rr.name, name)
})

@@ -113,3 +142,3 @@ .map(function (rr) {

.filter(function (rr) {
return dnsEqual(rr.name, name) && rr.type === 'PTR'
return rr.type === 'PTR' && dnsEqual(rr.name, name)
})

@@ -123,3 +152,3 @@ .map(function (ptr) {

.filter(function (rr) {
return dnsEqual(rr.name, ptr.data) && (rr.type === 'SRV' || rr.type === 'TXT')
return (rr.type === 'SRV' || rr.type === 'TXT') && dnsEqual(rr.name, ptr.data)
})

@@ -144,5 +173,7 @@ .forEach(function (rr) {

if (!service.name) return
records
.filter(function (rr) {
return dnsEqual(rr.name, service.host) && (rr.type === 'A' || rr.type === 'AAAA')
return (rr.type === 'A' || rr.type === 'AAAA') && dnsEqual(rr.name, service.host)
})

@@ -155,2 +186,5 @@ .forEach(function (rr) {

})
.filter(function (rr) {
return !!rr
})
}
{
"name": "bonjour",
"version": "3.1.0",
"version": "3.2.0",
"description": "A Bonjour/Zeroconf implementation in pure JavaScript",

@@ -44,5 +44,5 @@ "main": "index.js",

"coordinates": [
59.992475702944795,
11.08010022705082
55.6667216,
12.5799133
]
}

@@ -76,7 +76,7 @@ # bonjour

Options are:
Options (all optional):
- `type` (string)
- `subtypes` (array of strings, optional)
- `protocol` (string, optional) - defaults to `tcp`
- `subtypes` (array of strings)
- `protocol` (string) - defaults to `tcp`

@@ -83,0 +83,0 @@ #### `var browser = bonjour.findOne(options[, callback])`

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc