Sha256: bcd47e17c0ab492b6305873bd5caf3337a805d24a5c3d8704bffd93e3acc10b4

Contents?: true

Size: 1.63 KB

Versions: 33

Compression:

Stored size: 1.63 KB

Contents

module Ably::Realtime
  class Presence
    # PresenceManager is responsible for all actions relating to presence state
    #
    # This is a private class and should never be used directly by developers as the API is likely to change in future.
    #
    # @api private
    #
    class PresenceManager
      extend Forwardable

      # {Ably::Realtime::Presence} this Manager is associated with
      # @return [Ably::Realtime::Presence]
      attr_reader :presence

      def initialize(presence)
        @presence = presence

        setup_channel_event_handlers
      end

      # Expect SYNC ProtocolMessages from the server with a list of current members on this channel
      #
      # @return [void]
      #
      # @api private
      def sync_expected
        presence.members.change_state :sync_starting
      end

      # There server has indicated that there are no SYNC ProtocolMessages to come because
      # there are no members on this channel
      #
      # @return [void]
      #
      # @api private
      def sync_not_expected
        presence.members.change_state :in_sync
      end

      private
      def_delegators :presence, :members, :channel

      def setup_channel_event_handlers
        channel.unsafe_on(:detached) do
          presence.transition_state_machine :left if presence.can_transition_to?(:left)
        end

        channel.unsafe_on(:failed) do |metadata|
          presence.transition_state_machine :failed, metadata if presence.can_transition_to?(:failed)
        end

        presence.unsafe_on(:entered) do |message|
          presence.set_connection_id message.connection_id
        end
      end
    end
  end
end

Version data entries

33 entries across 33 versions & 2 rubygems

Version Path
ably-rest-0.8.15 lib/submodules/ably-ruby/lib/ably/realtime/presence/presence_manager.rb
ably-0.8.15 lib/ably/realtime/presence/presence_manager.rb
ably-rest-0.9.3 lib/submodules/ably-ruby/lib/ably/realtime/presence/presence_manager.rb
ably-rest-0.9.2 lib/submodules/ably-ruby/lib/ably/realtime/presence/presence_manager.rb
ably-rest-0.9.1 lib/submodules/ably-ruby/lib/ably/realtime/presence/presence_manager.rb
ably-rest-0.9.0 lib/submodules/ably-ruby/lib/ably/realtime/presence/presence_manager.rb
ably-rest-0.8.14 lib/submodules/ably-ruby/lib/ably/realtime/presence/presence_manager.rb
ably-0.8.14 lib/ably/realtime/presence/presence_manager.rb
ably-rest-0.8.13 lib/submodules/ably-ruby/lib/ably/realtime/presence/presence_manager.rb
ably-0.8.13 lib/ably/realtime/presence/presence_manager.rb
ably-0.8.12 lib/ably/realtime/presence/presence_manager.rb
ably-0.8.11 lib/ably/realtime/presence/presence_manager.rb
ably-0.8.10 lib/ably/realtime/presence/presence_manager.rb
ably-rest-0.8.9 lib/submodules/ably-ruby/lib/ably/realtime/presence/presence_manager.rb
ably-0.8.9 lib/ably/realtime/presence/presence_manager.rb
ably-0.8.8 lib/ably/realtime/presence/presence_manager.rb
ably-0.8.7 lib/ably/realtime/presence/presence_manager.rb
ably-0.8.6 lib/ably/realtime/presence/presence_manager.rb
ably-rest-0.8.6 lib/submodules/ably-ruby/lib/ably/realtime/presence/presence_manager.rb
ably-rest-0.8.5 lib/submodules/ably-ruby/lib/ably/realtime/presence/presence_manager.rb