diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2015-06-20 17:45:30 +0200 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2015-06-20 17:45:30 +0200 |
commit | dd77dd3868b6ea9942dc1340cba4491c2f1bc750 (patch) | |
tree | 7416d51224b1dd67bf9899da4b054768cbdce2aa /lib/action_cable/channel | |
parent | 7c1becfc1a0ebeb5a1fd840afd89af26b3a6f02d (diff) | |
parent | 082c6317f0b680f4bcd3b1643e6481bed4606139 (diff) | |
download | rails-dd77dd3868b6ea9942dc1340cba4491c2f1bc750.tar.gz rails-dd77dd3868b6ea9942dc1340cba4491c2f1bc750.tar.bz2 rails-dd77dd3868b6ea9942dc1340cba4491c2f1bc750.zip |
Merge branch 'master' of github.com:basecamp/action_cable
Diffstat (limited to 'lib/action_cable/channel')
-rw-r--r-- | lib/action_cable/channel/base.rb | 17 | ||||
-rw-r--r-- | lib/action_cable/channel/redis.rb | 7 |
2 files changed, 12 insertions, 12 deletions
diff --git a/lib/action_cable/channel/base.rb b/lib/action_cable/channel/base.rb index 6060ccf681..e6ca45ddcc 100644 --- a/lib/action_cable/channel/base.rb +++ b/lib/action_cable/channel/base.rb @@ -31,6 +31,12 @@ module ActionCable perform_connection end + def perform_connection + logger.info "#{channel_name} connecting" + connect + run_subscribe_callbacks + end + def perform_action(data) if authorized? action = extract_action(data) @@ -52,11 +58,6 @@ module ActionCable logger.info "#{channel_name} disconnected" end - def perform_connection - logger.info "#{channel_name} connecting" - connect - run_subscribe_callbacks - end protected # Override in subclasses @@ -78,10 +79,10 @@ module ActionCable end - def broadcast(data) + def transmit(data, via: nil) if authorized? - logger.info "#{channel_name} broadcasting #{data.inspect}" - connection.broadcast({ identifier: @channel_identifier, message: data }.to_json) + logger.info "#{channel_name} transmitting #{data.inspect}".tap { |m| m << " (via #{via})" if via } + connection.transmit({ identifier: @channel_identifier, message: data }.to_json) else unauthorized end diff --git a/lib/action_cable/channel/redis.rb b/lib/action_cable/channel/redis.rb index b5fc812919..0f77dc0418 100644 --- a/lib/action_cable/channel/redis.rb +++ b/lib/action_cable/channel/redis.rb @@ -14,14 +14,14 @@ module ActionCable @_redis_channels << [ redis_channel, callback ] pubsub.subscribe(redis_channel, &callback) - logger.info "#{channel_name} subscribed to incoming actions from #{redis_channel}" + logger.info "#{channel_name} subscribed to broadcasts from #{redis_channel}" end def unsubscribe_from_all_channels if @_redis_channels @_redis_channels.each do |redis_channel, callback| pubsub.unsubscribe_proc(redis_channel, callback) - logger.info "#{channel_name} unsubscribed from incoming actions #{redis_channel}" + logger.info "#{channel_name} unsubscribed to broadcasts from #{redis_channel}" end end end @@ -29,8 +29,7 @@ module ActionCable protected def default_subscription_callback(channel) -> (message) do - logger.info "Received a message over the redis channel: #{channel}" - broadcast ActiveSupport::JSON.decode(message) + transmit ActiveSupport::JSON.decode(message), via: "broadcast from #{channel}" end end end |