From 9415011b5fd192f1bafeaa9b6eacbb7921382a00 Mon Sep 17 00:00:00 2001 From: David Gay Date: Wed, 19 May 2021 22:53:38 -0400 Subject: Chat --- app/channels/chat_room_channel.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 app/channels/chat_room_channel.rb (limited to 'app/channels/chat_room_channel.rb') diff --git a/app/channels/chat_room_channel.rb b/app/channels/chat_room_channel.rb new file mode 100644 index 0000000..1e14b35 --- /dev/null +++ b/app/channels/chat_room_channel.rb @@ -0,0 +1,17 @@ +class ChatRoomChannel < ApplicationCable::Channel + def self.broadcast_chat_message(chat_message) + ActionCable.server.broadcast "chat_room_channel", + html: ApplicationController.render(partial: "chat_messages/message", + locals: { + chat: chat_message + }) + end + + def subscribed + stream_from "chat_room_channel" + end + + def unsubscribed + # Any cleanup needed when channel is unsubscribed + end +end -- cgit v1.2.3