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

Merged
merged 1 commit into from Sep 23, 2011

Projects

None yet

2 participants

@rookus

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 lifo merged commit 5d3be6e into lifo:master Sep 23, 2011
@lifo
Owner

Thanks for the patch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment