Class: Rack::Stream::Handlers::WebSocket

Inherits:
AbstractHandler show all
Defined in:
lib/rack/stream/handlers/web_socket.rb

Overview

This handler uses delegates WebSocket requests to faye-websocket

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractHandler

#chunk, #initialize

Constructor Details

This class inherits a constructor from Rack::Stream::Handlers::AbstractHandler

Class Method Details

.accepts?(app) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/rack/stream/handlers/web_socket.rb', line 6

def self.accepts?(app)
  ::Faye::WebSocket.websocket?(app.env)
end

Instance Method Details

#closeObject



10
11
12
13
14
# File 'lib/rack/stream/handlers/web_socket.rb', line 10

def close
  @body.callback {
    @ws.close(@app.status)
  }
end

#openObject



16
17
18
19
20
21
# File 'lib/rack/stream/handlers/web_socket.rb', line 16

def open
  @ws = ::Faye::WebSocket.new(@app.env)
  @ws.onopen = lambda do |event|
    @body.each {|c| @ws.send(c)}
  end
end