class Volt::WebsocketHandler

Public Class Methods

new(app) click to toggle source
# File lib/volt/server/websocket/websocket_handler.rb, line 15
def initialize(app)
  @app = app
end

Public Instance Methods

call(env) click to toggle source
# File lib/volt/server/websocket/websocket_handler.rb, line 19
def call(env)
  if Faye::WebSocket.websocket?(env)
    ws = Faye::WebSocket.new(env, nil, WEBSOCKET_OPTIONS)

    socket_connection_handler = SocketConnectionHandler.new(ws)

    ws.on :message do |event|
      socket_connection_handler.process_message(event.data)
    end

    ws.on :close do |event|
      socket_connection_handler.closed

      ws = nil
    end

    # Return async Rack response
    ws.rack_response
  else
    # Call down to the app
    @app.call(env)
  end
end