Channel
Base
include Callbacks
include PeriodicTimers
include Streams
include Naming
include Broadcastingaction_methodsStreams
最后更新于
include Callbacks
include PeriodicTimers
include Streams
include Naming
include Broadcastingaction_methods最后更新于
method_added
clear_action_methods!attr_reader :params, :connection, :identifier
delegate :logger, to: :connectionperform_action
unsubscribe_from_channel# 实际上由 connection 完成
transmit
# 以下两个由子类实现
subscribed
unsubscribed
# 以下几个相当于配置、问询
reject
defer_subscription_confirmation?
defer_subscription_confirmation!
subscription_confirmation_sent?
subscription_rejected?# pubsub.subscribe
stream_from
# pubsub.unsubscribe
stop_all_streams
# 封装 stream_from
stream_forclass CommentsChannel < ApplicationCable::Channel
def follow(data)
stream_from "comments_for_#{data['recording_id']}"
end
def unfollow
stop_all_streams
end
end
CommentsChannel.broadcast_to(@post, @comment)stream_from -> connection.transmit -> Connection#transmit -> WebSocket#transmit@websocket = ::WebSocket::Driver.websocket?(env) ? ClientSocket.new(env, event_target, stream_event_loop) : nil