I want to use Action Cable (Rails 5) to create a chat app.
When the client signs in to the app, I send the message to subscribe for the channel. The channel will stream for connection based on current_user
's room_id
.
When the user sends a message it will be sent to all who subscribed for the channel
That 's normal flow of action cable.
Here is my channel:
class RoomChannel < ApplicationCable::Channel
def subscribed
current_user.chatrooms.each do |chatroom|
stream_from "room_#{chatroom.id}"
end
end
end
But I wonder when the client sends the message to the new one who is not in the room. The streaming was not created. How can the other receive the message and keep the conversation move on?