rails/rails — pull request #10040 by dahakawang (2013-04-02 01:59:25+00:00)
Title: Add SSE functionality for rails based on AC::Live

This class is an initial implementation of HTML5 SSE for rails. Currently we provide 2 kinds of ways to implement a SSE server. The first is controller level SSE, in which we do not distinguish clients and will send data to all the clients that subscribe the same sse source.
The second is client level SSE, which we DO distinguish clients and the data sent to different client can be totally different.

## Controlller level SSE:

```ruby
class MySSE < ActionController::Base
include ActionController::Live
include ActionController::ServerSentEvents
extend ActionController::ServerSentEvents::ClassMethods
end
```
in this way, an action named ```sse_source``` will be created automaticlly and you can use ```MySSE.send_sse``` or ```MySSE.send_sse_hash``` to send event to all clients that subscribed the sse_source (you should register the action in route.rb manually)

## Client level SSE(Session awared):

```ruby
class MySSE < ActionController::Base
include ActionController::Live
include ActionController::ServerSentEvents

def event
start_serve do |sse_client|
we can access some session variables here
sse_client.send_sse sse
sse_client.send_sse_hash :data => "david"
end

end
end
```
Please note that Controller level SSE and Client level SSE are not meant to
work together in the same controller.