Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect Action Cable connection status

I have a Vue app that connects to a Rails back-end and need to find out whether the connection is established or not.

In my app I do:

var app = new Vue({
    name: "Site",
    store,
    router,
    i18n,
    components: {},
    mixins: [],
    data: {
     cable: App.cable
    }
});

However cable.connection.disconnected is always true even when actually connected.

How can I reliably figure out (when needed) what the connection status is?

like image 702
Nick M Avatar asked Mar 26 '26 01:03

Nick M


1 Answers

Got it sorted out. In my components, when I need to find out cable status, I do

this.$root.cable.connection.isOpen()

If false I revert to HTTP.

Hope this helps someone later on.

like image 171
Nick M Avatar answered Mar 27 '26 13:03

Nick M



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!