{"name":"mqtt-connection","version":"3.2.0","description":"Stream-based Connection object for MQTT, extracted from MQTT.js","main":"connection.js","contributors":[{"name":"Matteo Collina","email":"matteo.collina@gmail.com","url":"https://github.com/mcollina"},{"name":"Adam Rudd","email":"adamvrr@gmail.com"}],"scripts":{"test":"mocha test/ && standard"},"repository":{"type":"git","url":"git+https://github.com/mqttjs/mqtt-connection.git"},"keywords":["mqtt","connection","server"],"license":"MIT","bugs":{"url":"https://github.com/mqttjs/mqtt-connection/issues"},"homepage":"https://github.com/mqttjs/mqtt-connection","dependencies":{"duplexify":"^3.5.1","inherits":"^2.0.3","mqtt-packet":"^5.4.0","safe-buffer":"^5.1.1","through2":"^2.0.1"},"devDependencies":{"mocha":"^4.0.0","should":"^13.0.0","standard":"^10.0.3"},"gitHead":"09bcbed38372c0cc53adca11744885fbafdc890d","_id":"mqtt-connection@3.2.0","_npmVersion":"5.5.1","_nodeVersion":"8.7.0","_npmUser":{"name":"matteo.collina","email":"hello@matteocollina.com"},"dist":{"integrity":"sha512-br1n12OegkGfkseOHYby2LggkQy9qtgVKo8kg64acd89/Pc+vzcEA2PzmLd/kNo5K08YuJTVo2GYmymhY8NDIw==","shasum":"2104d875ea917c46d25e89922c6694072910f408","tarball":"http://registry-npm.ywwl.com/mqtt-connection/download/mqtt-connection-3.2.0.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIC0QXkWteLTTB381biOWBhbZfIVYEWaLGZ3YghMjijwBAiAWr2ht2s3zkKpNx+Fzc1LL8Xgw1oKDfIO01JlumapEVg=="}],"size":10228,"noattachment":false,"key":"/mqtt-connection/-/mqtt-connection-3.2.0.tgz"},"maintainers":[{"name":"matteo.collina","email":"hello@matteocollina.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/mqtt-connection-3.2.0.tgz_1508226887121_0.6235934398137033"},"directories":{},"readme":"mqtt-connection&nbsp;&nbsp;&nbsp;[![Build Status](https://travis-ci.org/mqttjs/mqtt-connection.png)](https://travis-ci.org/mqttjs/mqtt-connection)\n===============\n\nBarebone Connection object for MQTT.\nWorks over any kind of binary Streams, TCP, TLS, WebSocket, ...\n\n[![JavaScript Style Guide](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)\n\nIt uses [mqtt-packet](http://npm.im/mqtt-packet) for generating and\nparsing MQTT packets. See it for the full documentations on the\npacket types.\n\n  * <a href=\"#installation\">Installation</a>\n  * <a href=\"#usage\">Usage</a>\n  * <a href=\"#api\">API</a>\n  * <a href=\"#contributing\">Contributing</a>\n  * <a href=\"#license\">License &amp; copyright</a>\n\nThis library is tested with node v4, v6 and v7. The last version to support\nolder versions of node was mqtt-connection@2.1.1.\n\nInstallation\n-------\n\n```sh\nnpm install mqtt-connection --save\n```\n\nUsage\n-----\n\nAs a client:\n\n```js\nvar net = require('net')\nvar mqttCon = require('mqtt-connection')\nvar stream = net.createConnection(1883, 'localhost')\nvar conn = mqttCon(stream)\n\n// conn is your MQTT connection!\n```\n\nAs a server:\n```js\nvar net = require('net')\nvar mqttCon = require('mqtt-connection')\nvar server = new net.Server()\n\nserver.on('connection', function (stream) {\n  var client = mqttCon(stream)\n\n  // client connected\n  client.on('connect', function (packet) {\n    // acknowledge the connect packet\n    client.connack({ returnCode: 0 });\n  })\n\n  // client published\n  client.on('publish', function (packet) {\n    // send a puback with messageId (for QoS > 0)\n    client.puback({ messageId: packet.messageId })\n  })\n\n  // client pinged\n  client.on('pingreq', function () {\n    // send a pingresp\n    client.pingresp()\n  });\n\n  // client subscribed\n  client.on('subscribe', function (packet) {\n    // send a suback with messageId and granted QoS level\n    client.suback({ granted: [packet.qos], messageId: packet.messageId })\n  })\n\n  // timeout idle streams after 5 minutes\n  stream.setTimeout(1000 * 60 * 5)\n\n  // connection error handling\n  client.on('close', function () { client.destroy() })\n  client.on('error', function () { client.destroy() })\n  client.on('disconnect', function () { client.destroy() })\n\n  // stream timeout\n  stream.on('timeout', function () { client.destroy(); })\n})\n\n// listen on port 1883\nserver.listen(1883)\n```\n\nAs a websocket server:\n\n```js\nvar websocket = require('websocket-stream')\nvar WebSocketServer = require('ws').Server\nvar Connection = require('mqtt-connection')\nvar server = http.createServer()\n\nvar wss = new WebSocketServer({server: server})\n\nif (handler) {\n  server.on('client', handler)\n}\n\nwss.on('connection', function (ws) {\n  var stream = websocket(ws)\n  var connection = new Connection(stream)\n\n  handle(connection)\n})\n\nfunction handle (conn) {\n  // handle the MQTT connection like\n  // the net example\n}\n```\n\nAPI\n---\n\n  * <a href=\"#connection\"><code>mqtt.<b>Connection()</b></code></a>\n  * <a href=\"#parseStream\"><code>mqtt.<b>parseStream()</b></code></a>\n  * <a href=\"#generateStream\"><code>mqtt.<b>generateStream()</b></code></a>\n\n---------------------------------\n\n<a name=\"connection\"></a>\n### new mqtt.Connection([options])\n\nCreates a new MQTT `Connection`.\n\nOptions:\n\n  * `notData`: do not listen to the `'data'` event, so that it can\n    respect backpressure. Pipe the `Connection` to another stream to\n    consume the packets. If this option is passed `true` the object will\n    emit no packet-related events.\n\n#### Connection#connect(options, [callback])\n\nSend a MQTT connect packet.\n\n`options` supports the following properties:\n\n* `protocolId`: Protocol ID, usually `MQIsdp`. `string`\n* `protocolVersion`: Protocol version, usually 3. `number`\n* `keepalive`: keepalive period in seconds. `number`\n* `clientId`: client ID. `string`\n* `will`: the client's will message options.\n`object` that supports the following properties:\n  * `topic`: the will topic. `string`\n  * `payload`: the will payload. `string`\n  * `qos`: will qos level. `number`\n  * `retain`: will retain flag. `boolean`\n  * `properties`: properties of will by MQTT 5.0:\n      * `willDelayInterval`: representing the Will Delay Interval in seconds `number`,\n      * `payloadFormatIndicator`: Will Message is UTF-8 Encoded Character Data or not `boolean`,\n      * `messageExpiryInterval`: value is the lifetime of the Will Message in seconds and is sent as the Publication Expiry Interval when the Server publishes the Will Message `number`,\n      * `contentType`: describing the content of the Will Message `string`,\n      * `responseTopic`: String which is used as the Topic Name for a response message `string`,\n      * `correlationData`: The Correlation Data is used by the sender of the Request Message to identify which request the Response Message is for when it is received `binary`,\n      * `userProperties`: The User Property is allowed to appear multiple times to represent multiple name, value pairs `object`\n* `properties`: properties MQTT 5.0.\n`object` that supports the following properties:\n    * `sessionExpiryInterval`: representing the Session Expiry Interval in seconds `number`,\n    * `receiveMaximum`: representing the Receive Maximum value `number`,\n    * `maximumPacketSize`: representing the Maximum Packet Size the Client is willing to accept `number`,\n    * `topicAliasMaximum`: representing the Topic Alias Maximum value indicates the highest value that the Client will accept as a Topic Alias sent by the Server `number`,\n    * `requestResponseInformation`: The Client uses this value to request the Server to return Response Information in the CONNACK `boolean`,\n    * `requestProblemInformation`: The Client uses this value to indicate whether the Reason String or User Properties are sent in the case of failures `boolean`,\n    * `userProperties`: The User Property is allowed to appear multiple times to represent multiple name, value pairs `object`,\n    * `authenticationMethod`: the name of the authentication method used for extended authentication `string`,\n    * `authenticationData`: Binary Data containing authentication data `binary`\n* `clean`: the 'clean start' flag. `boolean`\n* `username`: username for protocol v3.1. `string`\n* `password`: password for protocol v3.1. `string`\n\n#### Connection#connack(options, [callback])\nSend a MQTT connack packet.\n\n`options` supports the following properties:\n\n* `returnCode`: the return code of the connack, success is for MQTT < 5.0\n* `reasonCode`: suback Reason Code `number` MQTT 5.0\n* `properties`: properties MQTT 5.0.\n`object` that supports the following properties:\n    * `sessionExpiryInterval`: representing the Session Expiry Interval in seconds `number`,\n    * `receiveMaximum`: representing the Receive Maximum value `number`,\n    * `maximumQoS`: maximum qos supported by server `number`,\n    * `retainAvailable`: declares whether the Server supports retained messages `boolean`,\n    * `maximumPacketSize`: Maximum Packet Size the Server is willing to accept `number`,\n    * `assignedClientIdentifier`: Assigned Client Identifier `string`,\n    * `topicAliasMaximum`: representing the Topic Alias Maximum value indicates the highest value that the Client will accept as a Topic Alias sent by the Server `number`,\n    * `reasonString`: representing the reason associated with this response `string`,\n    * `userProperties`: The User Property is allowed to appear multiple times to represent multiple name, value pairs `object`,\n    * `wildcardSubscriptionAvailable`: this byte declares whether the Server supports Wildcard Subscriptions `boolean`\n    * `subscriptionIdentifiersAvailable`: declares whether the Server supports Subscription Identifiers `boolean`,\n    * `sharedSubscriptionAvailable`: declares whether the Server supports Shared Subscriptions `boolean`,\n    * `serverKeepAlive`: Keep Alive time assigned by the Server `number`,\n    * `responseInformation`: String which is used as the basis for creating a Response Topic `string`,\n    * `serverReference`: String which can be used by the Client to identify another Server to use `string`,\n    * `authenticationMethod`: the name of the authentication method used for extended authentication `string`,\n    * `authenticationData`: Binary Data containing authentication data `binary`\n\n#### Connection#publish(options, [callback])\nSend a MQTT publish packet.\n\n`options` supports the following properties:\n\n* `topic`: the topic to publish to. `string`\n* `payload`: the payload to publish, defaults to an empty buffer.\n`string` or `buffer`\n* `qos`: the quality of service level to publish on. `number`\n* `messageId`: the message ID of the packet,\nrequired if qos > 0. `number`\n* `retain`: retain flag. `boolean`\n* `properties`: `object`\n    * `payloadFormatIndicator`: Payload is UTF-8 Encoded Character Data or not `boolean`,\n    * `messageExpiryInterval`: the lifetime of the Application Message in seconds `number`,\n    * `topicAlias`: value that is used to identify the Topic instead of using the Topic Name `number`,\n    * `responseTopic`: String which is used as the Topic Name for a response message `string`,\n    * `correlationData`: used by the sender of the Request Message to identify which request the Response Message is for when it is received `binary`,\n    * `userProperties`: The User Property is allowed to appear multiple times to represent multiple name, value pairs `object`,\n    * `subscriptionIdentifier`: representing the identifier of the subscription `number`,\n    * `contentType`: String describing the content of the Application Message `string`\n\n#### Connection#puback #pubrec #pubcomp #unsuback(options, [callback])\nSend a MQTT `[puback, pubrec, pubcomp, unsuback]` packet.\n\n`options` supports the following properties:\n\n* `messageId`: the ID of the packet\n* `reasonCode`: Reason Code by packet `number`\n* `properties`: `object`\n    * `reasonString`: representing the reason associated with this response `string`,\n    * `userProperties`: The User Property is allowed to appear multiple times to represent multiple name, value pairs `object`\n\n#### Connection#pubrel(options, [callback])\nSend a MQTT pubrel packet.\n\n`options` supports the following properties:\n\n* `dup`: duplicate message flag\n* `reasonCode`: pubrel Reason Code `number`\n* `messageId`: the ID of the packet\n* `properties`: `object`\n    * `reasonString`: representing the reason associated with this response `string`,\n    * `userProperties`: The User Property is allowed to appear multiple times to represent multiple name, value pairs `object`\n\n#### Connection#subscribe(options, [callback])\nSend a MQTT subscribe packet.\n\n`options` supports the following properties:\n\n* `dup`: duplicate message flag\n* `messageId`: the ID of the packet\n* `properties`: `object`\n    * `subscriptionIdentifier`:  representing the identifier of the subscription `number`,\n    * `userProperties`: The User Property is allowed to appear multiple times to represent multiple name, value pairs `object`\n* `subscriptions`: a list of subscriptions of the form\n`[{topic: a, qos: 0}, {topic: b, qos: 1}]`\n`[{topic: a, qos: 0, nl: false, rap: true, rh: 15 }, {topic: b, qos: 1, nl: false, rap: false, rh: 100 }]` MQTT 5.0 Example\n\n#### Connection#suback(options, [callback])\nSend a MQTT suback packet.\n\n`options` supports the following properties:\n\n* `granted`: a vector of granted QoS levels,\nof the form `[0, 1, 2]`\n* `messageId`: the ID of the packet\n* `reasonCode`: suback Reason Code `number`\n* `properties`: `object`\n    * `reasonString`: representing the reason associated with this response `string`,\n    * `userProperties`: The User Property is allowed to appear multiple times to represent multiple name, value pairs `object`\n\n#### Connection#unsubscribe(options, [callback])\nSend a MQTT unsubscribe packet.\n\n`options` supports the following properties:\n\n* `messageId`: the ID of the packet\n* `reasonCode`: unsubscribe Reason Code MQTT 5.0 `number`\n* `dup`: duplicate message flag\n* `properties`: `object`\n    * `userProperties`: The User Property is allowed to appear multiple times to represent multiple name, value pairs `object`\n* `unsubscriptions`: a list of topics to unsubscribe from,\nof the form `[\"topic1\", \"topic2\"]`\n\n#### Connection#pingreq #pingresp #disconnect(options, [callback])\nSend a MQTT `[pingreq, pingresp]` packet.\n\n#### Connection#disconnect(options, [callback])\nSend a MQTT `disconnect` packet.\n\n`options` supports the following properties only MQTT 5.0:\n\n* `reasonCode`: Disconnect Reason Code `number`\n* `properties`: `object`\n    * `sessionExpiryInterval`: representing the Session Expiry Interval in seconds `number`,\n    * `reasonString`: representing the reason for the disconnect `string`,\n    * `userProperties`: The User Property is allowed to appear multiple times to represent multiple name, value pairs `object`,\n    * `serverReference`: String which can be used by the Client to identify another Server to use `string`\n\n#### Connection#auth(options, [callback])\nSend a MQTT `auth` packet. Only MQTT 5.0\n\n`options` supports the following properties only MQTT 5.0:\n\n* `reasonCode`: Auth Reason Code `number`\n* `properties`: `object`\n    * `authenticationMethod`: the name of the authentication method used for extended authentication `string`,\n    * `authenticationData`: Binary Data containing authentication data `binary`,\n    * `reasonString`: representing the reason for the disconnect `string`,\n    * `userProperties`: The User Property is allowed to appear multiple times to represent multiple name, value pairs `object`\n\n#### Event: 'connect'\n`function(packet) {}`\n\nEmitted when a MQTT connect packet is received by the client.\n\n`packet` is an object that may have the following properties:\n\n* `version`: the protocol version string\n* `versionNum`: the protocol version number\n* `keepalive`: the client's keepalive period\n* `clientId`: the client's ID\n* `will`: an object with the following keys:\n  * `topic`: the client's will topic\n  * `payload`: the will message\n  * `retain`: will retain flag\n  * `qos`: will qos level\n  * `properties`: properties of will\n* `properties`: properties of packet\n* `clean`: clean start flag\n* `username`: v3.1 username\n* `password`: v3.1 password\n\n#### Event: 'connack'\n`function(packet) {}`\n\nEmitted when a MQTT connack packet is received by the client.\n\n`packet` is an object that may have the following properties:\n\n* `returnCode`: the return code of the connack packet\n* `properties`: properties of packet\n\n#### Event: 'publish'\n`function(packet) {}`\n\nEmitted when a MQTT publish packet is received by the client.\n\n`packet` is an object that may have the following properties:\n\n* `topic`: the topic the message is published on\n* `payload`: the payload of the message\n* `messageId`: the ID of the packet\n* `properties`: properties of packet\n* `qos`: the QoS level to publish at\n\n#### Events: \\<'puback', 'pubrec', 'pubrel', 'pubcomp', 'unsuback'\\>\n`function(packet) {}`\n\nEmitted when a MQTT `[puback, pubrec, pubrel, pubcomp, unsuback]`\npacket is received by the client.\n\n`packet` is an object that may contain the property:\n\n* `messageId`: the ID of the packet\n* `properties`: properties of packet\n\n#### Event: 'subscribe'\n`function(packet) {}`\n\nEmitted when a MQTT subscribe packet is received.\n\n`packet` is an object that may contain the properties:\n\n* `messageId`: the ID of the packet\n* `properties`: properties of packet\n* `subscriptions`: an array of objects\nrepresenting the subscribed topics, containing the following keys\n  * `topic`: the topic subscribed to\n  * `qos`: the qos level of the subscription\n\n\n#### Event: 'suback'\n`function(packet) {}`\n\nEmitted when a MQTT suback packet is received.\n\n`packet` is an object that may contain the properties:\n\n* `messageId`: the ID of the packet\n* `properties`: properties of packet\n* `granted`: a vector of granted QoS levels\n\n#### Event: 'unsubscribe'\n`function(packet) {}`\n\nEmitted when a MQTT unsubscribe packet is received.\n\n`packet` is an object that may contain the properties:\n\n* `messageId`: the ID of the packet\n* `properties`: properties of packet\n* `unsubscriptions`: a list of topics the client is\nunsubscribing from, of the form `[topic1, topic2, ...]`\n\n#### Events: \\<'pingreq', 'pingresp'\\>\n`function(packet){}`\n\nEmitted when a MQTT `[pingreq, pingresp, disconnect]` packet is received.\n\n`packet` only includes static header information and can be ignored.\n\n#### Event: 'disconnect'\n`function(packet) {}`\n\nEmitted when a MQTT disconnect packet is received.\n\n`packet` only includes static header information and can be ignored for MQTT < 5.0.\n\n`packet` is an object that may contain the properties for MQTT 5.0:\n\n* `reasonCode`: disconnect Reason Code\n* `properties`: properties of packet\n\n#### Event: 'auth'\n`function(packet) {}`\n\nEmitted when a MQTT auth packet is received.\n\n`packet` is an object that may contain the properties:\n\n* `reasonCode`: Auth Reason Code\n* `properties`: properties of packet\n-------------------------------------\n\n<a name=\"generateStream\">\n\n### mqtt.generateStream()\n\nReturns a `Transform` stream that calls [`generate()`](https://github.com/mqttjs/mqtt-packet#generate).\nThe stream is configured into object mode.\n\n<a name=\"parseStream\">\n\n### mqtt.parseStream(opts)\n\nReturns a `Transform` stream that embeds a [`Parser`](https://github.com/mqttjs/mqtt-packet#mqttparser) and calls [`Parser.parse()`](https://github.com/mqttjs/mqtt-packet#parserparsebuffer) for each new `Buffer`. The stream is configured into object mode. It accepts the same options of [`parser(opts)`](#parser).\n\n<a name=\"contributing\"></a>\nContributing\n------------\n\nmqtt-connection is an **OPEN Open Source Project**. This means that:\n\n> Individuals making significant and valuable contributions are given commit-access to the project to contribute as they see fit. This project is more like an open wiki than a standard guarded open source project.\n\nSee the [CONTRIBUTING.md](https://github.com/mqttjs/mqtt-connection/blob/master/CONTRIBUTING.md) file for more details.\n\n### Contributors\n\nmqtt-connection is only possible due to the excellent work of the following contributors:\n\n<table><tbody>\n<tr><th align=\"left\">Matteo Collina</th><td><a href=\"https://github.com/mcollina\">GitHub/mcollina</a></td><td><a href=\"http://twitter.com/matteocollina\">Twitter/@matteocollina</a></td></tr>\n<tr><th align=\"left\">Adam Rudd</th><td><a href=\"https://github.com/adamvr\">GitHub/adamvr</a></td><td><a href=\"http://twitter.com/adam_vr\">Twitter/@adam_vr</a></td></tr>\n<tr><th align=\"left\">Siarhei Buntsevich</th><td><a href=\"https://github.com/scarry1992\">GitHub/scarry1992</a></td></tr>\n</tbody></table>\n\nLicense\n-------\n\nMIT\n","publish_time":1508226888029,"_cnpm_publish_time":1508226888029,"dist-tags":{"latest":"4.1.0"}}