# Code coverage report for node-ssdp/lib/client.js

## Statements: 50% (9 / 18) Branches: 0% (0 / 2) Functions: 40% (2 / 5) Lines: 50% (9 / 18) Ignored: none

All files » node-ssdp/lib/ » client.js

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    661

    1
    1
    1

    1

    1
    1

    1

    1
     var SSDP = require('./')
      , util = require('util')
      , c = require('./const')

    /**
     *
     * @param opts
     * @constructor
     */
    function SsdpClient(opts) {
      this._subclass = 'ssdp-client'
      SSDP.call(this, opts)
    }

    util.inherits(SsdpClient, SSDP)

    /**
     *
     * @param [cb]
     */
    SsdpClient.prototype.start = function (cb) {
      this._start(cb)
    }

    /**
     *
     * @param {String} serviceType
     * @returns {*}
     */
    SsdpClient.prototype.search = function search(serviceType) {
      var self = this

      if (!this._started) {
        return this.start(function () {
          self.search(serviceType)
        })
      }

      var pkt = self._getSSDPHeader(
        c.M_SEARCH,
        {
          'HOST': self._ssdpServerHost,
          'ST': serviceType,
          'MAN': '"ssdp:discover"',
          'MX': 3
        }
      )

      self._logger.trace('Sending an M-SEARCH request')

      var message = new Buffer(pkt)

      self._send(message, function (err, bytes) {
        self._logger.trace({'message': pkt}, 'Sent M-SEARCH request')
      })
    }

    module.exports = SsdpClient