index.js
function Discovery(options) {
    var self = this;

    if (options && !is.obj(options))
        debug('Dicovery constructor bad options argument: '+inspect(options));

    // Create a dgram socket and bind it
    self.dgramType = (options && options.dgramType) ?
                      options.dgramType.toLowerCase() : DEFAULT_DGRAM_TYPE;
    self.reuseaddr = (options && options.reuseaddr) ? options.reuseaddr : DEFAULT_REUSE_ADDR;
    self.socket = dgram.createSocket({type: self.dgramType, reuseAddr: self.reuseaddr});
    self.port = (options && options.port) ? options.port : DEFAULT_UDP_PORT;
    self.bindAddr = (options && options.bindAddr) ? options.bindAddr :
                     undefined;
    self.socket.bind(self.port, self.bindAddr);

    // create an interval task to check for announcements that have timed out
    self.timeOutInt = (options && options.timeOutInt) ? options.timeOutInt :
                                        DEFAULT_TIMEOUT;
    self.timeOutId = setInterval(function() { self.handleTimeOut(); },
                                                             self.timeOutInt);

    // listen and listen for multicast packets
    self.socket.on('listening', function() {
        self.socket.addMembership(MULTICAST_ADDRESS);
    });

    // handle any announcements, here we just do the formatting
    self.socket.on('message', function(message, rinfo) {
        if (message) {
            var obj = objToJson.jsonParse(message.toString());
            if (!obj) {
                debug('bad announcement: '+message.toString());
                return;
            }

            // the received message was either an event or an announcement
            if (obj.eventName)
                self.emit(GLOBAL_EVENT_NAME, obj.eventName, obj.data);
            else
                self.handleAnnouncement(obj, rinfo);
        }
    });
}
function Discovery(options) {
    var self = this;

    if (options && !is.obj(options))
        debug('Dicovery constructor bad options argument: '+inspect(options));

    // Create a dgram socket and bind it
    self.dgramType = (options && options.dgramType) ?
                      options.dgramType.toLowerCase() : DEFAULT_DGRAM_TYPE;
    self.reuseaddr = (options && options.reuseaddr) ? options.reuseaddr : DEFAULT_REUSE_ADDR;
    self.socket = dgram.createSocket({type: self.dgramType, reuseAddr: self.reuseaddr});
    self.port = (options && options.port) ? options.port : DEFAULT_UDP_PORT;
    self.bindAddr = (options && options.bindAddr) ? options.bindAddr :
                     undefined;
    self.socket.bind(self.port, self.bindAddr);

    // create an interval task to check for announcements that have timed out
    self.timeOutInt = (options && options.timeOutInt) ? options.timeOutInt :
                                        DEFAULT_TIMEOUT;
    self.timeOutId = setInterval(function() { self.handleTimeOut(); },
                                                             self.timeOutInt);

    // listen and listen for multicast packets
    self.socket.on('listening', function() {
        self.socket.addMembership(MULTICAST_ADDRESS);
    });

    // handle any announcements, here we just do the formatting
    self.socket.on('message', function(message, rinfo) {
        if (message) {
            var obj = objToJson.jsonParse(message.toString());
            if (!obj) {
                debug('bad announcement: '+message.toString());
                return;
            }

            // the received message was either an event or an announcement
            if (obj.eventName)
                self.emit(GLOBAL_EVENT_NAME, obj.eventName, obj.data);
            else
                self.handleAnnouncement(obj, rinfo);
        }
    });
}
Creates a Discovery object. The options object is optional. Supported
options are:
- port - Set the port the service listens on for announcements default:
44201
- bindAddr - bind to an address
- dgramType - Either 'udp4' or 'udp6', default: 'udp4'.
- timeOutInt - duration of time between timeout checks in ms. Default 1000.
@param {Object} [options] An optional configuration object.
@constructor