How to Send Message to All Client Except Sender in Rails/Actioncable

how to reply message to the sender client with actioncable?

Use ActionCable::Connection::Base#transmit method

class BoardChannel < ApplicationCable::Channel
def subscribed
stream_from "board:#{params[:board]}"
end

def speak
result = do_something()
transmit(result) # send message to current connection (sender)
end
end

Send ActionCable to particular user

You should use a channel that's specific to that user. For example:

"notifications_channel_#{current_user.id}"

This is also documented in an example from the actioncable repo here: https://github.com/rails/rails/tree/master/actioncable#channel-example-2-receiving-new-web-notifications

What can be the reason of Unable to find subscription with identifier in Rails ActionCable?

It looks like it's related to this issue: https://github.com/rails/rails/issues/25381

Some kind of race conditions when Rails reply the subscription has been created but in fact it hasn't been done yet.

As a temporary solution adding a small timeout after establishing the subscription has solved the issue.

More investigation needs to be done, though.



Related Topics



Leave a reply



Submit