lib/submodules/ably-ruby/lib/ably/realtime/client.rb in ably-rest-1.2.4 vs lib/submodules/ably-ruby/lib/ably/realtime/client.rb in ably-rest-1.2.6
- old
+ new
@@ -1,7 +1,8 @@
require 'uri'
require 'ably/realtime/channel/publisher'
+require 'ably/realtime/recovery_key_context'
module Ably
module Realtime
# A client that extends the functionality of the {Ably::Realtime::Client} and provides additional realtime-specific features.
#
@@ -9,10 +10,11 @@
include Ably::Modules::AsyncWrapper
include Ably::Realtime::Channel::Publisher
include Ably::Modules::Conversions
extend Forwardable
+ using Ably::Util::AblyExtensions
DOMAIN = 'realtime.ably.io'
# A {Aby::Realtime::Channels} object.
#
@@ -118,20 +120,26 @@
@transport_params = options.delete(:transport_params).to_h.each_with_object({}) do |(key, value), acc|
acc[key.to_s] = value.to_s
end
@rest_client = Ably::Rest::Client.new(options.merge(realtime_client: self))
- @echo_messages = rest_client.options.fetch(:echo_messages, true) == false ? false : true
- @queue_messages = rest_client.options.fetch(:queue_messages, true) == false ? false : true
+ @echo_messages = rest_client.options.fetch_with_default(:echo_messages, true)
+ @queue_messages = rest_client.options.fetch_with_default(:queue_messages, true)
@custom_realtime_host = rest_client.options[:realtime_host] || rest_client.options[:ws_host]
- @auto_connect = rest_client.options.fetch(:auto_connect, true) == false ? false : true
- @recover = rest_client.options[:recover]
+ @auto_connect = rest_client.options.fetch_with_default(:auto_connect, true)
+ @recover = rest_client.options.fetch_with_default(:recover, '')
- raise ArgumentError, "Recovery key '#{recover}' is invalid" if recover && !recover.match(Connection::RECOVER_REGEX)
-
@auth = Ably::Realtime::Auth.new(self)
@channels = Ably::Realtime::Channels.new(self)
@connection = Ably::Realtime::Connection.new(self, options)
+
+ unless @recover.nil_or_empty?
+ recovery_context = RecoveryKeyContext.from_json(@recover, logger)
+ unless recovery_context.nil?
+ @channels.set_channel_serials recovery_context.channel_serials # RTN16j
+ @connection.set_msg_serial_from_recover = recovery_context.msg_serial # RTN16f
+ end
+ end
end
# Return a {Ably::Realtime::Channel Realtime Channel} for the given name
#
# @param (see Ably::Realtime::Channels#get)