lib/ably/realtime/presence.rb in ably-1.2.4 vs lib/ably/realtime/presence.rb in ably-1.2.6
- old
+ new
@@ -108,10 +108,18 @@
ensure_supported_payload data
send_presence_action_for_client(Ably::Models::PresenceMessage::ACTION.Enter, client_id, data, &success_block)
end
+ # @api private
+ def enter_client_with_id(id, client_id, data = nil, &success_block)
+ ensure_supported_client_id client_id
+ ensure_supported_payload data
+
+ send_presence_action_for_client(Ably::Models::PresenceMessage::ACTION.Enter, client_id, data, id, &success_block)
+ end
+
# Leave this client from this channel. This client will be removed from the presence
# set and presence subscribers will see a leave message for this client.
#
# @param (see Presence#enter)
#
@@ -336,12 +344,12 @@
members.sync_complete?
end
private
# @return [Ably::Models::PresenceMessage] presence message is returned allowing callbacks to be added
- def send_presence_protocol_message(presence_action, client_id, data)
- presence_message = create_presence_message(presence_action, client_id, data)
+ def send_presence_protocol_message(presence_action, client_id, data, id = nil)
+ presence_message = create_presence_message(presence_action, client_id, data, id)
unless presence_message.client_id
raise Ably::Exceptions::Standard.new('Unable to enter create presence message without a client_id', 400, Ably::Exceptions::Codes::UNABLE_TO_ENTER_PRESENCE_CHANNEL_NO_CLIENTID)
end
protocol_message = {
@@ -353,16 +361,17 @@
client.connection.send_protocol_message protocol_message
presence_message
end
- def create_presence_message(action, client_id, data)
+ def create_presence_message(action, client_id, data, id = nil)
model = {
action: Ably::Models::PresenceMessage.ACTION(action).to_i,
clientId: client_id,
- data: data
+ data: data,
}
+ model[:id] = id unless id.nil?
Ably::Models::PresenceMessage.new(model, logger: logger).tap do |presence_message|
presence_message.encode(client.encoders, channel.options) do |encode_error, error_message|
client.logger.error error_message
end
@@ -431,16 +440,16 @@
safe_yield(block, *args) if block_given?
EventMachine.next_tick { deferrable.fail(*args) } # allow errback to be added to the returned Deferrable
deferrable
end
- def send_presence_action_for_client(action, client_id, data, &success_block)
+ def send_presence_action_for_client(action, client_id, data, id = nil, &success_block)
requirements_failed_deferrable = ensure_presence_publishable_on_connection_deferrable
return requirements_failed_deferrable if requirements_failed_deferrable
deferrable = create_deferrable
ensure_channel_attached(deferrable) do
- send_presence_protocol_message(action, client_id, data).tap do |protocol_message|
+ send_presence_protocol_message(action, client_id, data, id).tap do |protocol_message|
protocol_message.callback { |message| deferrable_succeed deferrable, &success_block }
protocol_message.errback { |error| deferrable_fail deferrable, error }
end
end
end