I’m trying to send for front-end an especific information (how many registers I have, with a colunm null in database), with ActionCable, but I’m using Rails Api mode.
I’m generate a channel, and don’t create a authentication code (all can access), and create a method subscribed:
def subscribed
stream_from "password_channel"
end
Configured CORS and WebSocket access.
After I call the channel with this code in controller, to send a message for subscribed clients.
PasswordChannel.broadcast_to("password_channel", { title: "Oi" })
And create this js for consume informations in WebSockets
let webSocket = new WebSocket("ws://localhost:3000/cable")
webSocket.addEventListener("message", function(event) {
console.log(event)
})
This js return this object:
But this object don’t have the information { title: “Oi” }
Here it is github repository
Can anyone help me figure out what I’m doing wrong? =)