Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom channel and custom stream not working #259

Closed
houssemFat opened this issue Dec 4, 2022 · 1 comment
Closed

Custom channel and custom stream not working #259

houssemFat opened this issue Dec 4, 2022 · 1 comment

Comments

@houssemFat
Copy link

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)

notification = CommentNotification.with(comment: "hi")
notification.deliver(current_user)

CommentNotification Code

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

Capture d’écran 2022-12-04 à 23 11 30

Javascript console

Capture d’écran 2022-12-04 à 23 09 49

@OrestF
Copy link

OrestF commented Aug 14, 2023

This issue is relevant for me too!

Repository owner locked and limited conversation to collaborators Oct 31, 2023
@Kentasmic Kentasmic converted this issue into discussion #328 Oct 31, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants