{"_id":"watershed","_rev":"4251781","name":"watershed","description":"simple websockets (RFC6455) client and server","dist-tags":{"latest":"0.4.1"},"maintainers":[{"name":"arekinath","email":"alex@cooperi.net"},{"name":"bahamat","email":""},{"name":"jclulow","email":"josh@sysmgr.org"},{"name":"kebesays","email":""},{"name":"kusor","email":""},{"name":"michael.hicks","email":"michael.hicks@joyent.com"},{"name":"shmeeny","email":"richard.kiene@faithlife.com"},{"name":"todd.whiteman","email":"todd.whiteman@joyent.com"},{"name":"tpaul","email":""}],"time":{"modified":"2026-03-31T23:46:38.000Z","created":"2013-02-13T04:13:11.882Z","0.4.1":"2021-11-02T20:26:57.431Z","0.4.0":"2017-11-21T23:53:27.108Z","0.3.4":"2017-09-21T16:23:34.414Z","0.3.3":"2016-10-28T03:48:09.155Z","0.3.1":"2015-10-26T17:55:53.590Z","0.3.0":"2013-06-10T02:07:33.913Z","0.2.0":"2013-06-08T00:35:55.564Z","0.1.0":"2013-05-14T00:35:32.342Z","0.0.1":"2013-02-13T04:13:11.882Z"},"users":{},"author":{"name":"Joshua M. Clulow","email":"jmc@joyent.com"},"repository":{"type":"git","url":"git+https://github.com/joyent/node-watershed.git"},"versions":{"0.4.1":{"name":"watershed","version":"0.4.1","description":"simple websockets (RFC6455) client and server","main":"./lib/watershed.js","author":{"name":"Joshua M. Clulow","email":"jmc@joyent.com"},"repository":{"type":"git","url":"git+https://github.com/joyent/node-watershed.git"},"bugs":{"url":"https://github.com/joyent/node-watershed/issues"},"dependencies":{"readable-stream":"1.0.2","dtrace-provider":"~0.8"},"devDependencies":{"istanbul":"^0.4.0","tape":"^4.2.2"},"engines":["node >=0.8.0"],"gitHead":"88e01e435a6e2ec9b3dc921d7269e507caad11c6","homepage":"https://github.com/joyent/node-watershed#readme","_id":"watershed@0.4.1","_nodeVersion":"12.22.7","_npmVersion":"6.14.13","dist":{"shasum":"79aa9cad9f9ac22f9979000bd1dbffb870dcf1bd","size":9280,"noattachment":false,"key":"/watershed/-/watershed-0.4.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/watershed/download/watershed-0.4.1.tgz"},"_npmUser":{"name":"bahamat","email":"bahamat@digitalelf.net"},"directories":{},"maintainers":[{"name":"arekinath","email":"alex@cooperi.net"},{"name":"bahamat","email":""},{"name":"jclulow","email":"josh@sysmgr.org"},{"name":"kebesays","email":""},{"name":"kusor","email":""},{"name":"michael.hicks","email":"michael.hicks@joyent.com"},{"name":"shmeeny","email":"richard.kiene@faithlife.com"},{"name":"todd.whiteman","email":"todd.whiteman@joyent.com"},{"name":"tpaul","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/watershed_0.4.1_1635884817281_0.9069635041104287"},"_hasShrinkwrap":false,"publish_time":1635884817431,"_cnpm_publish_time":1635884817431,"_cnpmcore_publish_time":"2021-12-16T23:06:46.563Z"},"0.4.0":{"name":"watershed","version":"0.4.0","description":"simple websockets (RFC6455) client and server","main":"./lib/watershed.js","author":{"name":"Joshua M. Clulow","email":"jmc@joyent.com"},"repository":{"type":"git","url":"git://github.com/joyent/node-watershed.git"},"bugs":{"url":"https://github.com/joyent/node-watershed/issues"},"dependencies":{"readable-stream":"1.0.2","dtrace-provider":"~0.8"},"devDependencies":{"istanbul":"^0.4.0","tape":"^4.2.2"},"engines":["node >=0.8.0"],"gitHead":"09e7e3cd5956efa9bebebeb3e8fcbcb3e5a4290a","homepage":"https://github.com/joyent/node-watershed#readme","_id":"watershed@0.4.0","scripts":{},"_shasum":"e4124b877129b47652247767eb722029f8095531","_from":".","_npmVersion":"4.2.0","_nodeVersion":"0.12.18","_npmUser":{"name":"arekinath","email":"alex@cooperi.net"},"dist":{"shasum":"e4124b877129b47652247767eb722029f8095531","size":9391,"noattachment":false,"key":"/watershed/-/watershed-0.4.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/watershed/download/watershed-0.4.0.tgz"},"maintainers":[{"name":"arekinath","email":"alex@cooperi.net"},{"name":"bahamat","email":""},{"name":"jclulow","email":"josh@sysmgr.org"},{"name":"kebesays","email":""},{"name":"kusor","email":""},{"name":"michael.hicks","email":"michael.hicks@joyent.com"},{"name":"shmeeny","email":"richard.kiene@faithlife.com"},{"name":"todd.whiteman","email":"todd.whiteman@joyent.com"},{"name":"tpaul","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/watershed-0.4.0.tgz_1511308406929_0.5286243334412575"},"directories":{},"publish_time":1511308407108,"_hasShrinkwrap":false,"_cnpm_publish_time":1511308407108,"_cnpmcore_publish_time":"2021-12-16T23:06:46.843Z"},"0.3.4":{"name":"watershed","version":"0.3.4","description":"simple websockets (RFC6455) client and server","main":"./lib/watershed.js","author":{"name":"Joshua M. Clulow","email":"jmc@joyent.com"},"repository":{"type":"git","url":"git://github.com/joyent/node-watershed.git"},"bugs":{"url":"https://github.com/joyent/node-watershed/issues"},"dependencies":{"readable-stream":"1.0.2","dtrace-provider":"~0.8"},"devDependencies":{"istanbul":"^0.4.0","tape":"^4.2.2"},"engines":["node >=0.8.0"],"gitHead":"214d02f17ac35ab13de12e179e4a223c7251dba8","homepage":"https://github.com/joyent/node-watershed#readme","_id":"watershed@0.3.4","scripts":{},"_shasum":"79331f666366b3b1c6ab02ceb04bad8dd2eebb0c","_from":".","_npmVersion":"2.15.11","_nodeVersion":"4.6.2","_npmUser":{"name":"shmeeny","email":"richard.kiene@gmail.com"},"dist":{"shasum":"79331f666366b3b1c6ab02ceb04bad8dd2eebb0c","size":8634,"noattachment":false,"key":"/watershed/-/watershed-0.3.4.tgz","tarball":"http://registry.cnpm.dingdandao.com/watershed/download/watershed-0.3.4.tgz"},"maintainers":[{"name":"arekinath","email":"alex@cooperi.net"},{"name":"bahamat","email":""},{"name":"jclulow","email":"josh@sysmgr.org"},{"name":"kebesays","email":""},{"name":"kusor","email":""},{"name":"michael.hicks","email":"michael.hicks@joyent.com"},{"name":"shmeeny","email":"richard.kiene@faithlife.com"},{"name":"todd.whiteman","email":"todd.whiteman@joyent.com"},{"name":"tpaul","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/watershed-0.3.4.tgz_1506011014282_0.17506547295488417"},"directories":{},"publish_time":1506011014414,"_hasShrinkwrap":false,"_cnpm_publish_time":1506011014414,"_cnpmcore_publish_time":"2021-12-16T23:06:47.065Z"},"0.3.3":{"name":"watershed","version":"0.3.3","description":"simple websockets (RFC6455) client and server","main":"./lib/watershed.js","author":{"name":"Joshua M. Clulow","email":"jmc@joyent.com"},"repository":{"type":"git","url":"git://github.com/jclulow/node-watershed.git"},"dependencies":{"readable-stream":"1.0.2","dtrace-provider":"0.6.0"},"optionalDependencies":{"dtrace-provider":"0.6.0"},"engines":["node >=0.8.0"],"gitHead":"84d01ea350c5bd7ade083badf08c49fef46e125b","bugs":{"url":"https://github.com/jclulow/node-watershed/issues"},"homepage":"https://github.com/jclulow/node-watershed#readme","_id":"watershed@0.3.3","scripts":{},"_shasum":"ebfc2381cc246f61c7a50cc49ef57a1f028aad0f","_from":".","_npmVersion":"2.15.9","_nodeVersion":"4.6.0","_npmUser":{"name":"shmeeny","email":"richard.kiene@gmail.com"},"maintainers":[{"name":"arekinath","email":"alex@cooperi.net"},{"name":"bahamat","email":""},{"name":"jclulow","email":"josh@sysmgr.org"},{"name":"kebesays","email":""},{"name":"kusor","email":""},{"name":"michael.hicks","email":"michael.hicks@joyent.com"},{"name":"shmeeny","email":"richard.kiene@faithlife.com"},{"name":"todd.whiteman","email":"todd.whiteman@joyent.com"},{"name":"tpaul","email":""}],"dist":{"shasum":"ebfc2381cc246f61c7a50cc49ef57a1f028aad0f","size":8515,"noattachment":false,"key":"/watershed/-/watershed-0.3.3.tgz","tarball":"http://registry.cnpm.dingdandao.com/watershed/download/watershed-0.3.3.tgz"},"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/watershed-0.3.3.tgz_1477626488929_0.053544528083875775"},"directories":{},"publish_time":1477626489155,"_hasShrinkwrap":false,"_cnpm_publish_time":1477626489155,"_cnpmcore_publish_time":"2021-12-16T23:06:47.258Z"},"0.3.1":{"name":"watershed","version":"0.3.1","description":"simple websockets (RFC6455) client and server","main":"./lib/watershed.js","author":{"name":"Joshua M. Clulow","email":"jmc@joyent.com"},"repository":{"type":"git","url":"git://github.com/jclulow/node-watershed.git"},"dependencies":{"readable-stream":"1.0.2","dtrace-provider":"0.6.0"},"optionalDependencies":{"dtrace-provider":"0.6.0"},"engines":["node >=0.8.0"],"gitHead":"494c74d1a4ec8d99c8782bc26f73856112a8cc3d","bugs":{"url":"https://github.com/jclulow/node-watershed/issues"},"homepage":"https://github.com/jclulow/node-watershed","_id":"watershed@0.3.1","scripts":{},"_shasum":"6dcede31f5272638bd4472266d47633edc7e0382","_from":".","_npmVersion":"1.4.28","_npmUser":{"name":"jclulow","email":"josh@sysmgr.org"},"maintainers":[{"name":"arekinath","email":"alex@cooperi.net"},{"name":"bahamat","email":""},{"name":"jclulow","email":"josh@sysmgr.org"},{"name":"kebesays","email":""},{"name":"kusor","email":""},{"name":"michael.hicks","email":"michael.hicks@joyent.com"},{"name":"shmeeny","email":"richard.kiene@faithlife.com"},{"name":"todd.whiteman","email":"todd.whiteman@joyent.com"},{"name":"tpaul","email":""}],"dist":{"shasum":"6dcede31f5272638bd4472266d47633edc7e0382","size":8494,"noattachment":false,"key":"/watershed/-/watershed-0.3.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/watershed/download/watershed-0.3.1.tgz"},"directories":{},"publish_time":1445882153590,"_hasShrinkwrap":false,"_cnpm_publish_time":1445882153590,"_cnpmcore_publish_time":"2021-12-16T23:06:47.483Z"},"0.3.0":{"name":"watershed","version":"0.3.0","description":"simple websockets (RFC6455) client and server","main":"./lib/watershed.js","author":{"name":"Joshua M. Clulow","email":"jmc@joyent.com"},"repository":{"type":"git","url":"git://github.com/jclulow/node-watershed.git"},"dependencies":{"readable-stream":"1.0.2","dtrace-provider":"0.2.8"},"optionalDependencies":{"dtrace-provider":"0.2.8"},"engines":["node >=0.8.0"],"_id":"watershed@0.3.0","dist":{"shasum":"38c4995b3ccc9b1bef767a480054d1c7340578bb","size":8705,"noattachment":false,"key":"/watershed/-/watershed-0.3.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/watershed/download/watershed-0.3.0.tgz"},"maintainers":[{"name":"arekinath","email":"alex@cooperi.net"},{"name":"bahamat","email":""},{"name":"jclulow","email":"josh@sysmgr.org"},{"name":"kebesays","email":""},{"name":"kusor","email":""},{"name":"michael.hicks","email":"michael.hicks@joyent.com"},{"name":"shmeeny","email":"richard.kiene@faithlife.com"},{"name":"todd.whiteman","email":"todd.whiteman@joyent.com"},{"name":"tpaul","email":""}],"directories":{},"publish_time":1370830053913,"_hasShrinkwrap":false,"_cnpm_publish_time":1370830053913,"_cnpmcore_publish_time":"2021-12-16T23:06:47.695Z"},"0.2.0":{"name":"watershed","version":"0.2.0","description":"simple websockets (RFC6455) client and server","main":"./lib/watershed.js","author":{"name":"Joshua M. Clulow","email":"jmc@joyent.com"},"repository":{"type":"git","url":"git://github.com/jclulow/node-watershed.git"},"dependencies":{"readable-stream":"1.0.2"},"engines":["node >=0.8.0"],"_id":"watershed@0.2.0","dist":{"shasum":"e1cc5e264a0b8a644bfb74d74f80956facbd7cec","size":7159,"noattachment":false,"key":"/watershed/-/watershed-0.2.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/watershed/download/watershed-0.2.0.tgz"},"maintainers":[{"name":"arekinath","email":"alex@cooperi.net"},{"name":"bahamat","email":""},{"name":"jclulow","email":"josh@sysmgr.org"},{"name":"kebesays","email":""},{"name":"kusor","email":""},{"name":"michael.hicks","email":"michael.hicks@joyent.com"},{"name":"shmeeny","email":"richard.kiene@faithlife.com"},{"name":"todd.whiteman","email":"todd.whiteman@joyent.com"},{"name":"tpaul","email":""}],"directories":{},"publish_time":1370651755564,"_hasShrinkwrap":false,"_cnpm_publish_time":1370651755564,"_cnpmcore_publish_time":"2021-12-16T23:06:47.915Z"},"0.1.0":{"name":"watershed","version":"0.1.0","description":"simple websockets (RFC6455) client and server","main":"./lib/watershed.js","author":{"name":"Joshua M. Clulow","email":"jmc@joyent.com"},"repository":{"type":"git","url":"git://github.com/jclulow/node-watershed.git"},"engines":["node >=0.8.0"],"readmeFilename":"README.md","_id":"watershed@0.1.0","dist":{"shasum":"05908227c93d3eaa214df4bc86a9f11a97b21c5b","size":6451,"noattachment":false,"key":"/watershed/-/watershed-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/watershed/download/watershed-0.1.0.tgz"},"_from":".","_npmVersion":"1.2.2","_npmUser":{"name":"jclulow","email":"josh@sysmgr.org"},"maintainers":[{"name":"arekinath","email":"alex@cooperi.net"},{"name":"bahamat","email":""},{"name":"jclulow","email":"josh@sysmgr.org"},{"name":"kebesays","email":""},{"name":"kusor","email":""},{"name":"michael.hicks","email":"michael.hicks@joyent.com"},{"name":"shmeeny","email":"richard.kiene@faithlife.com"},{"name":"todd.whiteman","email":"todd.whiteman@joyent.com"},{"name":"tpaul","email":""}],"directories":{},"publish_time":1368491732342,"_hasShrinkwrap":false,"_cnpm_publish_time":1368491732342,"_cnpmcore_publish_time":"2021-12-16T23:06:48.114Z"},"0.0.1":{"name":"watershed","version":"0.0.1","description":"simple websockets (RFC6455) client and server","main":"./lib/watershed.js","author":{"name":"Joshua M. Clulow","email":"jmc@joyent.com"},"repository":{"type":"git","url":"git://github.com/jclulow/node-watershed.git"},"engines":["node >=0.8.0"],"readmeFilename":"README.md","_id":"watershed@0.0.1","dist":{"shasum":"bc160d76afc945845f30c06f8cfc8a68924da94e","size":5812,"noattachment":false,"key":"/watershed/-/watershed-0.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/watershed/download/watershed-0.0.1.tgz"},"_from":".","_npmVersion":"1.2.2","_npmUser":{"name":"jclulow","email":"josh@sysmgr.org"},"maintainers":[{"name":"arekinath","email":"alex@cooperi.net"},{"name":"bahamat","email":""},{"name":"jclulow","email":"josh@sysmgr.org"},{"name":"kebesays","email":""},{"name":"kusor","email":""},{"name":"michael.hicks","email":"michael.hicks@joyent.com"},{"name":"shmeeny","email":"richard.kiene@faithlife.com"},{"name":"todd.whiteman","email":"todd.whiteman@joyent.com"},{"name":"tpaul","email":""}],"directories":{},"publish_time":1360728791882,"_hasShrinkwrap":false,"_cnpm_publish_time":1360728791882,"_cnpmcore_publish_time":"2021-12-16T23:06:48.385Z"}},"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","_attachments":{},"homepage":"https://github.com/joyent/node-watershed#readme","bugs":{"url":"https://github.com/joyent/node-watershed/issues"}}