lib/async_cable/connection.rb in async_cable-0.2.0 vs lib/async_cable/connection.rb in async_cable-0.2.1
- old
+ new
@@ -7,18 +7,21 @@
class << self
def inherited(subclass)
subclass.identified_as subclass.name.demodulize.underscore
end
+ # sets #channel_name for connection class
def identified_as(channel)
@channel_name = channel.to_s
end
+ # @return [String]
def channel_name
@channel_name
end
+ # @return [Logger]
def logger
AsyncCable.config.logger
end
# Transmit data to all WS connections in current channel and provided stream.
@@ -75,10 +78,12 @@
# @return [String] stream name
def stream_name
@stream_name
end
+ # @param reason [String,NilClass] exception message.
+ # @raise [AsyncCable::UnauthorizedError]
def reject_unauthorized(reason = nil)
raise UnauthorizedError, reason
end
# WS connection close code
@@ -92,10 +97,11 @@
# @return [Boolean]
def close_clean?
close_code == Protocol::WebSocket::Error::NO_ERROR
end
+ # Called when connection being opened.
# @param env [Hash]
# @raise [AsyncCable::Errors::StreamNameNotSet] if #stream_for was not called
# @raise [AsyncCable::Errors::UnauthorizedError] if #reject_unauthorized was called
def handle_open(env)
logger.debug { "#{self.class}#handle_open" }
@@ -103,20 +109,24 @@
on_open
raise Errors::StreamNameNotSet, self.class.name unless defined?(@stream_name)
Registry.add(channel_name, stream_name, self)
end
+ # Called when connection being closed.
+ # @see #close_code #close_reason for close details.
def handle_close
logger.debug { "#{self.class}#handle_close clean=#{close_clean?} code=#{close_code} reason=#{close_reason}" }
close
Registry.remove(channel_name, stream_name, self)
on_close
end
+ # @return [String]
def channel_name
self.class.channel_name
end
+ # @return [Logger]
def logger
self.class.logger
end
end
end