Class: PusherClient::Channel

Inherits:
Object
  • Object
show all
Defined in:
lib/pusher-client/channel.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(channel_name, user_data = nil, logger = PusherClient.logger) ⇒ Channel

Returns a new instance of Channel


7
8
9
10
11
12
13
14
# File 'lib/pusher-client/channel.rb', line 7

def initialize(channel_name, user_data=nil, logger=PusherClient.logger)
  @name = channel_name
  @user_data = user_data
  @logger = logger
  @global = false
  @callbacks = {}
  @subscribed = false
end

Instance Attribute Details

#callbacksObject (readonly)

Returns the value of attribute callbacks


5
6
7
# File 'lib/pusher-client/channel.rb', line 5

def callbacks
  @callbacks
end

#globalObject

Returns the value of attribute global


4
5
6
# File 'lib/pusher-client/channel.rb', line 4

def global
  @global
end

#nameObject (readonly)

Returns the value of attribute name


5
6
7
# File 'lib/pusher-client/channel.rb', line 5

def name
  @name
end

#subscribedObject

Returns the value of attribute subscribed


4
5
6
# File 'lib/pusher-client/channel.rb', line 4

def subscribed
  @subscribed
end

#user_dataObject (readonly)

Returns the value of attribute user_data


5
6
7
# File 'lib/pusher-client/channel.rb', line 5

def user_data
  @user_data
end

Instance Method Details

#acknowledge_subscription(data) ⇒ Object


38
39
40
# File 'lib/pusher-client/channel.rb', line 38

def acknowledge_subscription(data)
  @subscribed = true
end

#bind(event_name, &callback) ⇒ Object


16
17
18
19
20
21
# File 'lib/pusher-client/channel.rb', line 16

def bind(event_name, &callback)
  PusherClient.logger.debug "Binding #{event_name} to #{name}"
  @callbacks[event_name] = callbacks[event_name] || []
  @callbacks[event_name] << callback
  return self
end

#dispatch(event_name, data) ⇒ Object


27
28
29
30
31
32
33
34
35
36
# File 'lib/pusher-client/channel.rb', line 27

def dispatch(event_name, data)
  logger.debug("Dispatching #{global ? 'global ' : ''}callbacks for #{event_name}")
  if @callbacks[event_name]
    @callbacks[event_name].each do |callback|
      callback.call(data)
    end
  else
    logger.debug "No #{global ? 'global ' : ''}callbacks to dispatch for #{event_name}"
  end
end

#dispatch_with_all(event_name, data) ⇒ Object


23
24
25
# File 'lib/pusher-client/channel.rb', line 23

def dispatch_with_all(event_name, data)
  dispatch(event_name, data)
end