diff --git a/lib/action_cable/broadcaster.rb b/lib/action_cable/broadcaster.rb deleted file mode 100644 index 7d8cc90970..0000000000 --- a/lib/action_cable/broadcaster.rb +++ /dev/null @@ -1,17 +0,0 @@ -module ActionCable - class Broadcaster - attr_reader :server, :channel, :redis - delegate :logger, to: :server - - def initialize(server, channel) - @server = server - @channel = channel - @redis = @server.threaded_redis - end - - def broadcast(message) - logger.info "[ActionCable] Broadcasting to #{channel}: #{message}" - redis.publish channel, message.to_json - end - end -end diff --git a/lib/action_cable/server.rb b/lib/action_cable/server.rb index e17cf872e0..fa7bad4e32 100644 --- a/lib/action_cable/server.rb +++ b/lib/action_cable/server.rb @@ -1,6 +1,7 @@ module ActionCable module Server autoload :Base, 'action_cable/server/base' + autoload :Broadcasting, 'action_cable/server/broadcasting' autoload :Worker, 'action_cable/server/worker' end end diff --git a/lib/action_cable/server/base.rb b/lib/action_cable/server/base.rb index 6abec92dc1..6dcd282e4a 100644 --- a/lib/action_cable/server/base.rb +++ b/lib/action_cable/server/base.rb @@ -1,6 +1,8 @@ module ActionCable module Server class Base + include ActionCable::Server::Broadcasting + cattr_accessor(:logger, instance_reader: true) { Rails.logger } attr_accessor :registered_channels, :redis_config, :log_tags @@ -49,14 +51,6 @@ module ActionCable @remote_connections ||= RemoteConnections.new(self) end - def broadcaster_for(channel) - Broadcaster.new(self, channel) - end - - def broadcast(channel, message) - broadcaster_for(channel).broadcast(message) - end - def connection_identifiers @connection_class.identifiers end diff --git a/lib/action_cable/server/broadcasting.rb b/lib/action_cable/server/broadcasting.rb new file mode 100644 index 0000000000..682064571f --- /dev/null +++ b/lib/action_cable/server/broadcasting.rb @@ -0,0 +1,28 @@ +module ActionCable + module Server + module Broadcasting + def broadcaster_for(channel) + Broadcaster.new(self, channel) + end + + def broadcast(channel, message) + broadcaster_for(channel).broadcast(message) + end + + class Broadcaster + attr_reader :server, :channel, :redis + delegate :logger, to: :server + + def initialize(server, channel) + @server, @channel = server, channel + @redis = @server.threaded_redis + end + + def broadcast(message) + logger.info "[ActionCable] Broadcasting to #{channel}: #{message}" + redis.publish channel, message.to_json + end + end + end + end +end \ No newline at end of file