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

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
actionCable.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?