Sinatra example using EventSource (Server Sent Events)
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
config
public
tmp
views
Gemfile
Gemfile.lock
Readme.md
config.ru
sinatra_sse.rb

Readme.md

Sinatra-stream Example

Sinatra example using EventSource (Server Sent Events)

Original code from: https://gist.github.com/maccman/2992949

Server Sent Events are an awesome api that lets you push data asynchronously directly to your clients.

https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events https://developer.mozilla.org/en-US/docs/Web/API/EventSource

A polyfill for EventSource is available (thanks IE), please check:

https://github.com/Yaffle/EventSource

Setup:

gem i bundler

bundle

(you need to have Redis installed)

On ubuntu you can install redis by:

apt-get install redis-server

Run:

bundle exec rackup

Usage:

Open <http://localhost:4567>

Then from your console:

redis-cli publish message hello

Voila', you shoul see your message in every browser window you have open.