{"name":"@achingbrain/ssdp","description":"Yet another SSDP implementation for node.js","keywords":["ssdp","multicast","media","device","upnp"],"license":"ISC","version":"1.0.1","author":{"name":"Alex Potsides"},"repository":{"type":"git","url":"git+ssh://git@github.com/achingbrain/ssdp.git"},"bugs":{"url":"https://github.com/achingbrain/ssdp/issues"},"scripts":{"lint":"standard","test":"mocha --recursive --reporter=nyan","test:coverage":"istanbul --include-all-sources cover _mocha --recursive","test:coverage:check":"istanbul --include-all-sources cover _mocha --recursive && istanbul check-coverage --statement 100 --branch 100 --function 100","coveralls":"npm run test:coverage && cat ./coverage/lcov.info | coveralls"},"devDependencies":{"chai":"^3.0.0","coveralls":"^2.11.2","istanbul":"^0.4.1","mocha":"^2.2.5","pre-commit":"^1.0.10","proxyquire":"^1.6.0","sinon":"^1.15.4","standard":"^6.0.7"},"pre-commit":["lint","test:coverage:check"],"dependencies":{"async":"^1.3.0","freeport":"^1.0.5","lodash":"^4.5.1","uuid":"^2.0.1","wildemitter":"^1.1.0","wreck":"^7.0.0","xml2js":"^0.4.9"},"gitHead":"1ed3f259c86d8a03d7eca78a3b4fc49a0f995a5c","homepage":"https://github.com/achingbrain/ssdp#readme","_id":"@achingbrain/ssdp@1.0.1","_shasum":"bb5fc20eb29943a6814bad41105c3c112aa415db","_from":".","_npmVersion":"3.3.12","_nodeVersion":"5.5.0","_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"maintainers":[{"name":"achingbrain","email":"alex@achingbrain.net"}],"dist":{"shasum":"bb5fc20eb29943a6814bad41105c3c112aa415db","tarball":"http://registry-npm.ywwl.com/@achingbrain/ssdp/download/@achingbrain/ssdp-1.0.1.tgz","integrity":"sha512-BAEhsd5OIGv6NQPXYbsr/E3fV97IlwHmT0aZBlLCJC93SzjSO7Nz4KbfTACKG8p0a5jEGDXq1362ZPvrKAIKPA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC92HF5CxwwDcuaUVHhhmROBhs0q37tJ6XJFCrh6Qgi+wIgXuOVZDP0GpqMpmB6QenRbNvxF0dhTK9TztSi6qLKE+k="}],"size":17945,"noattachment":false,"key":"/@achingbrain/ssdp/-/@achingbrain/ssdp-1.0.1.tgz"},"_npmOperationalInternal":{"host":"packages-9-west.internal.npmjs.com","tmp":"tmp/ssdp-1.0.1.tgz_1456731644555_0.5312632697168738"},"directories":{},"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":1456731647547,"_cnpm_publish_time":1456731647547,"dist-tags":{"latest":"4.2.4"}}