Module: Sinatra::SSE

Extended by:
Marshal
Defined in:
lib/sinatra/sse.rb,
lib/sinatra/sse/version.rb,
lib/sinatra/sse.rb

Overview

Support for SSE streams.

The Sinatra::SSE module adds support for streaming server sent events.

It wraps a sinatra stream (via stream :keep_open) in a structure which

  • formats events according to the SSE specs, and

  • keeps the connection alive by sending some data every 28 seconds.

Defined Under Namespace

Modules: Marshal Classes: Stream

Constant Summary collapse

VERSION =

The Sinatra::SSE version number

"0.1"
KEEP_ALIVE =

The keepalive period.

28

Constants included from Marshal

Marshal::FIXED_ORDER

Instance Method Summary collapse

Methods included from Marshal

marshal, unmarshal, unmarshal_all

Instance Method Details

#sse_stream(&block) ⇒ Object

Start a SSE stream.



76
77
78
79
80
81
82
# File 'lib/sinatra/sse.rb', line 76

def sse_stream(&block)
  content_type "text/event-stream"

  stream :keep_open do |out|
    yield Sinatra::SSE::Stream.new(out)
  end
end