Skip to content

Commit

Permalink
Merge branch 'kkushimoto-add-binary-txt'
Browse files Browse the repository at this point in the history
  • Loading branch information
watson committed May 6, 2016
2 parents 6f8e6be + 89893f5 commit dc1bd8b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
7 changes: 4 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,6 +35,7 @@ function Browser (mdns, opts, onup) {
this._mdns = mdns
this._onresponse = null
this._serviceMap = {}
this._txt = dnsTxt(opts.txt)

if (!opts || !opts.type) {
this._name = WILDCARD
Expand Down Expand Up @@ -75,7 +76,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 @@ -131,7 +132,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
16 changes: 16 additions & 0 deletions test/bonjour.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,22 @@ test('bonjour.find', function (bonjour, t) {
bonjour.publish({ name: 'Baz', type: 'test', port: 3000, txt: { foo: 'bar' } }).on('up', next())
})

test('bonjour.find - binary txt', function (bonjour, t) {
var next = afterAll(function () {
var browser = bonjour.find({ type: 'test', txt: { binary: true } })

browser.on('up', function (s) {
t.equal(s.name, 'Foo')
t.deepEqual(s.txt, { bar: new Buffer('buz') })
t.deepEqual(s.rawTxt, new Buffer('076261723d62757a', 'hex'))
bonjour.destroy()
t.end()
})
})

bonjour.publish({ name: 'Foo', type: 'test', port: 3000, txt: { bar: new Buffer('buz') } }).on('up', next())
})

test('bonjour.find - down event', function (bonjour, t) {
var service = bonjour.publish({ name: 'Foo Bar', type: 'test', port: 3000 })

Expand Down

0 comments on commit dc1bd8b

Please sign in to comment.