Sha256: 7d82ca23cd8aeecdf5651339cddd7920950d4a6a6d42977254c64d6e9192ac05

Contents?: true

Size: 1.16 KB

Versions: 2

Compression:

Stored size: 1.16 KB

Contents

module Angelo
  class Responder
    class Websocket < Responder

      class << self

        attr_writer :on_pong

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

      end

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

      def handle_request
        begin
          if @response_handler
            Angelo.log @connection, @request, @websocket, :switching_protocols
            @websocket.on_pong &Responder::Websocket.on_pong
            @base.filter :before
            @base.instance_exec(@websocket, &@response_handler)
            @base.filter :after
          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::StateError => rcse
            close_websocket
          end
        end
      end

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

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
angelo-0.4.1 lib/angelo/responder/websocket.rb
angelo-0.4.0 lib/angelo/responder/websocket.rb