Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/segment-boneyard/sse-stream
A Server-Sent Events transform stream
https://github.com/segment-boneyard/sse-stream
Last synced: about 5 hours ago
JSON representation
A Server-Sent Events transform stream
- Host: GitHub
- URL: https://github.com/segment-boneyard/sse-stream
- Owner: segment-boneyard
- Created: 2014-01-13T15:12:08.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2014-01-29T14:43:24.000Z (almost 11 years ago)
- Last Synced: 2024-04-09T16:31:15.005Z (7 months ago)
- Language: JavaScript
- Size: 182 KB
- Stars: 64
- Watchers: 41
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- Changelog: History.md
Awesome Lists containing this project
README
# sse-stream
A [Server-Sent Events](http://www.html5rocks.com/en/tutorials/eventsource/basics/) transform stream.
[![build status](https://secure.travis-ci.org/segmentio/sse-stream.png)](http://travis-ci.org/segmentio/sse-stream)
## Installation
```bash
$ npm install segmentio/sse-stream
```## Example
Transform a random object stream into sse format and stream it over http:
```js
var http = require('http');
var sse = require('sse-stream');
var Readable = require('stream').Readable;http.createServer(function(req, res){
objectStream().pipe(sse()).pipe(res);
}).listen(3000);function objectStream(){
var stream = new Readable({ objectMode: true });
var i = 0;
stream._read = function(){
this.push({
foo: ++i
});
if (i == 3) this.push(null);
}
return stream;
}
``````bash
$ curl http://localhost:3000
data: {"foo":1}data: {"foo":2}
data: {"foo":3}
$
```## API
### sse(opts)
Create a new stream that transforms data into the server-sent events format. It accepts (multiline) strings, numbers, buffers and objects as inputs. `error` events are emitted when functions or circular object structures are written to it.
Options:
- `retry:number` How many milliseconds the browser should wait in between reconnects
## License
MIT.