How to detect when turbo stream connection is established?

In my Rails view I call turbo_stream_from view helper to establish turbo stream web socket connection:

<%= turbo_stream_from :my_broadcast %>

Is there a way for know when the web socket connection was established using JavaScript in the browser? Does @hotwired/turbo-rails JavaScript library allows to submit a callback that will be called when the WebSocket is established?

Thanks!

1 Like

Found a solution, the connected attribute is added to the <turbo-cable-stream-source> HTML element when connection is established.

See How to detect when Turbo Stream broadcast is established? · Issue #434 · hotwired/turbo-rails · GitHub and How to detect when Turbo Stream broadcast is established? · Issue #434 · hotwired/turbo-rails · GitHub

1 Like