Sha256: d62a67b9bffcda319a5a8bca80c7adde7df3d498c547e11704ec715c9caa8312
Contents?: true
Size: 1.38 KB
Versions: 1
Compression:
Stored size: 1.38 KB
Contents
module PusherClient class Channel attr_accessor :global, :subscribed attr_reader :name, :callbacks, :global_callbacks def initialize(channel_name) @name = channel_name @global = false @callbacks = {} @global_callbacks = {} @subscribed = false end def bind(event_name, &callback) @callbacks[event_name] = callbacks[event_name] || [] @callbacks[event_name] << callback return self end def dispatch_with_all(event_name, data) dispatch(event_name, data) dispatch_global_callbacks(event_name, data) end def dispatch(event_name, data) PusherClient.logger.debug "Dispatching callbacks for #{event_name}" if @callbacks[event_name] @callbacks[event_name].each do |callback| callback.call(data) end else PusherClient.logger.debug "No callbacks to dispatch for #{event_name}" end end def dispatch_global_callbacks(event_name, data) if @global_callbacks[event_name] PusherClient.logger.debug "Dispatching global callbacks for #{event_name}" @global_callbacks[event_name].each do |callback| callback.call(data) end else PusherClient.logger.debug "No global callbacks to dispatch for #{event_name}" end end def acknowledge_subscription(data) @subscribed = true end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
pusher-client-nc-0.2.1 | lib/pusher-client/channel.rb |