0

I got this channel:

class TestChannel < ApplicationCable::Channel
  def subscribed
    stream_from 'test'

    ActionCable.server.broadcast 'Test', vehicles: Vehice.find_by id: 13
  end
end

I don't wanna broadcast to all subscriber when someone subscribe. I was thinking about changing confirm_subscription with adding 'message'.

Can someone tell me if it's even possible?

bonekost
  • 57
  • 9

1 Answers1

0

You can use transmit to send a message only to the current subscription. It's not really documented and somehow an anti pattern (because in a pub sub scenario, each message in a channel should reach every user), but it works fine. We use it for "responding" with error messages when the client sends an invalid request.

p0wl
  • 481
  • 5
  • 13