class PusherFake::Channel::Presence

A presence channel.

Attributes

members[R]

@return [Hash] Channel members hash.

Public Class Methods

new(name) click to toggle source

Create a new {Presence} object.

@param [String] name The channel name.

Calls superclass method
# File lib/pusher-fake/channel/presence.rb, line 13
def initialize(name)
  super

  @members = {}
end

Public Instance Methods

remove(connection) click to toggle source

Remove the connection from the channel and notify the channel.

Also trigger the member_removed webhook.

@param [Connection] connection The connection to remove.

Calls superclass method
# File lib/pusher-fake/channel/presence.rb, line 24
def remove(connection)
  super

  return unless members.key?(connection)

  trigger("member_removed",
          channel: name, user_id: members[connection][:user_id])

  emit("pusher_internal:member_removed", members.delete(connection))
end
subscription_data() click to toggle source

Return a hash containing presence information for the channel.

@return [Hash] Hash containing presence information.

# File lib/pusher-fake/channel/presence.rb, line 38
def subscription_data
  hash = members.to_h { |_, member| [member[:user_id], member[:user_info]] }

  { presence: { hash: hash, count: members.size } }
end

Private Instance Methods

subscription_succeeded(connection, options = {}) click to toggle source

Store the member data for the connection and notify the channel a member was added.

Also trigger the member_added webhook.

@param [Connection] connection Connection a subscription succeeded for. @param [Hash] options The options for the channel.

Calls superclass method
# File lib/pusher-fake/channel/presence.rb, line 53
def subscription_succeeded(connection, options = {})
  member = members[connection] = MultiJson.load(
    options[:channel_data], symbolize_keys: true
  )

  emit("pusher_internal:member_added", member)

  trigger("member_added", channel: name, user_id: member[:user_id])

  super
end