1.0.3 • Published 8 years ago

eventsource-worker v1.0.3

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

eventsource-worker Build Status

Start an EventSource in a web worker to avoid browser concurrency limits

$ npm install --save eventsource-worker

Browsers have concurrent connection limits (eg Chrome's limit is 6).

EventSources eat up the browser's number of available concurrent connections and slow your app down, or even stop it if you have six EventSources.

To get around the concurrency limits, we can open each EventSource in a web worker.

Usage

var EventSource = require('eventsource-worker')

var source = EventSource('http://myserver.com/events')

source.addEventListener('myevent', function (event) {
  // => `event` has properties `type` and `data`
})

API

EventSourceWorker(url) -> eventSource

url

Valid url pointing to an SSE endpoint.

eventSource

Returned from EventSourceWorker, the eventSource instance has two methods from the EventSource API.

addEventListener(eventType, listener)

Same as the native EventSource's addEventListener.

removeEventListener(eventType, listener)

Same as the native EventSource's removeEventListener.

close()

This is not implemented and currently throws an error. PRs welcome.

Contributing

The tests currently do not run on travis, only linting does.

All that needs to be done to make the tests happen is configure Zuul to use a valid saucelabs account.

Use npm run browser to run the tests locally.

License

MIT © Andrew Joslin