Class: Sinapse::Server

Inherits:
Goliath::API
  • Object
show all
Defined in:
lib/sinapse/server.rb

Instance Method Summary collapse

Instance Method Details

#keep_aliveObject



15
16
17
# File 'lib/sinapse/server.rb', line 15

def keep_alive
  @keep_alive ||= KeepAlive.new
end

#on_close(env) ⇒ Object



19
20
21
22
# File 'lib/sinapse/server.rb', line 19

def on_close(env)
  close_redis(env['redis']) if env['redis']
  keep_alive.delete(env)
end

#response(env) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/sinapse/server.rb', line 24

def response(env)
  env['redis'] = Redis.new(:driver => :synchrony, :url => Sinapse.config[:url])

  user, channels = authenticate(env)
  return [401, {}, []] if user.nil? || channels.empty?

  EM.next_tick do
    sse(env, :ok, :authentication, retry: Config.retry)
    subscribe(env, user, channels)
    keep_alive << env
  end

  chunked_streaming_response(200, response_headers(env))
end