multicast-dns
Advanced tools
Comparing version 2.2.0 to 3.0.0
42
index.js
@@ -20,3 +20,3 @@ var packets = require('./packets') | ||
var bind = thunky(function (cb) { | ||
var createSocket = function () { | ||
var socket = dgram.createSocket({ | ||
@@ -30,3 +30,6 @@ type: type, | ||
socket.on('error', cb) | ||
socket.on('error', function (err) { | ||
that.emit('warning', err) | ||
}) | ||
socket.on('message', function (message, rinfo) { | ||
@@ -46,3 +49,3 @@ try { | ||
socket.bind(port, function () { | ||
socket.on('listening', function () { | ||
if (opts.multicast !== false) { | ||
@@ -53,21 +56,28 @@ socket.addMembership(ip, opts.interface) | ||
} | ||
}) | ||
socket.removeListener('error', cb) | ||
socket.on('error', function (err) { | ||
that.emit('warning', err) | ||
}) | ||
return socket | ||
} | ||
that.emit('ready') | ||
var receiveSocket = createSocket() | ||
var sendSocket = createSocket() | ||
cb(null, socket) | ||
var sendBind = thunky(function (cb) { | ||
sendSocket.on('error', cb) | ||
sendSocket.bind(0, function () { | ||
sendSocket.removeListener('error', cb) | ||
cb(null, sendSocket) | ||
}) | ||
}) | ||
bind() | ||
receiveSocket.bind(port, function () { | ||
that.emit('ready') | ||
}) | ||
that.send = function (packet, cb) { | ||
bind(function (err, socket) { | ||
if (!cb) cb = noop | ||
sendBind(function (err, socket) { | ||
if (err) return cb(err) | ||
var message = packets.encode(packet) | ||
socket.send(message, 0, message.length, port, ip, cb) | ||
sendSocket.send(message, 0, message.length, port, ip, cb) | ||
}) | ||
@@ -98,7 +108,7 @@ } | ||
if (!cb) cb = noop | ||
bind(function (err, socket) { | ||
if (err) return cb() | ||
socket.once('close', cb) | ||
socket.close() | ||
sendSocket.once('close', function () { | ||
receiveSocket.once('close', cb) | ||
receiveSocket.close() | ||
}) | ||
sendSocket.close() | ||
} | ||
@@ -105,0 +115,0 @@ |
{ | ||
"name": "multicast-dns", | ||
"version": "2.2.0", | ||
"version": "3.0.0", | ||
"description": "Low level multicast-dns implementation in pure javascript", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26863
671