Stream events to the browser as server-sent events.
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
examples/simple
test
.gitignore
README.md
index.js
package.json

README.md

Streaming Server-Sent Events

Takes a stream of javascript events and pushes them to the browser as server-sent events.

Server

var ev = new EventEmitter;
setInterval(function () {
  ev.emit('ping', Date.now())
}, 1000)

var server = http.createServer(function(req, res) {
  if (req.url === '/data') {
    emitStream(ev)
      .pipe(ess.events())
      .pipe(res)
  }
})

server.listen(3000)

Client

var source = new EventSource('/data')
source.addEventListener('ping', function(time) {
  console.log(time)
})