@edenware/ssdp
v4.0.5
Published
A node.js SSDP client and server library (fork).
Maintainers
Readme
@edenware/ssdp
A fork of node-ssdp with stability improvements. A node.js SSDP client and server library.
Installation
npm install @edenware/ssdpThis is a maintained fork of the original node-ssdp package. Make sure to install @edenware/ssdp for the latest stable version with bug fixes.
Usage - Client
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');Usage - Server
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.
Configuration
Client
const Client = require('node-ssdp').Client
const client = new Client({...})interfacesString[] List of interfaces to explicitly bind. By default, bind to all available interfaces.explicitSocketBindBoolean Bind sockets to each discovered interface explicitly instead of relying on the system. Might help with issues with multiple NICs.customLoggerFunction A logger function to use instead of the default. The first argument to the function can contain a format string.reuseAddrBoolean When truesocket.bind()will reuse the address, even if another process has already bound a socket on it. Default:true
Server
const Server = require('node-ssdp').Server
const server = new Server({...})locationString URL pointing to description of your service, or a function which returns that URLudnString Unique Device Name. Default:uuid:f40c2981-7329-40b7-8b04-27f187aecfb5.allowWildcardsBoolean Accept wildcards (*) inserviceTypesofM-SEARCHpackets, e.g.usn:Belkin:device:**. Default:falseinterfacesString[] List of interfaces to explicitly bind. By default, bind to all available interfaces.explicitSocketBindBoolean Bind sockets to each discovered interface explicitly instead of relying on the system. Might help with issues with multiple NICs.customLoggerFunction A logger function to use instead of the default. The first argument to the function can contain a format string.suppressRootDeviceAdvertisementsBoolean When true the SSDP server will not advertise the root device (i.e. the bare UDN). In some scenarios this advertisement is not needed. Default:falsereuseAddrBoolean When truesocket.bind()will reuse the address, even if another process has already bound a socket on it. Default:trueadIntervalNumberadvertiseevent frequency (ms). Default: 10 sec.ttlNumber Packet TTL. Default:1800.
SSDP configuration:
ssdpSigString SSDP signature. Default:node.js/NODE_VERSION UPnP/1.1 @edenware/ssdp/PACKAGE_VERSIONssdpIpString SSDP multicast group. Default:239.255.255.250.ssdpPortNumber SSDP port. Default:1900ssdpTtlNumber Multicast TTL. Default:4
Logging
You can enable logging via an environment variable DEBUG. Set DEBUG=node-ssdp:* to enable all logs. To enable only client or server logs, use
DEBUG=node-ssdp:client or DEBUG=node-ssdp:server respectively.
Alternatively, you can provide your own customLogger function, in which case the DEBUG environment variable will be ignored.
Fork Improvements
This fork includes critical stability fixes from node-ssdp v4.0.1 applied to the v3.3.0 codebase:
- Socket availability validation: Throws clear error when no network sockets are available
- Promise-based server startup: Proper Promise handling in
server.start() - Enhanced logging: Better interface discovery logging
- Code cleanup: Removed unused coverage-related code
- Dual module compatibility: Support for both CommonJS and ES Modules
Compatibility
This fork maintains 100% API compatibility with the original node-ssdp package. Existing code will work without changes.
Module System Support
This package supports both CommonJS and ES Module (ESM) systems:
CommonJS (require):
const { Client, Server } = require('@edenware/ssdp');ES Modules (import):
import { Client, Server } from '@edenware/ssdp';The package automatically provides the appropriate format based on how it's imported.
License
(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.
