2016-10-01 57 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 
相關問題