lib/submodules/ably-ruby/lib/ably/realtime/channel/channel_manager.rb in ably-rest-0.8.2 vs lib/submodules/ably-ruby/lib/ably/realtime/channel/channel_manager.rb in ably-rest-0.8.3

- old
+ new

@@ -24,11 +24,11 @@ end end # Commence attachment def detach(error = nil) - if connection.closed? || connection.connecting? + if connection.closed? || connection.connecting? || connection.suspended? channel.transition_state_machine :detached, error elsif can_transition_to?(:detached) send_detach_protocol_message end end @@ -57,11 +57,11 @@ # When a channel is no longer attached or has failed, # all messages awaiting an ACK response should fail immediately def fail_messages_awaiting_ack(error) # Allow a short time for other queued operations to complete before failing all messages EventMachine.add_timer(0.1) do - error = Ably::Exceptions::MessageDeliveryError.new('Channel is no longer in a state suitable to deliver this message to the server') unless error + error = Ably::Exceptions::MessageDeliveryFailed.new("Channel cannot publish messages whilst state is '#{channel.state}'") unless error fail_messages_in_queue connection.__pending_message_ack_queue__, error fail_messages_in_queue connection.__outgoing_message_queue__, error end end @@ -121,11 +121,19 @@ def setup_connection_event_handlers connection.unsafe_on(:closed) do channel.transition_state_machine :detaching if can_transition_to?(:detaching) end + connection.unsafe_on(:suspended) do |error| + if can_transition_to?(:detaching) + channel.transition_state_machine :detaching, Ably::Exceptions::ConnectionSuspended.new('Connection suspended', nil, 80002, error) + end + end + connection.unsafe_on(:failed) do |error| - channel.transition_state_machine :failed, error if can_transition_to?(:failed) + if can_transition_to?(:failed) + channel.transition_state_machine :failed, Ably::Exceptions::ConnectionFailed.new('Connection failed', nil, 80002, error) + end end end def logger connection.logger