blob: b0e51b8ba82458181f4c7eb5c5b4b509720ffc40 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
module ActionCable
module Server
module Broadcasting
def broadcast(broadcasting, message)
broadcaster_for(broadcasting).broadcast(message)
end
def broadcast_without_logging(broadcasting, message)
broadcaster_for(broadcasting).broadcast_without_logging(message)
end
def broadcaster_for(broadcasting)
Broadcaster.new(self, broadcasting)
end
def broadcasting_redis
@broadcasting_redis ||= Redis.new(redis_config)
end
private
class Broadcaster
attr_reader :server, :broadcasting
def initialize(server, broadcasting)
@server, @broadcasting = server, broadcasting
end
def broadcast(message)
server.logger.info "[ActionCable] Broadcasting to #{broadcasting}: #{message}"
broadcast_without_logging(message)
end
def broadcast_without_logging(message)
server.broadcasting_redis.publish broadcasting, message.to_json
end
end
end
end
end
|