lib/submodules/ably-ruby/lib/ably/realtime/presence.rb in ably-rest-0.8.5 vs lib/submodules/ably-ruby/lib/ably/realtime/presence.rb in ably-rest-0.8.6

- old
+ new

@@ -72,12 +72,12 @@ def enter(options = {}, &success_block) client_id = options.fetch(:client_id, self.client_id) data = options.fetch(:data, nil) deferrable = create_deferrable + ensure_supported_client_id client_id ensure_supported_payload data unless data.nil? - raise Ably::Exceptions::Standard.new('Unable to enter presence channel without a client_id', 400, 91000) unless client_id @data = data @client_id = client_id return deferrable_succeed(deferrable, &success_block) if state == STATE.Entered @@ -118,12 +118,12 @@ # @yield [Ably::Realtime::Presence] On success, will call the block with this {Ably::Realtime::Presence} object # @return [Ably::Util::SafeDeferrable] Deferrable that supports both success (callback) and failure (errback) callbacks # def enter_client(client_id, options = {}, &success_block) raise ArgumentError, 'options must be a Hash' unless options.kind_of?(Hash) + ensure_supported_client_id client_id ensure_supported_payload options[:data] if options.has_key?(:data) - raise Ably::Exceptions::Standard.new('Unable to enter presence channel without a client_id', 400, 91000) unless client_id send_presence_action_for_client(Ably::Models::PresenceMessage::ACTION.Enter, client_id, options, &success_block) end # Leave this client from this channel. This client will be removed from the presence @@ -137,10 +137,11 @@ # def leave(options = {}, &success_block) data = options.fetch(:data, self.data) # nil value defaults leave data to existing value deferrable = create_deferrable + ensure_supported_client_id client_id ensure_supported_payload data unless data.nil? raise Ably::Exceptions::Standard.new('Unable to leave presence channel that is not entered', 400, 91002) unless able_to_leave? @data = data @@ -176,12 +177,12 @@ # @yield (see Presence#enter_client) # @return (see Presence#enter_client) # def leave_client(client_id, options = {}, &success_block) raise ArgumentError, 'options must be a Hash' unless options.kind_of?(Hash) + ensure_supported_client_id client_id ensure_supported_payload options[:data] if options.has_key?(:data) - raise Ably::Exceptions::Standard.new('Unable to leave presence channel without a client_id', 400, 91000) unless client_id send_presence_action_for_client(Ably::Models::PresenceMessage::ACTION.Leave, client_id, options, &success_block) end # Update the presence data for this client. If the client is not already a member of @@ -196,12 +197,12 @@ # def update(options = {}, &success_block) data = options.fetch(:data, nil) deferrable = create_deferrable + ensure_supported_client_id client_id ensure_supported_payload data unless data.nil? - raise Ably::Exceptions::Standard.new('Unable to update presence channel without a client_id', 400, 91000) unless client_id @data = data ensure_presence_publishable_on_connection ensure_channel_attached(deferrable) do @@ -228,12 +229,12 @@ # @yield (see Presence#enter_client) # @return (see Presence#enter_client) # def update_client(client_id, options = {}, &success_block) raise ArgumentError, 'options must be a Hash' unless options.kind_of?(Hash) + ensure_supported_client_id client_id ensure_supported_payload options[:data] if options.has_key?(:data) - raise Ably::Exceptions::Standard.new('Unable to enter presence channel without a client_id', 400, 91000) unless client_id send_presence_action_for_client(Ably::Models::PresenceMessage::ACTION.Update, client_id, options, &success_block) end # Get the presence state for this Channel. @@ -383,9 +384,21 @@ yield else attach_channel_then { yield } end deferrable + end + + def ensure_supported_client_id(check_client_id) + unless check_client_id + raise Ably::Exceptions::IncompatibleClientId.new('Unable to enter/update/leave presence channel without a client_id', 400, 40012) + end + if check_client_id == '*' + raise Ably::Exceptions::IncompatibleClientId.new('Unable to enter/update/leave presence channel with the reserved wildcard client_id', 400, 40012) + end + unless client.auth.can_assume_client_id?(check_client_id) + raise Ably::Exceptions::IncompatibleClientId.new("Cannot enter with provided client_id '#{check_client_id}' as it is incompatible with the current configured client_id '#{client.client_id}'", 400, 40012) + end end def send_protocol_message_and_transition_state_to(action, options = {}, &success_block) deferrable = options.fetch(:deferrable) { raise ArgumentError, 'option :deferrable is required' } client_id = options.fetch(:client_id) { raise ArgumentError, 'option :client_id is required' }