Sha256: cdbebcda1e4bcb7078b381d93c34f9e3894f3556bdf1c0082b42f072e477509d

Contents?: true

Size: 1.32 KB

Versions: 109

Compression:

Stored size: 1.32 KB

Contents

// Action Cable provides the framework to deal with WebSockets in Rails.
// You can generate new channels where WebSocket features live using the `bin/rails generate channel` command.

import { createConsumer } from '@anycable/web'
import Rollbar from 'rollbar'

let cableProtocol = document.head.querySelector('meta[name=actioncable-protocol]')
cableProtocol = cableProtocol && cableProtocol.content
cableProtocol = cableProtocol || 'actioncable-v1-ext-json'

const consumer = createConsumer({
  protocol: cableProtocol
})

const anycable = consumer.cable

if (anycable) {
  anycable.on('connect', ev => {
    document.head.dataset.cableConnected = true
    if (ev.reconnect) {
      console.log('Welcome back!')
    } else {
      console.log('Welcome!')
    }
  })

  anycable.on('disconnect', ev => {
    document.head.dataset.cableConnected = false
    // document.head.dataset.cableDisconnectedEvent = ev
    if (ev.reason) {
      if (ev.reason === 'transport_closed') {
        // no hago nada (?
      } else {
        Rollbar.warning(`Disconnected because: ${ev.reason}`)
      }
      console.log(`Disconnected because: ${ev.reason}`)
    } else {
      Rollbar.warning('Disconnected for unknown reason')
      console.log('Disconnected for unknown reason')
    }
  })
}

// Para desconectar
// anycable.disconnect()

export default consumer

Version data entries

109 entries across 109 versions & 1 rubygems

Version Path
pg_rails-7.5.5 pg_layout/app/javascript/channels/consumer.js
pg_rails-7.5.4 pg_layout/app/javascript/channels/consumer.js
pg_rails-7.5.3 pg_layout/app/javascript/channels/consumer.js
pg_rails-7.5.2 pg_layout/app/javascript/channels/consumer.js
pg_rails-7.5.1 pg_layout/app/javascript/channels/consumer.js
pg_rails-7.5.0 pg_layout/app/javascript/channels/consumer.js
pg_rails-7.4.3 pg_layout/app/javascript/channels/consumer.js
pg_rails-7.4.2 pg_layout/app/javascript/channels/consumer.js
pg_rails-7.4.1 pg_layout/app/javascript/channels/consumer.js
pg_rails-7.4.0 pg_layout/app/javascript/channels/consumer.js
pg_rails-7.3.5 pg_layout/app/javascript/channels/consumer.js
pg_rails-7.3.4 pg_layout/app/javascript/channels/consumer.js
pg_rails-7.3.3 pg_layout/app/javascript/channels/consumer.js
pg_rails-7.3.2 pg_layout/app/javascript/channels/consumer.js
pg_rails-7.3.1 pg_layout/app/javascript/channels/consumer.js
pg_rails-7.3.0 pg_layout/app/javascript/channels/consumer.js
pg_rails-7.2.3 pg_layout/app/javascript/channels/consumer.js
pg_rails-7.2.2 pg_layout/app/javascript/channels/consumer.js
pg_rails-7.2.1 pg_layout/app/javascript/channels/consumer.js
pg_rails-7.2.0 pg_layout/app/javascript/channels/consumer.js