send-sse
v0.2.0
Published
Server-Sent Events over http
Downloads
6
Maintainers
Readme
Send SSE
Transmit Server-Sent Events over http.
Installation
npm install send-sse
Usage
var sendSSE = require('send-sse');
var events = require('./events');
http.createServer(function (req, res) {
sendSSE(req, res, events.onData);
}).listen(8080);
API
sendSSE(request, response, onOpen[, onClose])
-> close
Create an SSE stream on the response object, returning a close method to stop the stream.
request
Required
Type: http.ServerRequest
Request object from http
.
response
Required
Type: http.ServerResponse
Response object from http
to send the stream down.
onOpen
Required
Type: function (broadcast)
Method called when streaming events begins, passes in a broadcase method as the first parameter which can be used to send events on the stream.
onClose
Optional
Type: function (broadcast)
Called when the connection is closed, either from client or server, passing in the same broadcast method that onOpen receives.
Note: If onClose
is not passed in, and onOpen
returns a method, this method will be used as the onClose
handler. This makes geval events work seamlessly.
Contributing
npm run test
License
MIT