Sha256: e132b53f9e4cb251ab50f89356a1e8a25675fd29abf891f122cc46f699e41f5f

Contents?: true

Size: 1.04 KB

Versions: 3

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

require "action_cable"

ActionCable::Channel::Base.prepend(Module.new do
  def subscribe_to_channel
    super unless anycabled? && !@__anycable_subscribing__
  end

  def handle_subscribe
    @__anycable_subscribing__ = true
    subscribe_to_channel
  ensure
    @__anycable_subscribing__ = false
  end

  def start_periodic_timers
    super unless anycabled?
  end

  def stop_periodic_timers
    super unless anycabled?
  end

  def stream_from(broadcasting, _callback = nil, **)
    return super unless anycabled?

    connection.anycable_socket.subscribe identifier, broadcasting
  end

  def stop_stream_from(broadcasting)
    return super unless anycabled?

    connection.anycable_socket.unsubscribe identifier, broadcasting
  end

  def stop_all_streams
    return super unless anycabled?

    connection.anycable_socket.unsubscribe_from_all identifier
  end

  private

  def anycabled?
    # Use instance variable check here for testing compatibility
    connection.instance_variable_defined?(:@anycable_socket)
  end
end)

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
anycable-rails-1.3.5 lib/anycable/rails/action_cable_ext/channel.rb
anycable-rails-1.3.4 lib/anycable/rails/action_cable_ext/channel.rb
anycable-rails-1.3.3 lib/anycable/rails/action_cable_ext/channel.rb