lifo / cramp

Real-time web application framework in Ruby
http://cramp.in
MIT License
1.5k stars 121 forks source link

Specifying an SSE event name as an option to render #28

Closed rookus closed 13 years ago

rookus commented 13 years ago

Hi Pratik,

Just a quick patch that allows specification of an event name as an option to 'render' when using the :sse transport.

class EventAction < Cramp::Action
  self.transport = :sse
  periodic_timer :send_named_event, :every => 5

  def send_named_event
    render "This event has a name", :event => "special"
  end
end

The MessageEvent.type (received by the client) will be "special" rather than the default, which is just "message".

var source = new EventSource('/events');
source.addEventListener('special', function(e) {
   console.log(e);
}, false);

Cheers, Luke

lifo commented 13 years ago

Thanks for the patch!