lib/submodules/ably-ruby/lib/ably/realtime/client.rb in ably-rest-0.8.2 vs lib/submodules/ably-ruby/lib/ably/realtime/client.rb in ably-rest-0.8.3
- old
+ new
@@ -32,14 +32,18 @@
# The {Ably::Rest::Client REST client} instantiated with the same credentials and configuration that is used for all REST operations such as authentication
# @return [Ably::Rest::Client]
attr_reader :rest_client
- # When false the client suppresses messages originating from this connection being echoed back on the same connection. Defaults to true
+ # When false the client suppresses messages originating from this connection being echoed back on the same connection. Defaults to true
# @return [Boolean]
attr_reader :echo_messages
+ # If false, this disables the default behaviour whereby the library queues messages on a connection in the disconnected or connecting states. Defaults to true
+ # @return [Boolean]
+ attr_reader :queue_messages
+
# The custom realtime websocket host that is being used if it was provided with the option `:ws_host` when the {Client} was created
# @return [String,Nil]
attr_reader :custom_realtime_host
# When true, as soon as the client library is instantiated it will connect to Ably. If this attribute is false, a connection must be opened explicitly
@@ -50,11 +54,12 @@
# @return [String,Nil]
attr_reader :recover
def_delegators :auth, :client_id, :auth_options
def_delegators :@rest_client, :encoders
- def_delegators :@rest_client, :environment, :use_tls?, :protocol, :protocol_binary?, :custom_host
+ def_delegators :@rest_client, :use_tls?, :protocol, :protocol_binary?
+ def_delegators :@rest_client, :environment, :custom_host, :custom_port, :custom_tls_port
def_delegators :@rest_client, :log_level
# Creates a {Ably::Realtime::Client Realtime Client} and configures the {Ably::Auth} object for the connection.
#
# @param (see Ably::Rest::Client#initialize)
@@ -73,13 +78,14 @@
# # create a new client and configure a client ID used for presence
# client = Ably::Realtime::Client.new(key: 'key.id:secret', client_id: 'john')
#
def initialize(options)
@rest_client = Ably::Rest::Client.new(options)
- @auth = @rest_client.auth
+ @auth = Ably::Realtime::Auth.new(self)
@channels = Ably::Realtime::Channels.new(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
@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]
raise ArgumentError, "Recovery key is invalid" if @recover && !@recover.match(Connection::RECOVER_REGEX)
@@ -172,14 +178,24 @@
@fallback_endpoints[fallback_endpoint_index % @fallback_endpoints.count]
end
private
def endpoint_for_host(host)
- URI::Generic.build(
+ port = if use_tls?
+ custom_tls_port
+ else
+ custom_port
+ end
+
+ raise ArgumentError, "Custom port must be an Integer or nil" if port && !port.kind_of?(Integer)
+
+ options = {
scheme: use_tls? ? 'wss' : 'ws',
host: host
- )
+ }
+ options.merge!(port: port) if port
+
+ URI::Generic.build(options)
end
end
end
end
-