Comparing version 0.2.3 to 0.2.4
@@ -9,3 +9,2 @@ var mdns = require('../'); | ||
//var browser = mdns.createBrowser(mdns.tcp("workstation")); | ||
//var browser = mdns.createBrowser(mdns.tcp('http')); | ||
@@ -12,0 +11,0 @@ browser.on('ready', function onReady() { |
@@ -15,4 +15,5 @@ | ||
internal.sendDNSPacket = function (packet, cb) { | ||
debug('sending %d question, %d answer', packet.question.length, packet.answer.length); | ||
//debug('packet', packet); | ||
debug('sending %d question, %d answer', | ||
packet.question.length, packet.answer.length); | ||
debug('packet', packet); | ||
var buf = DNSPacket.toBuffer(packet); | ||
@@ -96,3 +97,3 @@ | ||
sock.on('message', function (message, remote) { | ||
//debug('got packet from remote', remote); | ||
debug('got packet from remote', remote); | ||
var packet; | ||
@@ -99,0 +100,0 @@ try { |
@@ -21,6 +21,7 @@ var debug = require('debug')('mdns:lib:ServiceType'); | ||
if (args.length === 1) { | ||
if (typeof args[0] === 'string') { | ||
this.fromString(args[0]); | ||
} else if (Array.isArray(args[0])) { | ||
this.fromArray(args[0]); | ||
// } else if (Array.isArray(args[0])) { | ||
// this.fromArray(args[0]); | ||
} else if (typeof args[0] === 'object') { | ||
@@ -70,2 +71,9 @@ this.fromJSON(args[0]); | ||
var subtypes = text.split(','); | ||
debug('subtypes', subtypes); | ||
if (subtypes.length === 1) { | ||
subtypes = text.split('._sub').reverse(); | ||
debug('new subtypes', subtypes); | ||
} | ||
var primaryString = subtypes.shift(); | ||
@@ -76,3 +84,4 @@ var serviceTokens = primaryString.split('.'); | ||
debug('primary: %s, servicetype: %s, serviceTokens: %s, subtypes: %s', | ||
debug('primary: %s, servicetype: %s, serviceTokens: %s, subtypes: %j', | ||
primaryString, serviceType, serviceTokens.join('.'), subtypes.join(',')); | ||
@@ -79,0 +88,0 @@ |
{ | ||
"name": "mdns-js", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"repository": { | ||
@@ -5,0 +5,0 @@ "type": "git", |
@@ -16,2 +16,3 @@ mDNS-js | ||
[![Build Status](https://travis-ci.org/kmpm/node-mdns-js.svg?branch=master)](https://travis-ci.org/kmpm/node-mdns-js) | ||
@@ -18,0 +19,0 @@ Future |
@@ -73,7 +73,44 @@ var Lab = require('lab'); | ||
it('should take object with subtypes as argument', function (done) { | ||
var type = new ServiceType({ | ||
protocol: 'tcp', | ||
name: 'http', | ||
subtypes:['printer'] | ||
}); | ||
expect(type).to.include({protocol: 'tcp', name: 'http'}); | ||
expect(type.subtypes).to.deep.equal(['printer']); | ||
done(); | ||
}); | ||
it('should subtype using _printer._sub', function (done) { | ||
var st = new ServiceType('_printer._sub._http._tcp.local'); | ||
expect(JSON.stringify(st)).to.equal('{"name":"http","protocol":"tcp",' + | ||
'"subtypes":["printer"]}'); | ||
expect(st.toString()).to.equal('_http._tcp,_printer'); | ||
done(); | ||
}); | ||
it('should subtype using ,_printer', function (done) { | ||
var st = new ServiceType('_http._tcp,_printer'); | ||
expect(JSON.stringify(st)).to.equal('{"name":"http","protocol":"tcp",' + | ||
'"subtypes":["printer"]}'); | ||
expect(st.toString()).to.equal('_http._tcp,_printer'); | ||
done(); | ||
}); | ||
it('should default to _tcp', function (done) { | ||
var type = new ServiceType(['_http']); | ||
expect(type).to.include({protocol: 'tcp', name: 'http'}); | ||
expect(type.subtypes).to.be.empty(); | ||
done(); | ||
}); | ||
it('should throw on bad protocol', function (done) { | ||
var throws = function () { | ||
function fn() { | ||
new ServiceType('service._http._qwe.local'); | ||
}; | ||
expect(throws).to.throw(Error, | ||
} | ||
expect(fn).to.throw(Error, | ||
'protocol must be either "_tcp" or "_udp" but is "_qwe"'); | ||
@@ -91,2 +128,28 @@ done(); | ||
}); | ||
it('should throw on missing object name', function (done) { | ||
function fn() { | ||
new ServiceType({protocol:'tcp'}); | ||
} | ||
expect(fn).to.throw(Error, | ||
'required property name is missing'); | ||
done(); | ||
}); | ||
it('should throw on missing object protocol', function (done) { | ||
function fn() { | ||
new ServiceType({name: 'http'}); | ||
} | ||
expect(fn).to.throw(Error, | ||
'required property protocol is missing'); | ||
done(); | ||
}); | ||
it('should throw on number as input', function (done) { | ||
expect(fn).to.throw(Error, 'argument must be a string, array or object'); | ||
done(); | ||
function fn () { | ||
new ServiceType(1234); | ||
} | ||
}); | ||
}); |
77498
1734
111
61