Sha256: aa18c4324e72d2b10f549cc9f582c30b8137e1825125bc540dd3d6729e364355

Contents?: true

Size: 974 Bytes

Versions: 6

Compression:

Stored size: 974 Bytes

Contents

# frozen_string_literal: true

require "action_cable"

ActionCable::Channel::Base.prepend(Module.new do
  # Whispering support
  def whispers_to(broadcasting)
    return super unless anycabled?

    connection.anycable_socket.whisper identifier, broadcasting
  end

  # Unsubscribing relies on the channel state (which is not persistent in AnyCable).
  # Thus, we pretend that the stream is registered to make Action Cable do its unsubscribing job.
  def stop_stream_from(broadcasting)
    streams[broadcasting] = true if anycabled?
    super
  end

  # For AnyCable, unsubscribing from all streams is a separate operation,
  # so we use a special constant to indicate it.
  def stop_all_streams
    if anycabled?
      streams.clear
      streams[AnyCable::Rails::Server::PubSub::ALL_STREAMS] = true
    end
    super
  end

  # Make rejected status accessible from outside
  def rejected? = subscription_rejected?

  private

  def anycabled? = connection.anycabled?
end)

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
anycable-rails-core-1.6.0.rc.3 lib/anycable/rails/next/action_cable_ext/channel.rb
anycable-rails-core-1.6.0.rc.2 lib/anycable/rails/next/action_cable_ext/channel.rb
anycable-rails-core-1.5.6 lib/anycable/rails/next/action_cable_ext/channel.rb
anycable-rails-core-1.6.0.rc.1 lib/anycable/rails/next/action_cable_ext/channel.rb
anycable-rails-core-1.5.5 lib/anycable/rails/next/action_cable_ext/channel.rb
anycable-rails-core-1.5.4 lib/anycable/rails/next/action_cable_ext/channel.rb