You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to send notification via web socket using custom channel cable and custom stream.
I need to normalize all notifications stream ids and use my single channel instead of "Noticed::NotificationChannel".
When i run the code below, I expect to receive comment notification from web socket the same way i'm sending data via UserChannel. But it is not working with custom channel and same steam id. (Note : The code is working fine when i remove custom channel and i subscribe to Noticed::NotificationChannel)
class CommentNotification < Noticed::Base
deliver_by :action_cable, channel: "UserChannel", stream: :custom_stream, format: :action_cable_data
def custom_stream
UserChannel.stream_id(recipient)
end
def action_cable_data
{ user_id: recipient, info: "test" }
end
...
UserChannel Code
class UserChannel < ApplicationCable::Channel
rescue_from 'MyError', with: :deliver_error_message
class << self
def stream_id(user)
# stream_for current_user
"user_#{user.email}"
end
end
# Called when the consumer has successfully
# become a subscriber to this channel.
def subscribed
stream_from UserChannel.stream_id(current_user)
# Just for test
ActionCable.server.broadcast("user_#{User.first.email}", { title: "foo", body: "bar" })
end
def deliver_error_message(e)
# error throw
end
end
I was able to test and receive data from UserChannel using this stream id "user_#{user.email}" by calling ActionCable.server.broadcast("user_#{User.first.email}", { title: "foo", body: "bar" }) (Just for test)
Action cable log
Javascript console
The text was updated successfully, but these errors were encountered:
Hello and thank you for your work.
Noticed version 1.6.0
ActionCable / Rails 7.0.4
I'm trying to send notification via web socket using custom channel cable and custom stream.
I need to normalize all notifications stream ids and use my single channel instead of "Noticed::NotificationChannel".
When i run the code below, I expect to receive comment notification from web socket the same way i'm sending data via UserChannel. But it is not working with custom channel and same steam id. (Note : The code is working fine when i remove custom channel and i subscribe to Noticed::NotificationChannel)
CommentNotification Code
UserChannel Code
I was able to test and receive data from UserChannel using this stream id
"user_#{user.email}"
by callingActionCable.server.broadcast("user_#{User.first.email}", { title: "foo", body: "bar" })
(Just for test)Action cable log
Javascript console
The text was updated successfully, but these errors were encountered: