{"name":"sse-stream","version":"0.0.2","description":"expose html5 server sent events (sse) as a writable stream","main":"index.js","dependencies":{"through":"~2.2.7"},"devDependencies":{},"browser":{"index.js":"browser.js"},"scripts":{"test":"node test/index.js"},"repository":{"type":"git","url":"git://github.com/chrisdickinson/sse-stream.git"},"keywords":["sse","eventsource","stream","writable"],"author":{"name":"Chris Dickinson","email":"chris@neversaw.us"},"license":"MIT","_id":"sse-stream@0.0.2","dist":{"shasum":"404ed7ea8fb5ffba6edb7656b982f02e94c3e984","tarball":"http://registry-npm.ywwl.com/sse-stream/download/sse-stream-0.0.2.tgz","integrity":"sha512-gmuIFhE+2mtjFeA57nQqzIcuGgHFTT4TnAH8qqitSCZ7RWCqNi38wd4xXP5PnZ/xcS0vn4nWD4Da1U3mi2PmaQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCyhO43xvfYU1QDME+YtWhih7lPlLcKJRKl9TnJVED9QwIhANbI5iauueqlP/HPJ1+z7E1CIbGbpPxIesssFd9wcC6H"}],"size":4135,"noattachment":false,"key":"/sse-stream/-/sse-stream-0.0.2.tgz"},"_from":".","_npmVersion":"1.2.14","_npmUser":{"name":"chrisdickinson","email":"chris@neversaw.us"},"maintainers":[{"name":"chrisdickinson","email":"chris@neversaw.us"}],"readme":"# sse-stream\n\nExpose [HTML5 Server Sent Events](https://developer.mozilla.org/en-US/docs/Server-sent_events/Using_server-sent_events) as an installable appliance on Node.JS `http` servers; connections are emitted as [Writable streams](https://github.com/dominictarr/stream-spec/blob/master/stream_spec.md#writablestream).\n\n```javascript\n\nvar http = require('http')\n  , fs = require('fs')\n  , through = require('through')\n  , sse = require('sse-stream')('/sse')\n  , serv\n\nmodule.exports = serv = http.createServer(function(req, resp) {\n  resp.setHeader('content-type', 'text/html')\n  resp.end('<html><body><script type=\"text/javascript\">('+js+')()</script></body></html>')\n})\n\nsse.install(serv)\n\nsse.on('connection', function(client) {\n  fs.createReadStream('/usr/share/dict/words')\n    .pipe(through(function(buf) { this.emit('data', buf.toString()) }))\n    .pipe(client)\n})\n\n// client-side code:\nfunction js() {\n  var es = new EventSource('/sse')\n    , pre = document.createElement('pre')\n    , closed = false\n\n  document.body.appendChild(pre)\n\n  es.onmessage = function(ev) {\n    if(closed) return\n\n    pre.appendChild(document.createTextNode(ev.data))\n\n    window.scrollTo(0, pre.clientHeight)\n  }\n\n  es.addEventListener('end', function() {\n    es.close()\n    closed = true\n  }, true)\n\n  es.onerror = function(e) {\n    closed = true\n  }\n}\n\n```\n\n# API\n\n### sse = require('sse-stream')(path | options)\n\nCreate a SSE server that emits `connection` events on new, successful eventstream connections.\n\nThe argument may either be a string `path` to listen on (defaults to `/sse/`) or an object:\n\n```javascript\n{ path: '/listen/on/this/path'\n, keepalive: 1000 }\n``` \n\n`keepalive` determines the interval time in ms that keepalives will be sent to all connected clients.\n\n### sse.on('connection', function(client))\n\n`client` is a writable stream representing a client connection (request response pair).\n\nOf note, all data sent through this connection will be stringified before sending due to\nthe event stream spec.\n\n### client.retry(integer ms)\n\nSend a \"retry\" message that lets the client know how many MS to wait until retrying a connection that ended.\n\n# license\n\nMIT\n","publish_time":1364536258629,"_cnpm_publish_time":1364536258629,"dist-tags":{"latest":"0.0.5"}}