{"name":"watershed","version":"0.4.1","author":{"name":"Joshua M. Clulow","email":"jmc@joyent.com"},"_id":"watershed@0.4.1","maintainers":[{"name":"todd.whiteman","email":"todd.whiteman@joyent.com"},{"name":"kusor","email":"kusorbox@gmail.com"},{"name":"wyatt","email":"wpreul@gmail.com"},{"name":"michael.hicks","email":"michael.hicks@joyent.com"},{"name":"bahamat","email":"bahamat@digitalelf.net"},{"name":"chudley","email":"aguycalledrichard@gmail.com"},{"name":"tchameroy","email":"tyler.chameroy@joyent.com"},{"name":"dbuell","email":"dayne.buell@joyent.com"},{"name":"jclulow","email":"josh@sysmgr.org"},{"name":"shmeeny","email":"richard.kiene@gmail.com"},{"name":"arekinath","email":"alex@cooperi.net"}],"homepage":"https://github.com/joyent/node-watershed#readme","bugs":{"url":"https://github.com/joyent/node-watershed/issues"},"dist":{"shasum":"79aa9cad9f9ac22f9979000bd1dbffb870dcf1bd","tarball":"http://registry-npm.ywwl.com/watershed/download/watershed-0.4.1.tgz","fileCount":6,"integrity":"sha512-hzWQQ3O3R+q+V186tWVJYXfgGfMxv3dd/QhF29hlktn5A+dP4pMtjbtvDuyxFAnmoeweucM0MSgaaS432bthgQ==","signatures":[{"sig":"MEUCIEIdeJlr4ENO9ekTYmJ+jRJD4p3ztK7skfCXm7shpZtyAiEAiw8OUOftkhmrK0aWoOXsTkjwiL1tiZfJrRNwtNTkRBs=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":28689,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh3A3HCRA9TVsSAnZWagAAvHkP/jIAu0NiRp1MKMSskUrD\ncPeQUEcv+e+2C+1vSK1zXyU+v09JQ8jEVa/U1ClBdORHJVMAhwQJorn7Vvfe\nUMvW9NvtbLnoeRh9vaB6tRKKbxtBDccA1oGmJKPGn7GC49C61gMExJGTjDpb\nARQ5ovOMCcufSRKgRMlaGHFNyZIOT3QK1Dpns0sp/7Suj84RD+syPwfTAtjb\nl+rA4B3X28wnbTG88nyZ7EpF9TQ6y0Uc4brqM86uS/vSmYrrsBdxgoqlljhE\nSPoIBFTS4xALxyz3bKrIqCx/j3mFHBVwbDXpOTppBINyuD3iQDbQh9GEu8dI\n214vGTjKFMJlFgm3Qd7FpNe+cdJlXYj+slvvW1gx9WMgfueMc6fap2CX8EuS\nBboMSwFq7oqOxXKpvy1Gg/mC79r3wOCN3El8iRwzm6u2u48IkKMx4Fqit6OY\nNaz8gP8s7ZGlKqIgKWyKW4vcYwpQlDgUknQG5BWciRI6AhW+61vQgu8+cFJt\nr19xDbYraaVNsUKNJc84bqtSrcFI2775JiMpr726SsTi99l3VX+VSRlQdBcu\n6nR47A8YUyqsYqsrb9oExYxa1KJncEdhAsgliFfbJd1u4db+pJ06aOa3CFf+\ne+pHMotvIpe5oSwK+AI0JX3hb0+WPcCN4SWkoCkp/sq4bNxqmJDf0qWnhiU6\nlD69\r\n=ixWo\r\n-----END PGP SIGNATURE-----\r\n","size":9280,"noattachment":false,"key":"/watershed/-/watershed-0.4.1.tgz"},"main":"./lib/watershed.js","engines":["node >=0.8.0"],"gitHead":"88e01e435a6e2ec9b3dc921d7269e507caad11c6","_npmUser":{"name":"bahamat","email":"bahamat@digitalelf.net"},"repository":{"url":"git+https://github.com/joyent/node-watershed.git","type":"git"},"_npmVersion":"6.14.13","description":"simple websockets (RFC6455) client and server","directories":{},"_nodeVersion":"12.22.7","dependencies":{"dtrace-provider":"~0.8","readable-stream":"1.0.2"},"_hasShrinkwrap":false,"devDependencies":{"tape":"^4.2.2","istanbul":"^0.4.0"},"_npmOperationalInternal":{"tmp":"tmp/watershed_0.4.1_1635884817281_0.9069635041104287","host":"s3://npm-registry-packages"},"readme":"# node-watershed\n\nA simple implementation of WebSockets for use with node.js 'http'-style web\nserver or client.  Deals only with [RFC6455][1], ignoring any Browser-specific\npeculiarities, curiosities, and fallback mechanisms.\n\n## API\n\n### Watershed\n\nThe core of this library is a Factory-style class `Watershed`.  It has several\nstatic methods:\n\n#### Watershed.accept(http.ServerRequest, net.Socket, Buffer[, Boolean[, String[] ]])\n\nResponds to a client's request to Upgrade an HTTP connection to a WebSocket and\nreturns a `WatershedConnection`, which is also an `EventEmitter`.\n\nThe arguments to this method should ideally come from the `'upgrade'` event on\na node.js `http.Server`.  For example:\n\n```javascript\nvar shed = new Watershed();\nvar srv = http.createServer();\nsrv.listen(8080);\nsrv.on('upgrade', function(req, socket, head) {\n        var wsc;\n        try {\n                wsc = shed.accept(req, socket, head);\n        } catch (ex) {\n                console.error('error: ' + ex.message);\n                return socket.end();\n        }\n        wsc.on('text', function(text) {\n                console.log('received text: ' + text);\n        });\n        wsc.on('end', function() {\n                console.log('end!');\n        });\n        /* ... etc ... */\n});\n```\n\nThe additional penultimate boolean argument may be used when implementing a\nwebsocket-to-websocket proxy.  If set to `true`, then `accept()` returns the\nraw underlying `Socket` of the connection and does not construct a\n`WatershedConnection` instance.  No event handlers will be placed on the\nsocket, meaning you are free to continue using it directly (e.g. calling\n`pipe()` on it to join it to a backend socket).\n\nThe final list-of-strings argument can be optionally provided to allow for the\nuse of WebSocket subprotocol negotiation.  It is a list of case-sensitive\nstring names of supported subprotocols.  If given, and protocol negotiation\ntakes place, the chosen subprotocol can be found with the `getProtocol()`\nmethod.\n\n#### Watershed.generateKey()\n\nReturns a random, Base64-encoded 16-byte value suitable for use as the\n`Sec-WebSocket-Key` header on an Upgrade request.  See Example usage in\n`connect()`.\n\n#### Watershed.connect(http.ClientResponse, net.Socket, Buffer, String)\n\nAttaches a new client-side `WatershedConnection` to this presently Upgraded\nsocket.\n\nThe arguments to this method should ideally come from the `'upgrade'` event on\na node.js `http.Client`.  For example:\n\n```javascript\nvar shed = new Watershed();\nvar wskey = shed.generateKey();\nvar options = {\n    port: 8082,\n    hostname: '127.0.0.1',\n    headers: {\n        'connection': 'upgrade',\n        'upgrade': 'websocket',\n        'Sec-WebSocket-Key': wskey,\n        'Sec-WebSocket-Version': '13'\n    }\n};\nvar req = http.request(options);\nreq.end();\nreq.on('upgrade', function(res, socket, head) {\n        var wsc = shed.connect(res, socket, head, wskey);\n        wsc.send('Hi there!');\n        wsc.on('end', function() {\n                console.log('end!');\n        });\n        /* ... etc ... */\n});\n```\n\n### WatershedConnection\n\n#### Event: 'error'\n\nEmitted once when an error occurs during processing.  The socket will be closed\nand an `'end'` event will follow.  The only argument will be an instance of\n`Error`.\n\n#### Event: 'connectionReset'\n\nEmitted when the remote peer closes the connection without sending us a CLOSE\nframe.  An `'end'` event will follow.\n\n#### Event: 'end' (code, reason)\n\nEmitted once when the socket is closing.  If we received a graceful CLOSE\nframe from the remote server, we will attempt to process it and pass `code`\nand `reason` -- both of type `String`.\n\n#### Event: 'text'\n\nEmitted for each inbound TEXT frame.  The only argument will be a `String`\ncontaining the UTF-8 string payload.\n\n#### Event: 'binary'\n\nEmitted for each inbound BINARY frame.  The only argument will be a `Buffer`\ncontaining the binary payload.\n\n#### Event: 'ping'\n\nEmitted for each inbound PING frame.  The only argument will be a `Buffer`\ncontaining the nonce in the ping request.  Note that the library presently\nresponds with a PONG frame for each inbound PING frame.\n\n#### Event: 'pong'\n\nEmitted for each inbound PONG frame.  The only argument will be a `Buffer`\ncontaining the nonce in the pong response.\n\n#### WatershedConnection.getProtocol()\n\nReturns the negotiated subprotocol, if any, for this connection, as a String.\nIf no subprotocol negotiation took place, this method returns `null`.\n\n#### WatershedConnection.send(data)\n\nSends a frame through the socket.  The single argument `data` may be a\n`Buffer`, in which case a BINARY frame is sent; or a `String`, in which case a\nTEXT frame is sent.\n\n#### WatershedConnection.end(reason)\n\nCloses the connection.  The RFC allows a reason for closing the connection to\nbe send in the CLOSE frame, though this is optional.  If passed, `reason`\nshould be a `String`.\n\n#### WatershedConnection.destroy()\n\nImmediately destroy the underlying socket, without sending a CLOSE frame.  You\ngenerally want `end()`, rather than this, in order to perform RFC-compliant\nconnection shutdowns.\n\n## License\n\nMIT.\n\n[1]: http://tools.ietf.org/html/rfc6455\n","publish_time":1635884817431,"_cnpm_publish_time":1635884817431,"dist-tags":{"latest":"0.4.1"}}