|
1 | | -'use strict' |
| 1 | +'use strict'; |
2 | 2 |
|
3 | 3 | /* |
4 | 4 | MIT License |
|
24 | 24 | SOFTWARE. |
25 | 25 | */ |
26 | 26 |
|
27 | | -var SSDP = require('./') |
28 | | - , util = require('util') |
29 | | - , c = require('./const') |
30 | | - , Promise = require('bluebird') |
31 | | - , SsdpHeader = require('./ssdpHeader') |
| 27 | +const SSDP = require('./'); |
| 28 | +const util = require('util'); |
| 29 | +const c = require('./const'); |
| 30 | +const Promise = require('bluebird'); |
| 31 | +const SsdpHeader = require('./ssdpHeader'); |
32 | 32 |
|
33 | 33 | /** |
34 | 34 | * |
35 | 35 | * @param opts |
36 | 36 | * @constructor |
37 | 37 | */ |
38 | | -function SsdpClient(opts) { |
39 | | - this._subclass = 'node-ssdp:client' |
40 | | - SSDP.call(this, opts) |
| 38 | +function SsdpClient (opts) { |
| 39 | + this._subclass = 'node-ssdp:client'; |
| 40 | + SSDP.call(this, opts); |
41 | 41 | } |
42 | 42 |
|
43 | | - |
44 | | - |
45 | | -util.inherits(SsdpClient, SSDP) |
46 | | - |
| 43 | +util.inherits(SsdpClient, SSDP); |
47 | 44 |
|
48 | 45 | /** |
49 | 46 | * Start the listener for multicast notifications from SSDP devices |
50 | 47 | * @param [cb] |
51 | 48 | */ |
52 | 49 | SsdpClient.prototype.start = function (cb) { |
53 | | - var self = this; |
54 | | - return new Promise(function(success, failure) { |
55 | | - function onBind(err) { |
56 | | - if (cb) cb.apply(self, arguments) |
57 | | - if (err) return failure(err) |
58 | | - success() |
| 50 | + const self = this; |
| 51 | + return new Promise(function (success, failure) { |
| 52 | + function onBind (err) { |
| 53 | + if (cb) cb.apply(self, arguments); |
| 54 | + if (err) return failure(err); |
| 55 | + success(); |
59 | 56 | } |
60 | | - self._start(onBind) |
61 | | - }) |
62 | | -} |
63 | | - |
| 57 | + self._start(onBind); |
| 58 | + }); |
| 59 | +}; |
64 | 60 |
|
65 | 61 | /** |
66 | 62 | *Close UDP socket. |
67 | 63 | */ |
68 | 64 | SsdpClient.prototype.stop = function () { |
69 | | - this._stop() |
70 | | -} |
71 | | - |
| 65 | + this._stop(); |
| 66 | +}; |
72 | 67 |
|
73 | 68 | /** |
74 | 69 | * |
75 | 70 | * @param {String} serviceType |
76 | 71 | * @returns {*} |
77 | 72 | */ |
78 | | -SsdpClient.prototype.search = function search(serviceType) { |
79 | | - var self = this |
| 73 | +SsdpClient.prototype.search = function search (serviceType) { |
| 74 | + const self = this; |
80 | 75 |
|
81 | 76 | if (!this._started) { |
82 | 77 | return this.start(function () { |
83 | | - self.search(serviceType) |
84 | | - }) |
| 78 | + self.search(serviceType); |
| 79 | + }); |
85 | 80 | } |
86 | 81 |
|
87 | | - var header = new SsdpHeader(c.M_SEARCH, { |
88 | | - 'HOST': self._ssdpServerHost, |
89 | | - 'ST': serviceType, |
90 | | - 'MAN': '"ssdp:discover"', |
91 | | - 'MX': 3 |
92 | | - }) |
| 82 | + const header = new SsdpHeader(c.M_SEARCH, { |
| 83 | + HOST: self._ssdpServerHost, |
| 84 | + ST: serviceType, |
| 85 | + MAN: '"ssdp:discover"', |
| 86 | + MX: 3 |
| 87 | + }); |
93 | 88 |
|
94 | | - self._logger('Attempting to send an M-SEARCH request') |
| 89 | + self._logger('Attempting to send an M-SEARCH request'); |
95 | 90 |
|
96 | 91 | self._send(header, function (err, bytes) { |
97 | 92 | if (err) { |
98 | | - self._logger('Error: unable to send M-SEARCH request ID %s: %o', header.id(), err) |
| 93 | + self._logger('Error: unable to send M-SEARCH request ID %s: %o', header.id(), err); |
99 | 94 | } else { |
100 | | - self._logger('Sent M-SEARCH request: %o', {'message': header.toString(), id: header.id()}) |
| 95 | + self._logger('Sent M-SEARCH request: %o', { message: header.toString(), id: header.id() }); |
101 | 96 | } |
102 | | - }) |
103 | | -} |
104 | | - |
105 | | - |
| 97 | + }); |
| 98 | +}; |
106 | 99 |
|
107 | | -module.exports = SsdpClient |
| 100 | +module.exports = SsdpClient; |
0 commit comments