[Feature][ActionCable] Public API to add websockets event listener in ActionCable JS

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

[Feature][ActionCable] Public API to add websockets event listener in ActionCable JS

Rafael Sales
Hey all,

I've been using ActionCable JS client and I need to listen to websockets events in order to handle the close event properly.

Here's an example of how I'm approaching this:

  const actionCable = ActionCable.createConsumer(url)

const originalCloseHandler = actionCable.connection.events.close
.connection.events.close = function(event) {

if (event.wasClean) {

Ideally we should be able to call actionCable.connection.addEventListener('close', handlerFunction) so that I don't have worry about calling the original close implementation.

You think a PR with this is welcome?

You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.