middleware for journeyman to simplify server sent events
JavaScript
Switch branches/tags
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
static
test
.gitignore
.travis.yml
README.md
package.json
rivulet.js

README.md

rivulet

Build Status

Middleware for journeyman to simplify server sent events

Client Side:

  <html>
    <head>
      <script type='text/javascript' src='/rivulets/event-source.js' />
      <script type='text/javascript'>
        var eventsource = new EventSource('/rivulets/test');

        eventsource.addEventListener('alert', function(message) {
          alert("Alert: " + message.data);
        });

        eventsource.addEventListener('message', function(message) {
          alert("Message: " + message.data);
        });
      </script>
    </head>
    <body>
      <h1>Test Page</h1>
    </body>
  </html>

Server Side:

var Rivulet      = require('rivulet');
var Journeyman   = require('journeyman');

var journeyman = new Journeyman(3000);
var rivulet = new Rivulet();

journeyman.use(function(req, res, next) {
  // render html page
});

journeyman.use(rivulet.middleware());
journeyman.listen();

To show an alert of "Alert: HELLO WORLD"

rivulet.send('test', 'HELLO WORLD', 'alert');

To show an alert of "Message: HELLO WORLD"

rivulet.send('test', 'HELLO WORLD');

Events:

Listening for a new connection

rivulet.on('connection', function(path, request, response) {
// Do something cool!
});

Listening for a disconnection

rivulet.on('disconnection', function(path, request, response) {
// Do something cool!
});

Thanks

Thanks to Yaffle for the event source polyfill which can be found here