### Node.js SSDP Server Usage Example Source: https://github.com/diversario/node-ssdp/blob/master/README.md Illustrates how to set up an SSDP server, add Unique Service Names (USNs), handle 'advertise-alive' and 'advertise-bye' events, start the server, and ensure proper shutdown on process exit. ```javascript 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 }) ``` -------------------------------- ### Install node-ssdp via npm Source: https://github.com/diversario/node-ssdp/blob/master/README.md Instructions to install the 'node-ssdp' library using npm, emphasizing the correct package name to avoid older, unmaintained versions. ```sh npm install node-ssdp ``` -------------------------------- ### Node.js SSDP Client Usage Example Source: https://github.com/diversario/node-ssdp/blob/master/README.md Demonstrates how to initialize an SSDP client, register a 'response' event listener, and perform searches for specific service types or all services on the network. ```javascript 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'); ``` -------------------------------- ### Node.js SSDP Server Configuration Options Source: https://github.com/diversario/node-ssdp/blob/master/README.md Details the available configuration options that can be passed to the `node-ssdp` Server constructor, covering service location, Unique Device Name (UDN), wildcard handling, network binding, logging, advertisement behavior, and TTL settings. ```APIDOC Server Constructor Options: Server(options: object) options: Configuration object for the SSDP server. - location: String | Object Description: URL pointing to the service description, or a function returning it. If an object, host is set to the responding interface's IP. Object properties: - protocol: String Description: Location protocol. Default: "http://". - port: Number Description: Location port. - path: String Description: Location path. - udn: String Description: Unique Device Name. Default: "uuid:f40c2981-7329-40b7-8b04-27f187aecfb5". - allowWildcards: Boolean Description: If true, accepts wildcards (`*`) in `serviceTypes` of `M-SEARCH` packets. Default: false. - interfaces: String[] Description: List of network interfaces to explicitly bind. Default: All available interfaces. - explicitSocketBind: Boolean Description: If true, binds sockets to each discovered interface explicitly. Useful for multiple NICs. Default: false (implied). - customLogger: Function Description: A custom logger function to use. The first argument can be a format string. - suppressRootDeviceAdvertisements: Boolean Description: If true, the SSDP server will not advertise the root device (bare UDN). Default: false. - reuseAddr: Boolean Description: If true, `socket.bind()` will reuse the address. Default: true. - adInterval: Number Description: Frequency of `advertise` events in milliseconds. Default: 10000 (10 seconds). - ttl: Number Description: Packet Time-To-Live. Default: 1800. ``` -------------------------------- ### Node.js SSDP Client Configuration Options Source: https://github.com/diversario/node-ssdp/blob/master/README.md Details the available configuration options that can be passed to the `node-ssdp` Client constructor, including network binding, custom logging, and address reuse settings. ```APIDOC Client Constructor Options: Client(options: object) options: Configuration object for the SSDP client. - interfaces: String[] Description: List of network interfaces to explicitly bind. Default: All available interfaces. - explicitSocketBind: Boolean Description: If true, binds sockets to each discovered interface explicitly instead of relying on the system. Useful for multiple NICs. Default: false (implied). - customLogger: Function Description: A custom logger function to use. The first argument can be a format string. - reuseAddr: Boolean Description: If true, `socket.bind()` will reuse the address, even if another process has already bound a socket. Default: true. ``` -------------------------------- ### Global SSDP Protocol Configuration Source: https://github.com/diversario/node-ssdp/blob/master/README.md Defines global configuration parameters for the SSDP protocol itself, including the SSDP signature, multicast IP address, port, and multicast Time-To-Live (TTL). ```APIDOC Global SSDP Protocol Configuration: These properties define global parameters for the SSDP protocol. - ssdpSig: String Description: SSDP signature string. Default: "node.js/NODE_VERSION UPnP/1.1 node-ssdp/PACKAGE_VERSION". - ssdpIp: String Description: SSDP multicast group IP address. Default: "239.255.255.250". - ssdpPort: Number Description: SSDP port. Default: 1900. - ssdpTtl: Number Description: Multicast Time-To-Live. Default: 4. ``` -------------------------------- ### Configure node-ssdp Logging via DEBUG Environment Variable Source: https://github.com/diversario/node-ssdp/blob/master/README.md This snippet demonstrates how to control logging verbosity for the node-ssdp library by setting the `DEBUG` environment variable. You can enable all logs, or filter specifically for client or server-side activities. Setting a custom logger will override these environment variables. ```shell DEBUG=node-ssdp:* ``` ```shell DEBUG=node-ssdp:client ``` ```shell DEBUG=node-ssdp:server ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.