2016-10-01 56 views
1

我知道,在ActionCable平以这种方式工作:如何将消息发送到每一个连接

def beat 
    transmit type: ActionCable::INTERNAL[:message_types][:ping], message: Time.now.to_i 
end 

但是当我尝试对连接传输,只有一个connecton得到我的消息transmit为什么?

def connect 
    self.uuid = SecureRandom.uuid 
    transmit({'title': 'players_online', 'message': 'A new user has been subscribed'}) 
end 
+0

也许只有一个用户?检查谁订阅。 – Sylar

+0

@Sylar 3订阅者 – Viktor

+0

用更多代码更新帖子,以便我可以复制。 – Sylar

回答

1

其实很简单:

ActionCable.server.connections.each do |connection| 
    connection.transmit({'title': 'players_online', 'message': ActionCable.server.connections.size}) 
end 
相关问题