lib/ably/models/protocol_message.rb in ably-0.6.2 vs lib/ably/models/protocol_message.rb in ably-0.7.0

- old
+ new

@@ -5,31 +5,35 @@ # ProtocolMessages are serially numbered on a connection. # See the {http://docs.ably.io/client-lib-development-guide/protocol/ Ably client library developer documentation} # for further details on the members of a ProtocolMessage # # @!attribute [r] action - # @return [ACTION] Protocol Message action {Ably::Modules::Enum} from list of {ACTION}. Returns nil if action is unsupported by protocol. + # @return [ACTION] Protocol Message action {Ably::Modules::Enum} from list of {ACTION}. Returns nil if action is unsupported by protocol # @!attribute [r] count # @return [Integer] The count field is used for ACK and NACK actions. See {http://docs.ably.io/client-lib-development-guide/protocol/#message-acknowledgement message acknowledgement protocol} # @!attribute [r] error_info # @return [ErrorInfo] Contains error information # @!attribute [r] channel # @return [String] Channel name for messages # @!attribute [r] channel_serial # @return [String] Contains a serial number for a message on the current channel # @!attribute [r] connection_id - # @return [String] Contains a string connection ID + # @return [String] Contains a string public identifier for the connection + # @!attribute [r] connection_key + # @return [String] Contains a string private connection key used to recover this connection # @!attribute [r] connection_serial # @return [Bignum] Contains a serial number for a message sent from the server to the client # @!attribute [r] message_serial # @return [Bignum] Contains a serial number for a message sent from the client to the server # @!attribute [r] timestamp # @return [Time] An optional timestamp, applied by the service in messages sent to the client, to indicate the system time at which the message was sent (milliseconds past epoch) # @!attribute [r] messages - # @return [Message] A {ProtocolMessage} with a `:message` action contains one or more messages belonging to a channel. + # @return [Message] A {ProtocolMessage} with a `:message` action contains one or more messages belonging to a channel # @!attribute [r] presence - # @return [PresenceMessage] A {ProtocolMessage} with a `:presence` action contains one or more presence updates belonging to a channel. + # @return [PresenceMessage] A {ProtocolMessage} with a `:presence` action contains one or more presence updates belonging to a channel + # @!attribute [r] flags + # @return [Integer] Flags inidicating special ProtocolMessage states # @!attribute [r] hash # @return [Hash] Access the protocol message Hash object ruby'fied to use symbolized keys # class ProtocolMessage include Ably::Modules::ModelCommon @@ -54,11 +58,12 @@ attach: 10, attached: 11, detach: 12, detached: 13, presence: 14, - message: 15 + message: 15, + sync: 16 ) # Indicates this protocol message action will generate an ACK response such as :message or :presence def self.ack_required?(for_action) [ACTION.Presence, ACTION.Message].include?(ACTION(for_action)) @@ -72,11 +77,11 @@ @hash_object[:action] = ACTION(@hash_object[:action]).to_i unless @hash_object[:action].kind_of?(Integer) @hash_object.freeze end - %w( id channel channel_serial connection_id ).each do |attribute| + %w(id channel channel_serial connection_id connection_key).each do |attribute| define_method attribute do hash[attribute.to_sym] end end @@ -153,9 +158,20 @@ def presence @presence ||= Array(hash[:presence]).map do |message| Ably::Models.PresenceMessage(message, self) end + end + + # Flags as bits + def flags + Integer(hash[:flags]) + rescue TypeError + 0 + end + + def has_presence_flag? + flags & 1 == 1 end # Indicates this protocol message will generate an ACK response when sent # Examples of protocol messages required ACK include :message and :presence def ack_required?