1

Is there a way to use a pure WebSocket library (browser or whatever) to connect to a channel from action cable in Rails ?

Am I tied to libs like: https://github.com/tomchinery/action-cable-node https://www.npmjs.com/package/actioncable-js or https://www.npmjs.com/package/actioncable

?

Marco Noronha
  • 115
  • 1
  • 9
  • 31

2 Answers2

1

Yes, you can. ActionCable is the official compiled javascript of the coffee support provided by rails - npmified version through sprockets.

All you have to do is install it, require and

var ActionCable = require('actioncable')
var cable = ActionCable.createConsumer('wss://mydomain.com/cable')

     cable.subscriptions.create({ channel: 'ChatChannel' }, {
       received: (data) => {
         console.log(data);
       }
     });
Gaudam Thiyagarajan
  • 1,022
  • 9
  • 24
0

I'm facing the same issue. I think you can find a good example here, but I still haven't tested it: Consuming Rails 5 Action Cable.

I think is possible to consume Action Cable endpoint outside from the coffee / Rails frontend framewrok, it's just an hack to turn it working.

If you have better resources, feel free to share.

Marco Sanfilippo
  • 293
  • 3
  • 19