{"name":"@achingbrain/ssdp","version":"4.1.3","keywords":["device","media","multicast","ssdp","upnp"],"author":{"name":"Alex Potsides"},"license":"Apache-2.0 OR MIT","_id":"@achingbrain/ssdp@4.1.3","maintainers":[{"name":"achingbrain","email":"alex@achingbrain.net"}],"homepage":"https://github.com/achingbrain/ssdp#readme","bugs":{"url":"https://github.com/achingbrain/ssdp/issues"},"dist":{"shasum":"09cd4d75f1ce48621a3d2b7124e0253fac8511b8","tarball":"http://registry-npm.ywwl.com/@achingbrain/ssdp/download/@achingbrain/ssdp-4.1.3.tgz","fileCount":114,"integrity":"sha512-ddCCCnsWuZwZsPQ/VKcdAgh7TfjLNZxsm/22mF1+YGcHdNUYIEvV195W36+dqUNjk9j3+Gsj6Vol1uTx1e+sOA==","signatures":[{"sig":"MEUCIQDeMDxvhdr7cR+eiTNGfdxpCi0ziZfrXDQkz17/2zYxzgIgB5lrZXArVaQSHujZyxAybBBuYWcrossEwYUFZG4eqYM=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@achingbrain%2fssdp@4.1.3","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":146783,"size":35778,"noattachment":false,"key":"/@achingbrain/ssdp/-/@achingbrain/ssdp-4.1.3.tgz"},"type":"module","types":"./dist/src/index.d.ts","exports":{".":{"types":"./dist/src/index.d.ts","import":"./dist/src/index.js"}},"gitHead":"ec3e815776e364d0b3b9b67f0584645929627737","release":{"plugins":[["@semantic-release/commit-analyzer",{"preset":"conventionalcommits","releaseRules":[{"release":"major","breaking":true},{"revert":true,"release":"patch"},{"type":"feat","release":"minor"},{"type":"fix","release":"patch"},{"type":"docs","release":"patch"},{"type":"test","release":"patch"},{"type":"deps","release":"patch"},{"scope":"no-release","release":false}]}],["@semantic-release/release-notes-generator",{"preset":"conventionalcommits","presetConfig":{"types":[{"type":"feat","section":"Features"},{"type":"fix","section":"Bug Fixes"},{"type":"chore","section":"Trivial Changes"},{"type":"docs","section":"Documentation"},{"type":"deps","section":"Dependencies"},{"type":"test","section":"Tests"}]}}],"@semantic-release/changelog","@semantic-release/npm","@semantic-release/github","@semantic-release/git"],"branches":["main"]},"scripts":{"docs":"aegir docs","lint":"aegir lint","test":"aegir test -t node -t electron-main","build":"aegir build --no-bundle","clean":"aegir clean","release":"aegir release","dep-check":"aegir dep-check","test:node":"aegir test -t node --cov","test:electron-main":"aegir test -t electron-main"},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"repository":{"url":"git+https://github.com/achingbrain/ssdp.git","type":"git"},"_npmVersion":"10.9.1","description":"Yet another SSDP implementation for node.js","directories":{},"_nodeVersion":"22.11.0","dependencies":{"xml2js":"^0.6.2","abort-error":"^1.0.0","merge-options":"^3.0.4","freeport-promise":"^2.0.0"},"eslintConfig":{"extends":"ipfs","parserOptions":{"project":true,"sourceType":"module"}},"publishConfig":{"access":"public","provenance":true},"_hasShrinkwrap":false,"devDependencies":{"aegir":"^45.0.1","sinon":"^19.0.2","p-defer":"^4.0.0","it-first":"^3.0.1","sinon-ts":"^2.0.0","@types/sinon":"^17.0.3","@types/xml2js":"^0.4.11"},"_npmOperationalInternal":{"tmp":"tmp/ssdp_4.1.3_1732714400953_0.8112945922821526","host":"s3://npm-registry-packages"},"readme":"# @achingbrain/ssdp\n\n[![codecov](https://img.shields.io/codecov/c/github/achingbrain/ssdp.svg?style=flat-square)](https://codecov.io/gh/achingbrain/ssdp)\n[![CI](https://img.shields.io/github/actions/workflow/status/achingbrain/ssdp/js-test-and-release.yml?branch=main\\&style=flat-square)](https://github.com/achingbrain/ssdp/actions/workflows/js-test-and-release.yml?query=branch%3Amain)\n\n> Yet another SSDP implementation for node.js\n\n# About\n\n<!--\n\n!IMPORTANT!\n\nEverything in this README between \"# About\" and \"# Install\" is automatically\ngenerated and will be overwritten the next time the doc generator is run.\n\nTo make changes to this section, please update the @packageDocumentation section\nof src/index.js or src/index.ts\n\nTo experiment with formatting, please run \"npm run docs\" from the root of this\nrepo and examine the changes made.\n\n-->\n\nFirst, import the module, call the function and set up an error handler:\n\n```javascript\nimport ssdp from '@achingbrain/ssdp'\n\nconst bus = await ssdp()\n\n// print error messages to the console\nbus.on('error', console.error)\n```\n\n## Example - Find a service\n\nPass a `serviceType` to the `discover` method - when services are found events will be emitted:\n\n```javascript\n// this is the unique service name we are interested in:\nconst serviceType = 'urn:schemas-upnp-org:service:ContentDirectory:1'\n\nfor await (const service of bus.discover({ serviceType })) {\n  // search for instances of a specific service\n}\n\nbus.on('service:discover', service => {\n  // receive a notification about discovery of a service\n})\n\nbus.on('service:update', service => {\n  // receive a notification when that service is updated - nb. this will only happen\n  // after the service max-age is reached and if the service's device description\n  // document has changed\n})\n```\n\n## Example - Find all services\n\nDon't pass any options to the `discover` method (n.b. you will also receive protocol related events):\n\n```javascript\nfor await (const service of bus.discover()) {\n  // receive a notification about all service types\n}\n```\n\n## Example - Advertise a service\n\n```javascript\n// advertise a service\n\nconst advert = await bus.advertise({\n  usn: 'urn:schemas-upnp-org:service:ContentDirectory:1',\n  details: {\n    URLBase: 'https://192.168.0.1:8001'\n  }\n})\n\n// stop advertising a service\nawait advert.stop()\n```\n\nFor full options, see [lib/advertise/parse-options.js](lib/advertise/parse-options.js)\n\n## Integrate with existing HTTP servers\n\nBy default when you create an advertisement an HTTP server is created to serve the `details.xml` document that describes your service.  To use an existing server instead, do something like:\n\n## Example - Hapi\n\n```javascript\nconst advert = await bus.advertise({\n  usn: 'urn:schemas-upnp-org:service:ContentDirectory:1',\n  location: {\n    udp4: 'http://192.168.0.1:8000/ssdp/details.xml'\n  },\n  details: {\n    URLBase: 'https://192.168.0.1:8001'\n  }\n})\n\nserver.route({\n  method: 'GET',\n  path: '/ssdp/details.xml',\n  handler: (request, reply) => {\n    reply(advert.service.details())\n      .type('text/xml')\n  }\n})\n```\n\n## Example - Express\n\n```javascript\nconst advert = await bus.advertise({\n  usn: 'urn:schemas-upnp-org:service:ContentDirectory:1',\n  location: {\n    udp4: 'http://192.168.0.1:8000/ssdp/details.xml'\n  },\n  details: {\n    URLBase: 'https://192.168.0.1:8001'\n  }\n})\n\napp.get('/ssdp/details.xml', async (request, response) => {\n  response.set('Content-Type', 'text/xml')\n\n  try {\n    const details = await advert.service.details()\n    response.send(details)\n  } catch (err) {\n    response.set('Content-Type', 'text/xml')\n    response.send(err)\n  }\n})\n```\n\n## Example - Shutting down gracefully\n\n`ssdp` opens several ports to communicate with other devices on your network, to shut them down, do something like:\n\n```javascript\nprocess.on('SIGINT',() => {\n  // stop the server(s) from running - this will also send ssdp:byebye messages for all\n  // advertised services however they'll only have been sent once the callback is\n  // invoked so it won't work with process.on('exit') as you can only perform synchronous\n  // operations there\n  bus.stop(error => {\n    process.exit(error ? 1 : 0)\n  })\n})\n```\n\n## Full API and options\n\n```javascript\nimport ssdp from '@achingbrain/ssdp'\n\n// all arguments are optional\nvar bus = ssdp({\n  udn: 'unique-identifier', // defaults to a random UUID\n  // a string to identify the server by\n  signature: 'node.js/0.12.6 UPnP/1.1 @achingbrain/ssdp/1.0.0',\n  retry {\n    times: 5, // how many times to attempt joining the UDP multicast group\n    interval: 5000 // how long to wait between attempts\n  },\n  // specify one or more sockets to listen on\n  sockets: [{\n    type: 'udp4', // or 'udp6'\n    broadcast: {\n      address: '239.255.255.250', // or 'FF02::C'\n      port: 1900 // SSDP broadcast port\n    },\n    bind: {\n      address: '0.0.0.0', // or '0:0:0:0:0:0:0:0'\n      port: 1900\n    },\n    maxHops: 4 // how many network segments packets are allow to travel through (UDP TTL)\n  }]\n})\nbus.on('error', console.error)\n\n// this is the type of service we are interested in\nvar serviceType = 'urn:schemas-upnp-org:service:ContentDirectory:1'\n\n// search for one type of service\nfor await (const service of bus.discover({ serviceType })) {\n\n}\n\nbus.on('service:discover', service => {\n  // receive a notification when a service of the passed type is discovered\n})\n\nbus.on('service:update', service => {\n  // receive a notification when that service is updated\n})\n\n// search for all types of service\nfor await (const service of bus.discover()) {\n\n}\n\n// advertise a service\nconst advert = await bus.advertise({\n  usn: 'a-usn', // unique service name\n  interval: 10000, // how often to broadcast service adverts in ms\n  ttl: 1800000, // how long the advert is valid for in ms\n  ipv4: true, // whether or not to broadcast the advert over IPv4\n  ipv6: true, // whether or not to broadcast the advert over IPv6\n  location: { // where the description document(s) are available - omit to have an http server automatically created\n    udp4: 'http://192.168.0.1/details.xml', // where the description document is available over ipv4\n    udp6: 'http://FE80::0202:B3FF:FE1E:8329/details.xml' // where the description document is available over ipv6\n  },\n  details: { // the contents of the description document\n    specVersion: {\n      major: 1,\n      minor: 1\n    },\n    URLBase: 'http://example.com',\n    device: {\n      deviceType: 'a-usn',\n      friendlyName: 'A friendly device name',\n      manufacturer: 'Manufactuer name',\n      manufacturerURL: 'http://example.com',\n      modelDescription: 'A description of the device',\n      modelName: 'A model name',\n      modelNumber: 'A vendor specific model number',\n      modelURL: 'http://example.com',\n      serialNumber: 'A device specific serial number',\n      UDN: 'unique-identifier' // should be the same as the bus USN\n      presentationURL: 'index.html'\n    }\n  }\n})\n\n// stop advertising a service\nadvert.stop()\n```\n\n## Device description document\n\nDuring UPnP device discovery, clients can request a [description of the various capabilities your service offers](http://jan.newmarch.name/internetdevices/upnp/upnp-devices.html).\nTo do this you can either store an xml document and set the `location` field of your advert to point at that document\nor have it automatically generated.\n\nE.g., create a document, `description.xml` and put it on a server at `http://server.com/path/to/description.xml`:\n\n```xml\n<root xmlns=\"urn:schemas-upnp-org:device-1-0\">\n  <specVersion>\n    <major>1</major>\n    <minor>0</minor>\n  </specVersion>\n  <URLBase>http://192.168.1.41:80</URLBase>\n  <device>\n    <deviceType>urn:schemas-upnp-org:device:Basic:1</deviceType>\n    <friendlyName>I am a light controller</friendlyName>\n    <manufacturer>Royal Philips Electronics</manufacturer>\n    <manufacturerURL>http://www.philips.com</manufacturerURL>\n    <modelDescription>Philips hue Personal Wireless Lighting</modelDescription>\n    <modelName>Philips hue bridge 2012</modelName>\n    <modelNumber>23409823049823</modelNumber>\n    <modelURL>http://www.meethue.com</modelURL>\n    <serialNumber>asd09f8s90832</serialNumber>\n    <UDN>uuid:2f402f80-da50-12321-9b23-2131298129</UDN>\n    <presentationURL>index.html</presentationURL>\n  </device>\n</root>\n```\n\nThen create your advert:\n\n```javascript\nbus.advertise({\n  usn: 'urn:schemas-upnp-org:device:Basic:1',\n  location: {\n    udp4: 'http://192.168.1.40/path/to/description.xml'\n  }\n})\n```\n\nAlternatively provide an descriptor object and let this module do the heavy lifting (n.b.\nyour object will be run through the [xml2js Builder](https://libraries.io/npm/xml2js#user-content-xml-builder-usage)):\n\n```javascript\nbus.advertise({\n  usn: 'urn:schemas-upnp-org:device:Basic:1',\n  details: {\n   '$': {\n      'xmlns': 'urn:schemas-upnp-org:device-1-0'\n    },\n    'specVersion': {\n      'major': '1',\n      'minor': '0'\n    },\n    'URLBase': 'http://192.168.1.41:80',\n    'device': {\n      'deviceType': 'urn:schemas-upnp-org:device:Basic:1',\n      'friendlyName': 'I am a light controller',\n      'manufacturer': 'Royal Philips Electronics',\n      'manufacturerURL': 'http://www.philips.com',\n      'modelDescription': 'Philips hue Personal Wireless Lighting',\n      'modelName': 'Philips hue bridge 2012',\n      'modelNumber': '23409823049823',\n      'modelURL': 'http://www.meethue.com',\n      'serialNumber': 'asd09f8s90832',\n      'UDN': 'uuid:2f402f80-da50-12321-9b23-2131298129',\n      'presentationURL': 'index.html'\n    }\n  }\n})\n```\n\nA random high port will be chosen, a http server will listen on that port and serve the descriptor and the `LOCATION`\nheader will be set appropriately in all `ssdp` messages.\n\nThe server will be shut down when you call `advert.stop`.\n\n## I want to see all protocol messages\n\nNo problem, try this:\n\n```javascript\nbus.on('transport:outgoing-message', (socket, message, remote) => {\n  console.info('-> Outgoing to %s:%s via %s', remote.address, remote.port, socket.type)\n  console.info(message.toString('utf8'))\n})\nbus.on('transport:incoming-message', (message, remote) => {\n  console.info('<- Incoming from %s:%s', remote.address, remote.port)\n  console.info(message.toString('utf8'))\n})\n```\n\nAlternatively see [test/fixtures/all.js](test/fixtures/all.js)\n\n## References\n\n- [LG SSDP discovery documentation](http://developer.lgappstv.com/TV_HELP/topic/lge.tvsdk.references.book/html/UDAP/UDAP/Discovery.htm)\n- [UPnP overview](http://jan.newmarch.name/internetdevices/upnp/upnp.html)\n- [UPnP device description](http://jan.newmarch.name/internetdevices/upnp/upnp-devices.html)\n- [UPnP Device Architecture v1.1](http://upnp.org/specs/arch/UPnP-arch-DeviceArchitecture-v1.1.pdf)\n- [diversario/node-ssdp](https://github.com/diversario/node-ssdp)\n- [Xedecimal/node-ssdp](https://www.npmjs.com/package/ssdp) (no longer maintained)\n\n# Install\n\n```console\n$ npm i @achingbrain/ssdp\n```\n\n# API Docs\n\n- <https://achingbrain.github.io/ssdp>\n\n# License\n\nLicensed under either of\n\n- Apache 2.0, ([LICENSE-APACHE](https://github.com/achingbrain/ssdp/LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)\n- MIT ([LICENSE-MIT](https://github.com/achingbrain/ssdp/LICENSE-MIT) / <http://opensource.org/licenses/MIT>)\n\n# Contribution\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.\n","publish_time":1732714401123,"_cnpm_publish_time":1732714401123,"dist-tags":{"latest":"4.2.4"}}