Class: Rasti::Web::Broadcaster
- Inherits:
-
Object
- Object
- Rasti::Web::Broadcaster
- Extended by:
- ClassConfig, Forwardable
- Defined in:
- lib/rasti/web/broadcaster.rb,
lib/rasti/web/broadcaster/timer.rb,
lib/rasti/web/broadcaster/version.rb
Defined Under Namespace
Classes: Timer
Constant Summary collapse
- KEEP_ALIVE_EVENT =
'keepAlive'
- VERSION =
'2.0.0'
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, headers = {}) ⇒ Broadcaster
constructor
A new instance of Broadcaster.
Constructor Details
#initialize(app, headers = {}) ⇒ Broadcaster
Returns a new instance of Broadcaster.
44 45 46 47 48 49 50 51 |
# File 'lib/rasti/web/broadcaster.rb', line 44 def initialize(app, headers={}) @app = app @headers = headers @mutex = Mutex.new @subscriptions = {} end |
Instance Method Details
#call(env) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/rasti/web/broadcaster.rb', line 53 def call(env) if Faye::EventSource.eventsource? env event_source = Faye::EventSource.new env, headers: headers subscription_id = subscribe channel_from(env), event_source event_source.on :close do unsubscribe subscription_id event_source = nil end event_source.rack_response else app.call env end end |