Sha256: ce6487fa91991f2acd423ccfeb520c4565966ee5c87b5df3903f2c1b5efb4528

Contents?: true

Size: 1.87 KB

Versions: 45

Compression:

Stored size: 1.87 KB

Contents

require 'ably/modules/state_machine'

module Ably::Realtime
  class Presence
    # Internal class to manage presence state for {Ably::Realtime::Presence}
    #
    # @api private
    #
    class PresenceStateMachine
      include Ably::Modules::StateMachine

      # States supported by this StateMachine match #{Presence::STATE}s
      #   :initialized
      #   :entering
      #   :entered
      #   :leaving
      #   :left
      Presence::STATE.each_with_index do |state_enum, index|
        state state_enum.to_sym, initial: index == 0
      end

      # Entering or entered states can skip leaving and go straight to left if a channel is detached
      # A channel that detaches very quickly will also go straight to :left from :initialized
      transition :from => :initialized,  :to => [:entering, :left]
      transition :from => :entering,     :to => [:entered, :leaving, :left]
      transition :from => :entered,      :to => [:leaving, :left]
      transition :from => :leaving,      :to => [:left, :entering]

      after_transition do |presence, transition|
        presence.synchronize_state_with_statemachine
      end

      after_transition(to: [:entering]) do |presence, current_transition|
        presence.manager.enter current_transition.metadata
      end

      after_transition(to: [:leaving]) do |presence, current_transition|
        presence.manager.leave current_transition.metadata
      end

      # Transitions responsible for updating channel#error_reason
      before_transition(to: [:left]) do |presence, current_transition|
        presence.channel.set_channel_error_reason current_transition.metadata if is_error_type?(current_transition.metadata)
      end

      private
      def channel
        object.channel
      end

      # Logged needs to be defined as it is used by {Ably::Modules::StateMachine}
      def logger
        channel.logger
      end
    end
  end
end

Version data entries

45 entries across 45 versions & 2 rubygems

Version Path
ably-rest-1.1.5 lib/submodules/ably-ruby/lib/ably/realtime/presence/presence_state_machine.rb
ably-1.1.5 lib/ably/realtime/presence/presence_state_machine.rb
ably-rest-1.1.4 lib/submodules/ably-ruby/lib/ably/realtime/presence/presence_state_machine.rb
ably-1.1.4 lib/ably/realtime/presence/presence_state_machine.rb
ably-rest-1.1.4.rc lib/submodules/ably-ruby/lib/ably/realtime/presence/presence_state_machine.rb
ably-1.1.4.rc lib/ably/realtime/presence/presence_state_machine.rb
ably-rest-1.1.3 lib/submodules/ably-ruby/lib/ably/realtime/presence/presence_state_machine.rb
ably-1.1.3 lib/ably/realtime/presence/presence_state_machine.rb
ably-rest-1.1.2 lib/submodules/ably-ruby/lib/ably/realtime/presence/presence_state_machine.rb
ably-1.1.2 lib/ably/realtime/presence/presence_state_machine.rb
ably-rest-1.1.2.rc1 lib/submodules/ably-ruby/lib/ably/realtime/presence/presence_state_machine.rb
ably-1.1.1 lib/ably/realtime/presence/presence_state_machine.rb
ably-rest-1.1.0 lib/submodules/ably-ruby/lib/ably/realtime/presence/presence_state_machine.rb
ably-1.1.0 lib/ably/realtime/presence/presence_state_machine.rb
ably-1.0.7 lib/ably/realtime/presence/presence_state_machine.rb
ably-rest-1.0.6 lib/submodules/ably-ruby/lib/ably/realtime/presence/presence_state_machine.rb
ably-1.0.6 lib/ably/realtime/presence/presence_state_machine.rb
ably-rest-1.0.5 lib/submodules/ably-ruby/lib/ably/realtime/presence/presence_state_machine.rb
ably-1.0.5 lib/ably/realtime/presence/presence_state_machine.rb
ably-1.0.4 lib/ably/realtime/presence/presence_state_machine.rb