Sha256: 2810bc40fe2174e525d1ba49ffea168f764aa3472645a5886866aba92538e895
Contents?: true
Size: 1.48 KB
Versions: 7
Compression:
Stored size: 1.48 KB
Contents
import ConnectionAdapter from './ConnectionAdapter' declare module ActionCable { function createConsumer(): Cable interface Cable { subscriptions: Subscriptions } interface CreateMixin { connected: () => void disconnected: () => void received: (obj: any) => void } interface ChannelNameWithParams { channel: string [key: string]: any } interface Subscriptions { create(channel: ChannelNameWithParams, obj: CreateMixin): Channel } interface Channel { unsubscribe(): void; perform(action: string, data: {}): void; send(data: any): boolean; } } export default class ActionCableAdapter implements ConnectionAdapter { connected: boolean _cable: ActionCable.Cable actionCableClass: typeof ActionCable constructor(actionCableClass: typeof ActionCable) { this.connected = true this.actionCableClass = actionCableClass 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 = this.actionCableClass.createConsumer() return this._cable.subscriptions.create( { channel: 'SyncChannel', key }, { received, disconnected, connected } ) } ondisconnect() {} onreconnect() {} }
Version data entries
7 entries across 7 versions & 1 rubygems