ActionCable::Server::Broadcasting

module ActionCable::Server::Broadcasting

Broadcasting is how other parts of your application can send messages to a channel's subscribers. As explained in Channel, most of the time, these broadcastings are streamed directly to the clients subscribed to the named broadcasting. Let's explain with a full-stack example:

class WebNotificationsChannel < ApplicationCable::Channel
  def subscribed
    stream_from "web_notifications_#{current_user.id}"
  end
end

# Somewhere in your app this is called, perhaps from a NewCommentJob:
ActionCable.server.broadcast \
  "web_notifications_1", { title: "New things!", body: "All that's fit for print" }

# Client-side CoffeeScript, which assumes you've already requested the right to send web notifications:
App.cable.subscriptions.create "WebNotificationsChan