class StreamsChannel
Ruby on Rails 1.3.3
Since v1.3.3 Last seen in v2.0.23The streams channel delivers all the turbo-stream actions created (primarily) through Turbo::Broadcastable. A subscription to this channel is made for each individual stream that one wishes to listen for updates to. The subscription relies on being passed a signed_stream_name parameter generated by turning a set of streamables into signed stream name using Turbo::Streams::StreamName#signed_stream_name. This is automatically done using the view helper Turbo::StreamsHelper#turbo_stream_from(*streamables). If the signed stream name cannot be verified, the subscription is rejected.
In case if custom behavior is desired, one can create their own channel and re-use some of the primitives from helper modules like Turbo::Streams::StreamName:
class CustomChannel < ActionCable::Channel::Base
extend Turbo::Streams::Broadcasts, Turbo::Streams::StreamName
include Turbo::Streams::StreamName::ClassMethods
def subscribed
if (stream_name = verified_stream_name_from_params).present? &&
subscription_allowed?
stream_from stream_name
else
reject
end
end
def subscription_allowed?
# ...
end
end
This channel can be connected to a web page using <tt>:channel</tt> option in
<tt>turbo_stream_from</tt> helper:
<%= turbo_stream_from 'room', channel: CustomChannel %>