Skip to content

Commit

Permalink
Add binary txt option
Browse files Browse the repository at this point in the history
  • Loading branch information
kkushimoto committed Mar 23, 2016
1 parent f6d23f2 commit 2fdae57
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var util = require('util')
var EventEmitter = require('events').EventEmitter
var serviceName = require('multicast-dns-service-types')
var dnsEqual = require('dns-equal')
var txt = require('dns-txt')()
var dnsTxt = require('dns-txt')

var TLD = '.local'
var WILDCARD = '_services._dns-sd._udp' + TLD
Expand Down Expand Up @@ -35,14 +35,21 @@ function Browser (mdns, opts, onup) {
this._mdns = mdns
this._onresponse = null
this._serviceMap = {}
this._txt = null

if (!opts || !opts.type) {
this._name = WILDCARD
this._wildcard = true
this._txt = dnsTxt()
} else {
this._name = serviceName.stringify(opts.type, opts.protocol || 'tcp') + TLD
if (opts.name) this._name = opts.name + '.' + this._name
this._wildcard = false
if (!opts.txt || !opts.txt.binary) {
this._txt = dnsTxt()
} else {
this._txt = dnsTxt({ binary: true })
}
}

this.services = []
Expand Down Expand Up @@ -75,7 +82,7 @@ Browser.prototype.start = function () {
Object.keys(nameMap).forEach(function (name) {
goodbyes(name, packet).forEach(self._removeService.bind(self))

var matches = buildServicesFor(name, packet)
var matches = buildServicesFor(name, packet, self._txt)
if (matches.length === 0) return

matches.forEach(function (service) {
Expand Down Expand Up @@ -127,7 +134,7 @@ function goodbyes (name, packet) {
})
}

function buildServicesFor (name, packet) {
function buildServicesFor (name, packet, txt) {
var records = packet.answers.concat(packet.additionals).filter(function (rr) {
return rr.ttl > 0 // ignore goodbye messages
})
Expand Down

0 comments on commit 2fdae57

Please sign in to comment.