Ruby on rails 如何向每个连接发送消息
我知道,在ActionCable中,ping的工作方式如下:Ruby on rails 如何向每个连接发送消息,ruby-on-rails,ruby,websocket,ruby-on-rails-5,actioncable,Ruby On Rails,Ruby,Websocket,Ruby On Rails 5,Actioncable,我知道,在ActionCable中,ping的工作方式如下: def beat transmit type: ActionCable::INTERNAL[:message_types][:ping], message: Time.now.to_i end 但是,当我尝试使用connect进行传输时,只有一个connecton使用传输获取我的消息,为什么 def connect self.uuid = SecureRandom.uuid transmit({'title': 'pla
def beat
transmit type: ActionCable::INTERNAL[:message_types][:ping], message: Time.now.to_i
end
但是,当我尝试使用connect进行传输时,只有一个connecton使用传输
获取我的消息,为什么
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
也许只有一个订户?检查谁订阅了。@Sylar 3订阅者使用更多代码更新帖子,以便我可以复制。您的客户端代码在哪里?你到处都在订阅这条消息吗?@maxpleaner我正在使用SocketRocket从iOS订阅