完全に只の備忘録です。
chat_channel.rb
class ChatChannel < ApplicationCable::Channel def subscribed # stream_from "some_channel" stream_from 'chat:message' end def unsubscribed # Any cleanup needed when channel is unsubscribed end def put_message(data) ChatChannel.broadcast_to('message', data['message']) end end
chat.coffee
App.chat = App.cable.subscriptions.create "ChatChannel", connected: -> # Called when the subscription is ready for use on the server disconnected: -> # Called when the subscription has been terminated by the server received: (data) -> # Called when there's incoming data on the websocket for this channel console.log(data) put_message: (msg) -> @perform('put_message', { message: msg })