First of all very new to the ActionCable feature. I have been following the tutorial here: https://www.driftingruby.com/episodes/push-notifications-with-actioncable
Created a channel called web_notifications_channel and web_notifications_channel.rb:
class WebNotificationsChannel < ApplicationCable::Channel
def subscribed
stream_from "web_notifications_channel"
end
def unsubscribed
# Any cleanup needed when channel is unsubscribed
end
end
web_notifications_channel.js:
import consumer from "./consumer"
consumer.subscriptions.create("WebNotificationsChannel", {
connected() {
// Called when the subscription is ready for use on the server
},
disconnected() {
// Called when the subscription has been terminated by the server
},
received(data) {
// Called when there's incoming data on the websocket for this channel
console.log(`wtf`)
}
});
Nothing shows in console.
Changed the adapter settings to redis in cable.yml in order to request from console:
development:
adapter: redis
test:
adapter: test
production:
adapter: redis
url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
channel_prefix: community_rails_production
Running console command:
ActionCable.server.broadcast 'web_notifications_channel', 'You have visited the welcome page.'
I get response as:
Broadcasting to web_notifications_channel: "You have visited the welcome page."
=> 0
But my received method never gets called!! I am getting nuts here as cannot understand what is happening!! I have checked some similar questions but none of them helped me.
PS: I have added the gem for redis and started redis from my console.