Class: Firehose::Rack::WebSocket

Inherits:
Rack::WebSocket::Application
  • Object
show all
Defined in:
lib/firehose/rack.rb

Instance Method Summary collapse

Instance Method Details

#on_close(env) ⇒ Object

Delete the subscription if the thing even happened.



55
56
57
# File 'lib/firehose/rack.rb', line 55

def on_close(env)
  @subscription.unsubscribe if @subscription
end

#on_error(env, error) ⇒ Object

Log websocket level errors



60
61
62
# File 'lib/firehose/rack.rb', line 60

def on_error(env, error)
  @subscription.unsubscribe if @subscription
end

#on_open(env) ⇒ Object

Subscribe to a path and make some magic happen, mmkmay?



43
44
45
46
47
48
49
50
51
52
# File 'lib/firehose/rack.rb', line 43

def on_open(env)
  req   = ::Rack::Request.new(env)
  cid   = req.params['cid']
  path  = req.path

  @subscription = Firehose::Subscription.new(cid)
  @subscription.subscribe path do |payload|
    send_data payload
  end
end