npm install node-ssdp
There is another package called ssdp
which is the original unmaintained version. Make sure to install node-ssdp
instead.
var Client = require('node-ssdp').Client
, client = new Client();
client.on('response', function (headers, statusCode, rinfo) {
console.log('Got a response to an m-search.');
});
// search for a service type
client.search('urn:schemas-upnp-org:service:ContentDirectory:1');
// Or get a list of all services on the network
client.search('ssdp:all');
var Server = require('node-ssdp').Server
, server = new Server()
;
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 (headers) {
// Expire old devices from your cache.
// Register advertising device somewhere (as designated in http headers heads)
});
server.on('advertise-bye', function (headers) {
// Remove specified device from cache.
});
// start the server
server.start();
process.on('exit', function(){
server.stop() // advertise shutting down and stop listening
})
Take a look at example
directory as well to see examples or client and server.
new SSDP([options, [socket]])
SSDP constructor accepts an optional configuration object and an optional initialized socket. At the moment, the following is supported:
logLevel
String Specifies log level to print. Possible values:TRACE
,DEBUG
,INFO
,WARN
,ERROR
,FATAL
. If not explicitly set in options logging is disabled completely.logJSON
Boolean Log JSON strings (using bunyan). Default:true
.ssdpSig
String SSDP signature. Default:node.js/NODE_VERSION UPnP/1.1 node-ssdp/PACKAGE_VERSION
ssdpIp
String SSDP multicast group. Default:239.255.255.250
.ssdpPort
Number SSDP port. Default:1900
ssdpTtl
Number Multicast TTL. Default:1
adInterval
Numberadvertise
event frequency (ms). Default: 10 sec.unicastHost
String IP address or hostname of server where SSDP service is running. This is used inHOST
header. Default:0.0.0.0
.location
String URL pointing to description of your service, or a function which returns that URLudn
String Unique Device Name. Default:uuid:f40c2981-7329-40b7-8b04-27f187aecfb5
.description
String Path to description file. Default:upnp/desc.php
.ttl
Number Packet TTL. Default:1800
.allowWildcards
Boolean Accept wildcards (*
) inserviceTypes
ofM-SEARCH
packets, e.g.usn:Belkin:device:**
. Default:false
Aside from logLevel
configuration option you can set the level via an environment variable LOG_LEVEL
, which overrides configuration.
At log levels DEBUG
and TRACE
module will print call source location.
Use bunyan
CLI tool to pretty-print JSON logs; running the module with pretty-print enabled is not recommended.
(The MIT License)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.