lib/ably/realtime/connection/connection_state_machine.rb in ably-0.8.15 vs lib/ably/realtime/connection/connection_state_machine.rb in ably-1.0.0

- old
+ new

@@ -45,12 +45,11 @@ end after_transition(to: [:connected]) do |connection, current_transition| error = current_transition.metadata.reason if is_error_type?(error) - connection.logger.warn "ConnectionManager: Connected with error - #{error.message}" - connection.emit :error, error + connection.logger.warn { "ConnectionManager: Connected with error - #{error.message}" } end end after_transition(to: [:disconnected, :suspended], from: [:connecting]) do |connection, current_transition| err = error_from_state_change(current_transition) @@ -60,19 +59,36 @@ after_transition(to: [:disconnected, :suspended], from: [:connected]) do |connection, current_transition| err = error_from_state_change(current_transition) connection.manager.respond_to_transport_disconnected_whilst_connected err end + after_transition(to: [:suspended]) do |connection, current_transition| + err = error_from_state_change(current_transition) + connection.manager.suspend_active_channels err + end + after_transition(to: [:disconnected, :suspended]) do |connection| connection.manager.destroy_transport # never reuse a transport if the connection has failed end before_transition(to: [:failed]) do |connection, current_transition| err = error_from_state_change(current_transition) connection.manager.fail err end + after_transition(to: [:failed]) do |connection, current_transition| + err = error_from_state_change(current_transition) + connection.manager.fail_active_channels err + end + + # RTN7C - If a connection enters the SUSPENDED, CLOSED or FAILED state... + # the client should consider the delivery of those messages as failed + after_transition(to: [:suspended, :closed, :failed]) do |connection, current_transition| + err = error_from_state_change(current_transition) + connection.manager.nack_messages_on_all_channels err + end + after_transition(to: [:closing], from: [:initialized, :disconnected, :suspended]) do |connection| connection.manager.force_close_connection end after_transition(to: [:closing], from: [:connecting, :connected]) do |connection| @@ -81,18 +97,21 @@ before_transition(to: [:closed], from: [:closing]) do |connection| connection.manager.destroy_transport end + after_transition(to: [:closed]) do |connection| + connection.manager.detach_active_channels + end + # Transitions responsible for updating connection#error_reason before_transition(to: [:disconnected, :suspended, :failed]) do |connection, current_transition| err = error_from_state_change(current_transition) connection.set_failed_connection_error_reason err end before_transition(to: [:connected, :closed]) do |connection, current_transition| err = error_from_state_change(current_transition) - if err connection.set_failed_connection_error_reason err else # Connected & Closed are "healthy" final states so reset the error reason connection.clear_error_reason