lib/angelo/responder/websocket.rb in angelo-0.1.14 vs lib/angelo/responder/websocket.rb in angelo-0.1.15
- old
+ new
@@ -1,60 +1,55 @@
module Angelo
+ class Responder
+ class Websocket < Responder
- class WebsocketResponder < Responder
+ class << self
- class << self
+ attr_writer :on_pong
- attr_writer :on_pong
+ def on_pong
+ @on_pong ||= ->(e){}
+ end
- def on_pong
- @on_pong ||= ->(e){}
end
- end
+ def request= request
+ @params = nil
+ @request = request
+ @websocket = @request.websocket
+ handle_request
+ 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
- @base.before if @base.respond_to? :before
- @bound_response_handler[@websocket]
- @base.after if @base.respond_to? :after
- else
- raise NotImplementedError
- end
- rescue IOError => ioe
- warn "#{ioe.class} - #{ioe.message}"
- close_websocket
- rescue => e
- error e.message
- ::STDERR.puts e.backtrace
+ def handle_request
begin
- @connection.close
- rescue Reel::StateError => rcse
+ if @response_handler
+ Angelo.log @connection, @request, @websocket, :switching_protocols
+ @bound_response_handler ||= @response_handler.bind @base
+ @websocket.on_pong &Responder::Websocket.on_pong
+ @base.before if @base.respond_to? :before
+ @bound_response_handler[@websocket]
+ @base.after if @base.respond_to? :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
- end
- def close_websocket
- @websocket.close
- @base.websockets.remove_socket @websocket
- end
+ def close_websocket
+ @websocket.close
+ @base.websockets.remove_socket @websocket
+ end
+ end
end
-
end