Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions lib/service_type.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,13 @@ function isProtocol(str) {
function _u(str) { return "_" + str; }
function _uu(str) { return str[0] === '_' ? str.substr(1) : str; }

var charset_regex = /[^-a-zA-Z0-9]/;
var charset_regex = /[^-_a-zA-Z0-9]/;
function checkLengthAndCharset(str) {
if (str.length === 0) {
throw new Error('type ' + str + ' must not be empty');
}
if (str.length > 15) {
throw new Error('type ' + str + ' has more than 15 characters');
if (str.length > 20) { // Note: this is not according to spec (https://github.com/agnat/node_mdns/issues/264)
throw new Error('type ' + str + ' has more than 20 characters');
}
if (str.match(charset_regex)) {
throw new Error('type ' + str + ' may only contain alphanumeric ' +
Expand All @@ -170,8 +170,9 @@ function checkFormat(str) {
if (str.length === 0) {
throw new Error('type string must not be empty');
}
if (str.length > 16) { // 16 is correct because we have a leading underscore
throw new Error('type ' + _uu(str) + ' has more than 15 characters');
// 21 is correct because we have a leading underscore
if (str.length > 21) { // Note: this is not according to spec (https://github.com/agnat/node_mdns/issues/264)
throw new Error('type ' + _uu(str) + ' has more than 20 characters');
}
if ( ! str.match(format_regex)) {
throw new Error('type ' + str + ' must start with an underscore ' +
Expand Down
24 changes: 24 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// import the module
const mdns = require('./');

// advertise a http server on port 4321
// const ad = mdns.createAdvertisement(mdns.tcp('http'), 4321);
// ad.start();

// watch all http servers
const browser = mdns.createBrowser(
new mdns.ServiceType({
name: 'androidtvremote2',
protocol: 'tcp',
}),
);
browser.on('serviceUp', service => {
console.log("service up: ", service);
});
browser.on('serviceDown', service => {
console.log("service down: ", service);
});
browser.start();

// discover all available service types
const all_the_types = mdns.browseThemAll(); // all_the_types is just another browser...