Class: Ably::Realtime::Presence::PresenceManager Private

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/ably/realtime/presence/presence_manager.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(presence) ⇒ PresenceManager

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of PresenceManager.



16
17
18
19
20
# File 'lib/ably/realtime/presence/presence_manager.rb', line 16

def initialize(presence)
  @presence = presence

  setup_channel_event_handlers
end

Instance Attribute Details

#presenceAbly::Realtime::Presence (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Ably::Realtime::Presence this Manager is associated with



14
15
16
# File 'lib/ably/realtime/presence/presence_manager.rb', line 14

def presence
  @presence
end

Instance Method Details

#on_attach(has_presence_flag) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ably/realtime/presence/presence_manager.rb', line 23

def on_attach(has_presence_flag)
  # RTP1
  if has_presence_flag
    # Expect SYNC ProtocolMessages from the server with a list of current members on this channel
    presence.members.change_state :sync_starting
  else
    # There server has indicated that there are no SYNC ProtocolMessages to come because
    # there are no members on this channel
    logger.debug { "#{self.class.name}: Emitting leave events for all members as a SYNC is not expected and thus there are no members on the channel" }
    presence.members.change_state :sync_none
  end
  presence.members.enter_local_members # RTP17f
end

#sync_process_messages(serial, presence_messages) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Process presence messages from SYNC messages. Sync can be server-initiated or triggered following ATTACH



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/ably/realtime/presence/presence_manager.rb', line 42

def sync_process_messages(serial, presence_messages)
  unless presence.members.sync_starting?
    presence.members.change_state :sync_starting
  end

  presence.members.update_sync_serial serial

  presence_messages.each do |presence_message|
    presence.__incoming_msgbus__.publish :sync, presence_message
  end

  presence.members.change_state :finalizing_sync if presence.members.sync_serial_cursor_at_end?
end