lib/ably/realtime/client/incoming_message_dispatcher.rb in ably-0.1.6 vs lib/ably/realtime/client/incoming_message_dispatcher.rb in ably-0.2.0

- old
+ new

@@ -6,10 +6,11 @@ ACTION = Ably::Models::ProtocolMessage::ACTION def initialize(client, connection) @client = client @connection = connection + subscribe_to_incoming_protocol_messages end private attr_reader :client, :connection @@ -19,11 +20,11 @@ end def get_channel(channel_name) channels.fetch(channel_name) do logger.warn "Received channel message for non-existent channel" - Ably::Models::NilChannel.new + Ably::Realtime::Models::NilChannel.new end end def logger client.logger @@ -62,11 +63,13 @@ connection.transition_state_machine :closed when ACTION.Error logger.error "Error received: #{protocol_message.error}" if protocol_message.channel && !protocol_message.has_message_serial? - get_channel(protocol_message.channel).change_state Ably::Realtime::Channel::STATE.Failed, protocol_message.error + dispatch_channel_error protocol_message + else + connection.transition_state_machine :failed, protocol_message.error end when ACTION.Attach when ACTION.Attached get_channel(protocol_message.channel).change_state Ably::Realtime::Channel::STATE.Attached @@ -88,10 +91,18 @@ else raise ArgumentError, "Protocol Message Action #{protocol_message.action} is unsupported by this MessageDispatcher" end end + def dispatch_channel_error(protocol_message) + if !protocol_message.has_message_serial? + get_channel(protocol_message.channel).change_state Ably::Realtime::Channel::STATE.Failed, protocol_message.error + else + logger.fatal "Cannot process ProtocolMessage as not yet implemented: #{protocol_message}" + end + end + def update_connection_id(protocol_message) if protocol_message.connection_id && (protocol_message.connection_id != connection.id) logger.debug "New connection ID set to #{protocol_message.connection_id}" connection.update_connection_id protocol_message.connection_id end @@ -134,10 +145,10 @@ end end end def subscribe_to_incoming_protocol_messages - connection.__incoming_protocol_msgbus__.subscribe(:message) do |*args| + connection.__incoming_protocol_msgbus__.subscribe(:protocol_message) do |*args| dispatch_protocol_message *args end end end end