aboutsummaryrefslogtreecommitdiffstats
path: root/lib/action_cable/channel/base.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2015-07-07 21:19:28 +0200
committerDavid Heinemeier Hansson <david@loudthinking.com>2015-07-07 21:19:28 +0200
commita01317ee9d5e42d847af8c3b1db6b2aa68b19343 (patch)
treeb58523289411d78833c2542d097e9a431193e929 /lib/action_cable/channel/base.rb
parent9b254fa61f3b815babd928b6fa28e096ee46acb1 (diff)
downloadrails-a01317ee9d5e42d847af8c3b1db6b2aa68b19343.tar.gz
rails-a01317ee9d5e42d847af8c3b1db6b2aa68b19343.tar.bz2
rails-a01317ee9d5e42d847af8c3b1db6b2aa68b19343.zip
Add documentation
Diffstat (limited to 'lib/action_cable/channel/base.rb')
-rw-r--r--lib/action_cable/channel/base.rb12
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/action_cable/channel/base.rb b/lib/action_cable/channel/base.rb
index 19a03f5ef6..ee22b29f4e 100644
--- a/lib/action_cable/channel/base.rb
+++ b/lib/action_cable/channel/base.rb
@@ -45,6 +45,9 @@ module ActionCable
subscribe_to_channel
end
+ # Extract the action name from the passed data and process it via the channel. The process will ensure
+ # that the action requested is a public method on the channel declared by the user (so not one of the callbacks
+ # like #subscribed).
def process_action(data)
if authorized?
action = extract_action(data)
@@ -76,16 +79,21 @@ module ActionCable
logger.error "#{channel_name}: Unauthorized access"
end
-
+ # Called once a consumer has become a subscriber of the channel. Usually the place to setup any streams
+ # you want this channel to be sending to the subscriber.
def subscribed
# Override in subclasses
end
+ # Called once a consumer has cut its cable connection. Can be used for cleaning up connections or marking
+ # people as offline or the like.
def unsubscribed
# Override in subclasses
end
-
+
+ # Transmit a hash of data to the subscriber. The hash will automatically be wrapped in a JSON envelope with
+ # the proper channel identifier marked as the recipient.
def transmit(data, via: nil)
if authorized?
logger.info "#{channel_name} transmitting #{data.inspect}".tap { |m| m << " (via #{via})" if via }