1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/lib/action_cable/server/broadcasting.rb

36 lines
912 B
Ruby
Raw Normal View History

2015-06-28 14:24:50 -04:00
module ActionCable
module Server
module Broadcasting
def broadcast(channel, message)
broadcaster_for(channel).broadcast(message)
end
2015-06-28 14:24:50 -04:00
def broadcaster_for(channel)
Broadcaster.new(self, channel)
end
private
def redis_for_threads
@redis_for_threads ||= Redis.new(redis_config)
end
2015-06-28 14:24:50 -04:00
class Broadcaster
def initialize(server, channel)
@server, @channel = server, channel
end
2015-06-28 14:24:50 -04:00
def broadcast(message)
server.logger.info "[ActionCable] Broadcasting to #{channel}: #{message}"
broadcast_without_logging(message)
end
def broadcast_without_logging(message)
server.redis_for_threads.publish channel, message.to_json
end
2015-06-28 14:24:50 -04:00
private
attr_reader :server, :channel
2015-06-28 14:24:50 -04:00
end
end
end
end