Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
[![Coverage Status](https://img.shields.io/coveralls/diversario/node-ssdp.svg)](https://coveralls.io/r/diversario/node-ssdp?branch=master)
[![Dependency Status](https://gemnasium.com/diversario/node-ssdp.png)](https://gemnasium.com/diversario/node-ssdp)
[![NPM version](https://badge.fury.io/js/node-ssdp.svg)](http://badge.fury.io/js/node-ssdp)
[![js-semistandard-style](https://img.shields.io/badge/code%20style-semistandard-brightgreen.svg)](https://github.com/standard/semistandard)

## Installation

Expand Down
10 changes: 5 additions & 5 deletions example/client.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
var ssdp = require('../index').Client
, client = new ssdp({})
const ssdp = require('../index').Client
const client = new ssdp({})

client.on('notify', function () {
//console.log('Got a notification.')
// console.log('Got a notification.')
})

client.on('response', function inResponse(headers, code, rinfo) {
client.on('response', function inResponse (headers, code, rinfo) {
console.log('Got a response to an m-search:\n%d\n%s\n%s', code, JSON.stringify(headers, null, ' '), JSON.stringify(rinfo, null, ' '))
})

client.search('urn:schemas-upnp-org:service:ContentDirectory:1')

// Or maybe if you want to scour for everything after 5 seconds
setInterval(function() {
setInterval(function () {
client.search('ssdp:all')
}, 5000)

Expand Down
18 changes: 9 additions & 9 deletions example/server.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
var SSDP = require('../index').Server
, server = new SSDP({
location: {
port: 8080,
path: '/ssdp/device-desc.xml'
}
})
const SSDP = require('../index').Server
const server = new SSDP({
location: {
port: 8080,
path: '/ssdp/device-desc.xml'
}
})

server.addUSN('upnp:rootdevice')
server.addUSN('urn:schemas-upnp-org:device:MediaServer:1')
server.addUSN('urn:schemas-upnp-org:service:ContentDirectory:1')
server.addUSN('urn:schemas-upnp-org:service:ConnectionManager:1')

server.on('advertise-alive', function (heads) {
//console.log('advertise-alive', heads)
// console.log('advertise-alive', heads)
// Expire old devices from your cache.
// Register advertising device somewhere (as designated in http headers heads)
})

server.on('advertise-bye', function (heads) {
//console.log('advertise-bye', heads)
// console.log('advertise-bye', heads)
// Remove specified device from cache.
})

Expand Down
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ SOFTWARE.
*/

module.exports = {
Server: require("./lib/server"),
Client: require("./lib/client"),
Base: require("./lib/index")
Server: require('./lib/server'),
Client: require('./lib/client'),
Base: require('./lib/index')
}
41 changes: 17 additions & 24 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,32 @@
SOFTWARE.
*/

var SSDP = require('./')
, util = require('util')
, c = require('./const')
, Promise = require('bluebird')
, SsdpHeader = require('./ssdpHeader')
const SSDP = require('./')
const util = require('util')
const c = require('./const')
const Promise = require('bluebird')
const SsdpHeader = require('./ssdpHeader')

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



util.inherits(SsdpClient, SSDP)


/**
* Start the listener for multicast notifications from SSDP devices
* @param [cb]
*/
SsdpClient.prototype.start = function (cb) {
var self = this;
return new Promise(function(success, failure) {
function onBind(err) {
const self = this
return new Promise(function (success, failure) {
function onBind (err) {
if (cb) cb.apply(self, arguments)
if (err) return failure(err)
success()
Expand All @@ -61,34 +58,32 @@ SsdpClient.prototype.start = function (cb) {
})
}


/**
*Close UDP socket.
*/
SsdpClient.prototype.stop = function () {
this._stop()
}


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

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

var header = new SsdpHeader(c.M_SEARCH, {
'HOST': self._ssdpServerHost,
'ST': serviceType,
'MAN': '"ssdp:discover"',
'MX': 3
const header = new SsdpHeader(c.M_SEARCH, {
HOST: self._ssdpServerHost,
ST: serviceType,
MAN: '"ssdp:discover"',
MX: 3
})

self._logger('Attempting to send an M-SEARCH request')
Expand All @@ -97,11 +92,9 @@ SsdpClient.prototype.search = function search(serviceType) {
if (err) {
self._logger('Error: unable to send M-SEARCH request ID %s: %o', header.id(), err)
} else {
self._logger('Sent M-SEARCH request: %o', {'message': header.toString(), id: header.id()})
self._logger('Sent M-SEARCH request: %o', { message: header.toString(), id: header.id() })
}
})
}



module.exports = SsdpClient
2 changes: 1 addition & 1 deletion lib/const.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ module.exports = {
M_SEARCH: 'm-search',
SSDP_DEFAULT_IP: '239.255.255.250',
SSDP_DEFAULT_PORT: 1900
}
}
Loading