Sha256: db022dd5b5e12b994487a7c541ce826f18c357d9e595f1917a6e831eadb1aa69

Contents?: true

Size: 871 Bytes

Versions: 2

Compression:

Stored size: 871 Bytes

Contents

import * as ActionCable from 'actioncable'
import ConnectionAdapter from './ConnectionAdapter'

export default class ActionCableAdapter implements ConnectionAdapter {
  connected: boolean
  _cable: ActionCable.Cable
  constructor() {
    this.connected = true
    this.subscribe(Math.random().toString(), () => {})
  }
  subscribe(key: string, received: (data: any) => void) {
    const disconnected = () => {
      if (!this.connected) return
      this.connected = false
      this.ondisconnect()
    }
    const connected = () => {
      if (this.connected) return
      this.connected = true
      this.onreconnect()
    }
    if (!this._cable) this._cable = ActionCable.createConsumer()
    return this._cable.subscriptions.create(
      { channel: 'SyncChannel', key },
      { received, disconnected, connected }
    )
  }
  ondisconnect() {}
  onreconnect() {}
}

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ar_sync-1.0.1 src/core/ActioncableAdapter.ts
ar_sync-1.0.0 src/core/ActioncableAdapter.ts