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.6.23 pg_layout/app/javascript/channels/consumer.js
pg_rails-7.6.22 pg_layout/app/javascript/channels/consumer.js
pg_rails-7.6.22.pre.3 pg_layout/app/javascript/channels/consumer.js
pg_rails-7.6.22.pre.2 pg_layout/app/javascript/channels/consumer.js
pg_rails-7.6.22.pre.1 pg_layout/app/javascript/channels/consumer.js
pg_rails-7.6.21 pg_layout/app/javascript/channels/consumer.js
pg_rails-7.6.21.pre.11 pg_layout/app/javascript/channels/consumer.js
pg_rails-7.6.21.pre.10 pg_layout/app/javascript/channels/consumer.js
pg_rails-7.6.21.pre.9 pg_layout/app/javascript/channels/consumer.js
pg_rails-7.6.21.pre.8 pg_layout/app/javascript/channels/consumer.js
pg_rails-7.6.21.pre.7 pg_layout/app/javascript/channels/consumer.js
pg_rails-7.6.21.pre.6 pg_layout/app/javascript/channels/consumer.js
pg_rails-7.6.21.pre.5 pg_layout/app/javascript/channels/consumer.js
pg_rails-7.6.21.pre.4 pg_layout/app/javascript/channels/consumer.js
pg_rails-7.6.21.pre.3 pg_layout/app/javascript/channels/consumer.js
pg_rails-7.6.21.pre.2 pg_layout/app/javascript/channels/consumer.js
pg_rails-7.6.21.pre.1 pg_layout/app/javascript/channels/consumer.js
pg_rails-7.6.20 pg_layout/app/javascript/channels/consumer.js
pg_rails-7.6.19 pg_layout/app/javascript/channels/consumer.js
pg_rails-7.6.18 pg_layout/app/javascript/channels/consumer.js