Rename broadcast to transmit for the connection/channel->subscriber communication

Disambiguate it from the broadcast to channel method used by the
broadcaster (which actually has several listeners, whereas a
connection/channel instance only ever has one listener – hence not much
of a BROADcast).
上级 404867d3
......@@ -79,10 +79,10 @@ def disconnect
end
def broadcast(data)
def transmit(data, via: nil)
if authorized?
logger.info "#{channel_name} broadcasting #{data.inspect}"
connection.broadcast({ identifier: @channel_identifier, message: data }.to_json)
logger.info "#{channel_name} transmitting #{data.inspect} #{via}"
connection.transmit({ identifier: @channel_identifier, message: data }.to_json)
else
unauthorized
end
......
......@@ -29,8 +29,7 @@ def unsubscribe_from_all_channels
protected
def default_subscription_callback(channel)
-> (message) do
logger.info "Received a message over the redis channel: #{channel}"
broadcast ActiveSupport::JSON.decode(message)
transmit ActiveSupport::JSON.decode(message), via: "incoming action from #{channel}"
end
end
end
......
......@@ -34,8 +34,8 @@ def process
@websocket = Faye::WebSocket.new(@env)
@websocket.on(:open) do |event|
broadcast_ping_timestamp
@ping_timer = EventMachine.add_periodic_timer(PING_INTERVAL) { broadcast_ping_timestamp }
transmit_ping_timestamp
@ping_timer = EventMachine.add_periodic_timer(PING_INTERVAL) { transmit_ping_timestamp }
worker_pool.async.invoke(self, :initialize_connection)
end
......@@ -87,7 +87,7 @@ def cleanup_subscriptions
end
end
def broadcast(data)
def transmit(data)
@websocket.send data
end
......@@ -127,8 +127,8 @@ def on_connection_closed
disconnect if respond_to?(:disconnect)
end
def broadcast_ping_timestamp
broadcast({ identifier: '_ping', message: Time.now.to_i }.to_json)
def transmit_ping_timestamp
transmit({ identifier: '_ping', message: Time.now.to_i }.to_json)
end
def subscribe_channel(data)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册