lib/submodules/ably-ruby/lib/ably/realtime/channel/channel_manager.rb in ably-rest-1.1.8 vs lib/submodules/ably-ruby/lib/ably/realtime/channel/channel_manager.rb in ably-rest-1.2.0

- old
+ new

@@ -36,10 +36,12 @@ # If no attached ProtocolMessage then this attached request was triggered by the client # library, such as returning to attached whne detach has failed if attached_protocol_message update_presence_sync_state_following_attached attached_protocol_message channel.properties.set_attach_serial(attached_protocol_message.channel_serial) + channel.options.set_modes_from_flags(attached_protocol_message.flags) + channel.options.set_params(attached_protocol_message.params) end end # An error has occurred on the channel def log_channel_error(error) @@ -62,10 +64,11 @@ channel.set_channel_error_reason protocol_message.error log_channel_error protocol_message.error end channel.properties.set_attach_serial(protocol_message.channel_serial) + channel.options.set_modes_from_flags(protocol_message.flags) if protocol_message.has_channel_resumed_flag? logger.debug { "ChannelManager: Additional resumed ATTACHED message received for #{channel.state} channel '#{channel.name}'" } else channel.emit :update, Ably::Models::ChannelStateChange.new( @@ -197,18 +200,25 @@ def channel_retry_timeout connection.defaults.fetch(:channel_retry_timeout) end def send_attach_protocol_message - send_state_change_protocol_message Ably::Models::ProtocolMessage::ACTION.Attach, :suspended # move to suspended + message_options = {} + message_options[:params] = channel.options.params if channel.options.params.any? + message_options[:flags] = channel.options.modes_to_flags if channel.options.modes + if channel.attach_resume + message_options[:flags] = message_options[:flags].to_i | Ably::Models::ProtocolMessage::ATTACH_FLAGS_MAPPING[:resume] + end + + send_state_change_protocol_message Ably::Models::ProtocolMessage::ACTION.Attach, :suspended, message_options end def send_detach_protocol_message(previous_state) send_state_change_protocol_message Ably::Models::ProtocolMessage::ACTION.Detach, previous_state # return to previous state if failed end - def send_state_change_protocol_message(new_state, state_if_failed) + def send_state_change_protocol_message(new_state, state_if_failed, message_options = {}) state_at_time_of_request = channel.state @pending_state_change_timer = EventMachine::Timer.new(realtime_request_timeout) do if channel.state == state_at_time_of_request error = Ably::Models::ErrorInfo.new(code: Ably::Exceptions::Codes::CHANNEL_OPERATION_FAILED_NO_RESPONSE_FROM_SERVER, message: "Channel #{new_state} operation failed (timed out)") channel.transition_state_machine state_if_failed, reason: error @@ -225,20 +235,22 @@ next unless pending_state_change_timer connection.unsafe_once(:connected) do next unless pending_state_change_timer connection.send_protocol_message( action: new_state.to_i, - channel: channel.name + channel: channel.name, + **message_options.to_h ) resend_if_disconnected_and_connected.call end end end resend_if_disconnected_and_connected.call connection.send_protocol_message( action: new_state.to_i, - channel: channel.name + channel: channel.name, + **message_options.to_h ) end def update_presence_sync_state_following_attached(attached_protocol_message) if attached_protocol_message.has_presence_flag?