如何向每个连接发送消息
How to send a message to every single connection
我知道在 ActionCable 中,ping 是这样工作的:
def beat
transmit type: ActionCable::INTERNAL[:message_types][:ping], message: Time.now.to_i
end
但是当我尝试在连接上传输时,只有一个连接收到我的消息 transmit
为什么?
def connect
self.uuid = SecureRandom.uuid
transmit({'title': 'players_online', 'message': 'A new user has been subscribed'})
end
其实很简单:
ActionCable.server.connections.each do |connection|
connection.transmit({'title': 'players_online', 'message': ActionCable.server.connections.size})
end
我知道在 ActionCable 中,ping 是这样工作的:
def beat
transmit type: ActionCable::INTERNAL[:message_types][:ping], message: Time.now.to_i
end
但是当我尝试在连接上传输时,只有一个连接收到我的消息 transmit
为什么?
def connect
self.uuid = SecureRandom.uuid
transmit({'title': 'players_online', 'message': 'A new user has been subscribed'})
end
其实很简单:
ActionCable.server.connections.each do |connection|
connection.transmit({'title': 'players_online', 'message': ActionCable.server.connections.size})
end