Ask A Question

Notifications

You’re not receiving notifications from this thread.

Send ActionCable broadcast from javascript

Chris Valentine asked in Javascript

In the tutorials here, I've seen an ActionCable broadcast be initiated by a chat message save. The broadcast is sent via a relay to a background job and then the chatmessages on the clients update when that broadcast job is run.

In my app, i have a host that runs a chatroom. I'd like the host to click a button and have that button run a javascript command to tell ActionCable to send the "disable-chat" command to the clients that are in the host's chat. I know how the clients receive that message thru ActionCable but how can the host send that request. There is no database save going on and no form to submit.

I imagine in javascript on the hosts page there is something like . chat_consumer.send('chatroom.disable'); or something like that, without doing a form that submits the requests. How do I go about this? Thx

Reply

i realize this was just a $.ajax() call so it was taken care of. Thanks.

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 82,464+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.