Sha256: ecc3ddd99629fb2dc700a8bf76462b52eded36caca2f9d5a5bfa42229a6e090b

Contents?: true

Size: 1.16 KB

Versions: 4

Compression:

Stored size: 1.16 KB

Contents

module Angelo

  class WebsocketResponder < Responder

    class << self

      attr_writer :on_pong

      def on_pong
        @on_pong ||= ->(e){}
      end

    end

    def params
      @params ||= parse_query_string
      @params
    end

    def request= request
      @params = nil
      @request = request
      @websocket = @request.websocket
      handle_request
    end

    def handle_request
      begin
        if @response_handler
          Angelo.log @connection, @request, @websocket, :switching_protocols
          @bound_response_handler ||= @response_handler.bind @base
          @websocket.on_pong &WebsocketResponder.on_pong
          @bound_response_handler[@websocket]
        else
          raise NotImplementedError
        end
      rescue IOError => ioe
        warn "#{ioe.class} - #{ioe.message}"
        close_websocket
      rescue => e
        error e.message
        ::STDERR.puts e.backtrace
        begin
          @connection.close
        rescue Reel::Connection::StateError => rcse
          close_websocket
        end
      end
    end

    def close_websocket
      @websocket.close
      @base.websockets.delete @websocket
    end

  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
angelo-0.1.7 lib/angelo/responder/websocket.rb
angelo-0.1.6 lib/angelo/responder/websocket.rb
angelo-0.1.5 lib/angelo/responder/websocket.rb
angelo-0.1.4 lib/angelo/responder/websocket.rb