{"name":"@achingbrain/ssdp","version":"4.0.1","description":"Yet another SSDP implementation for node.js","author":{"name":"Alex Potsides"},"license":"Apache-2.0 OR MIT","homepage":"https://github.com/achingbrain/ssdp#readme","repository":{"type":"git","url":"git+https://github.com/achingbrain/ssdp.git"},"bugs":{"url":"https://github.com/achingbrain/ssdp/issues"},"keywords":["device","media","multicast","ssdp","upnp"],"engines":{"node":">=16.0.0","npm":">=7.0.0"},"type":"module","types":"./dist/src/index.d.ts","exports":{".":{"import":"./dist/src/index.js"}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"release":{"branches":["master"],"plugins":[["@semantic-release/commit-analyzer",{"preset":"conventionalcommits","releaseRules":[{"breaking":true,"release":"major"},{"revert":true,"release":"patch"},{"type":"feat","release":"minor"},{"type":"fix","release":"patch"},{"type":"chore","release":"patch"},{"type":"docs","release":"patch"},{"type":"test","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":"Trivial Changes"},{"type":"test","section":"Tests"}]}}],"@semantic-release/changelog","@semantic-release/npm","@semantic-release/github","@semantic-release/git"]},"scripts":{"clean":"aegir clean","lint":"aegir lint","dep-check":"aegir dep-check","build":"aegir build --no-bundle","test":"aegir test -t node -t electron-main","test:node":"aegir test -t node --cov","test:electron-main":"aegir test -t electron-main","release":"aegir release"},"dependencies":{"event-iterator":"^2.0.0","freeport-promise":"^2.0.0","merge-options":"^3.0.4","uuid":"^8.3.2","xml2js":"^0.4.23"},"devDependencies":{"@types/uuid":"^8.3.4","@types/xml2js":"^0.4.9","aegir":"^37.0.15","it-first":"^1.0.7","p-defer":"^4.0.0","sinon":"^14.0.0"},"gitHead":"2b6edde232751910401b34fb6de989310bc63e50","_id":"@achingbrain/ssdp@4.0.1","_nodeVersion":"16.15.0","_npmVersion":"8.11.0","dist":{"integrity":"sha512-z/CkfFI0Ksrpo8E+lu2rKahlE1KJHUn8X8ihQj2Jg6CEL+oHYGCNfttOES0+VnV7htuog70c8bYNHYhlmmqxBQ==","shasum":"47ccaaa8256cf73b7b2ab86a0ad14128cfaf77b7","tarball":"http://registry-npm.ywwl.com/@achingbrain/ssdp/download/@achingbrain/ssdp-4.0.1.tgz","fileCount":108,"unpackedSize":105379,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHshIdEBBmND4RG0nLXwzDvjSO9l781xggwhph3DqTu4AiBypJduB+IIa64RfwYsnePQVH/hcWYuvv2zcghtVCNeTw=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJij7uoACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpNrBAAhERsnsrce7GUtw3eNipVWb3+DfQLpbPQeW0cc6L0LLtBxT5A\r\nlbebEtiVLnQEg5R0+/kmnISfXTUhQqg3QqGPQmlyEsRO6BKM4ucT7wqIUg++\r\nrqV1y+Pxb8Z7EbW2pAhlpl7e2g/jZJ+oeACzHELm6cxm3SxtPlDW0mtWUBPm\r\n0J7+/+b49Rupv4MTlb7BMOUeiaUb10aUcM0q+vKAelekyst8dKvx1YgZooya\r\njJ+Tv0KNYC0kdIX5c/dbG5kqptMTiXHlhegbxcB4reD4EzzmhGX/akVkVQ23\r\nblZUee28B6oTB/rkeomWDlTy5QuOcj5kXsb0f+4MO0+hvxtna1RrtDtQrfyb\r\np7yYKjZwXTpq/q86gNhYi0IyoDppaw5a6rRfFeJuPo7+Fy9apMGgBuxUiTSA\r\nXWVZRIXJvCT4l/sl/nQVD3iReyhh8gq8NuSWniYA3N4X54TWl/H5KrZLbLl/\r\n+pFCjRc8XNBQYvvTtlF32yuMF/mmCzFhox9Ig4GVzpGGH4elPF6f9pnXqFge\r\nrCyXiC5WXZQ9t2qo1L3Rh/eDQ6iyEi5lLT+6R0/OpS0i/QR6wjf/+7hhORhM\r\nUANixSl5WiUtaSYtoaWN7twQfsxLEJqtTDQOprLOV5+sX1BSUn2tgf5qfeEe\r\nSVpnpPRSADD3I5GrjhjsYYwz444sEl7Tdds=\r\n=7Ubv\r\n-----END PGP SIGNATURE-----\r\n","size":27730,"noattachment":false,"key":"/@achingbrain/ssdp/-/@achingbrain/ssdp-4.0.1.tgz"},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"achingbrain","email":"alex@achingbrain.net"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ssdp_4.0.1_1653586856769_0.7090801043688757"},"_hasShrinkwrap":false,"readme":"# @achingbrain/ssdp <!-- omit in toc -->\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=master\\&style=flat-square)](https://github.com/achingbrain/ssdp/actions/workflows/js-test-and-release.yml?query=branch%3Amaster)\n\n> Yet another SSDP implementation for node.js\n\n## Table of contents <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n  - [Find a service](#find-a-service)\n  - [Find all services](#find-all-services)\n  - [Advertise a service](#advertise-a-service)\n  - [Integrate with existing HTTP servers](#integrate-with-existing-http-servers)\n    - [Hapi](#hapi)\n    - [Express](#express)\n  - [Shutting down gracefully](#shutting-down-gracefully)\n  - [Full API and options](#full-api-and-options)\n  - [Device description document](#device-description-document)\n  - [I want to see all protocol messages](#i-want-to-see-all-protocol-messages)\n- [References](#references)\n- [License](#license)\n- [Contribution](#contribution)\n\n## Install\n\n```console\n$ npm i @achingbrain/ssdp\n```\n\nYet another SSDP implementation for node.js\n\nSSDP is a service discovery protocol that uses messages composed from HTTP-style headers sent over UDP.  It fulfills a similar role to mDNS but needs no extra libraries and is implemented completely in JavaScript.\n\nWith SSDP a service will broadcast it's availability and respond to search messages over UDP and also present a description document that contains details of the capabilities it offers.  A client can then search for available services and use them as required.\n\n## Usage\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### Find a service\n\nPass a `usn` 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 usn = 'urn:schemas-upnp-org:service:ContentDirectory:1'\n\nfor await (const service of bus.discover(usn)) {\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### 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### 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 advertisment 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#### 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#### 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### 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 usn = 'urn:schemas-upnp-org:service:ContentDirectory:1'\n\n// search for one type of service\nfor await (const service of bus.discover(usn)) {\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## License\n\nLicensed under either of\n\n- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)\n- MIT ([LICENSE-MIT](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":1653586856901,"_cnpm_publish_time":1653586856901,"dist-tags":{"latest":"4.2.4"}}