This simple demo shows streaming events from server to client, using EventSource.
- The server (app.js) streams a list of 10 random numbers, one every 3 seconds, or until the client stops listening.
- The client (main.js) listens to the stream, prints the results and stops listening after the last number has been received.
You may need to install some missing modules with npm
Once node and npm are installed, you can checkout the source and install the missing modules:
$ git clone https://github.com/TravelingTechGuy/express-eventsource.git
$ cd ./express-eventsource
$ npm install
$ node app
Now, browse to your localhost (ie: http://localhost:3000) in your web browser.
An online demo is available on Heroku at http://express-eventsource.herokuapp.com/
- Proper error handling
- Tests
- Grunt project
Since IE (at least up to version 9) does not support EventSource, I'm using this polyfill by Yaffle. I've used Modernizr to bootstrap it when needed (and found out I need to bootstrap the test into Modernizr :) ). It requires some server-side changes:
- The event name and the way it's added
- Response headers
- An additional 2k padding at the top of the header - apparently necessary
###Client side:
- jQuery
- EventSource polyfill by Yaffle
- Modernizr - bootstrapping the polyfill
- HTML5 Bolierplate
- Wrapidify by Ju Kempff - page design
###Server side: