I have this channel.
class TestChannel < ApplicationCable::Channel
def subscribed
Rails.logger.info 'subscribed to test_channel yuppi'
stream_for current_use
transmit({ message: 'Welcome to the test channel!' })
end
def unsubscribed
# Any cleanup needed when channel is unsubscribed
end
Then I am trying to use this from a javascript application
const socket = new WebSocket('wss://petros-test/cable/?
token=1234567890&channel=TestChannel');
socket.onopen = function() {
document.getElementById('status').innerText = 'Connected to cable';
console.log('WebSocket connection established');
};
socket.onmessage = function(event) {
console.log('Message from server:', event.data);
};
The connection is been established but without invoking the correct channel, only a general connection is established and I am getting this on the logs
WebSocket connection established
(index):23 Message from server: {"type":"welcome"}
(index):23 Message from server: {"type":"ping","message":1741205085}