Esempio n. 1
0
  constructor(opts, sock) {
    super()

    if (!(this instanceof SSDP)) return new SSDP(opts)

    this._subclass = this._subclass || 'ssdp-base'

    // we didn't get options, only socket
    if (!sock) {
      if (opts && /^udp\d$/.test(opts.type) && typeof opts.addMembership == 'function') {
        sock = opts
        opts = null
      }
    }

    opts = opts || {}

    if (sock) {
      this.sock = sock
    } else {
      this.sock = dgram.createSocket('udp4')
      this.sock.unref()
    }

    this.sock.on('close', () => {
      this.emit('close', this.sock)
    })

    this._init(opts)
  }
Esempio n. 2
0
 constructor () {
   super()
   this.debug = false;
   this.socket = dgram.createSocket('udp4');
   this.isSocketBound = false;
   this.devices = {};
   this.port = null;
   this.messagesQueue = [];
   this.sendTimer = null;
   this.discoveryTimer = null;
   this.discoveryPacketSequence = 0;
   this.messageHandlers = [{
     type: 'stateService',
     callback: this.processDiscoveryPacket.bind(this)
   }, {
     type: 'stateLabel',
     callback: this.processLabelPacket.bind(this)
   }, {
     type: 'stateLight',
     callback: this.processLabelPacket.bind(this)
   }];
   this.sequenceNumber = 0;
   this.lightOfflineTolerance = 3;
   this.messageHandlerTimeout = 45000; // 45 sec
   this.resendPacketDelay = 150;
   this.resendMaxTimes = 5;
   this.source = utils.getRandomHexString(8);
   this.broadcastAddress = '255.255.255.255';
 }