Transmit Server-Sent Events over http.
npm install send-sse
var sendSSE = require('send-sse');
var events = require('./events');
http.createServer(function (req, res) {
sendSSE(req, res, events.onData);
}).listen(8080);
Create an SSE stream on the response object, returning a close method to stop the stream.
Required
Type: http.ServerRequest
Request object from http
.
Required
Type: http.ServerResponse
Response object from http
to send the stream down.
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.
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.
npm run test
MIT