lib/wamp/client/connection.rb in wamp_client-0.1.1 vs lib/wamp/client/connection.rb in wamp_client-0.1.2
- old
+ new
@@ -30,11 +30,11 @@
require 'wamp/client/transport/faye_web_socket'
module Wamp
module Client
class Connection
- attr_accessor :options, :transport_class, :transport, :session, :verbose
+ attr_accessor :options, :transport_class, :transport, :session
@reconnect = true
@open = false
def is_open?
@@ -106,11 +106,10 @@
# @option options [Hash] :headers Custom headers to include during the connection
# @option options [WampClient::Serializer::Base] :serializer The serializer to use (default is json)
def initialize(options)
self.transport_class = options.delete(:transport) || Wamp::Client::Transport::WebSocketEventMachine
self.options = options || {}
- self.verbose = options[:verbose] || false
end
# Opens the connection
def open
@@ -181,22 +180,23 @@
# Initialize the transport
self.transport = self.transport_class.new(self.options)
# Setup transport callbacks
self.transport.on(:open) do
- puts "TRANSPORT OPEN" if self.verbose
+ logger.info("#{self.class.name} TRANSPORT OPEN")
+
# Call the callback
@on_connect.call if @on_connect
# Create the session
self._create_session
end
self.transport.on(:close) do |reason|
- puts "TRANSPORT CLOSED: #{reason}" if self.verbose
+ logger.info("#{self.class.name} TRANSPORT CLOSED: #{reason}")
@open = false
unless @retrying
@on_disconnect.call(reason) if @on_disconnect
end
@@ -212,11 +212,11 @@
self.transport_class.stop_event_machine
end
end
self.transport.on(:error) do |message|
- puts "TRANSPORT ERROR: #{message}"
+ logger.error("#{self.class.name} TRANSPORT ERROR: #{message}")
end
@open = true
self.transport.connect
@@ -234,15 +234,23 @@
@retry_timer = 2*@retry_timer unless @retry_timer == 32
@retrying = true
self._create_transport
- puts "Attempting Reconnect... Next attempt in #{@retry_timer} seconds" if self.verbose
+ logger.info("#{self.class.name} RECONNECT in #{@retry_timer} seconds")
self.transport_class.add_timer(@retry_timer*1000) do
self._retry if @retrying
end
end
+ end
+
+ private
+
+ # Returns the logger
+ #
+ def logger
+ Wamp::Client.logger
end
end
end
end
\ No newline at end of file