Sha256: ef7a3780d8425e6c31ce005c289f44ed0b77ed3e61e2be71fd66b76715a87eca

Contents?: true

Size: 1.57 KB

Versions: 18

Compression:

Stored size: 1.57 KB

Contents

# frozen_string_literal: true

module ActionCable
  module Connection
    # = Action Cable \InternalChannel
    #
    # Makes it possible for the RemoteConnection to disconnect a specific connection.
    module InternalChannel
      extend ActiveSupport::Concern

      private
        def internal_channel
          "action_cable/#{connection_identifier}"
        end

        def subscribe_to_internal_channel
          if connection_identifier.present?
            callback = -> (message) { process_internal_message decode(message) }
            @_internal_subscriptions ||= []
            @_internal_subscriptions << [ internal_channel, callback ]

            server.event_loop.post { pubsub.subscribe(internal_channel, callback) }
            logger.info "Registered connection (#{connection_identifier})"
          end
        end

        def unsubscribe_from_internal_channel
          if @_internal_subscriptions.present?
            @_internal_subscriptions.each { |channel, callback| server.event_loop.post { pubsub.unsubscribe(channel, callback) } }
          end
        end

        def process_internal_message(message)
          case message["type"]
          when "disconnect"
            logger.info "Removing connection (#{connection_identifier})"
            close(reason: ActionCable::INTERNAL[:disconnect_reasons][:remote], reconnect: message.fetch("reconnect", true))
          end
        rescue Exception => e
          logger.error "There was an exception - #{e.class}(#{e.message})"
          logger.error e.backtrace.join("\n")

          close
        end
    end
  end
end

Version data entries

18 entries across 18 versions & 4 rubygems

Version Path
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/actioncable-7.1.3.4/lib/action_cable/connection/internal_channel.rb
actioncable-7.1.5.1 lib/action_cable/connection/internal_channel.rb
actioncable-7.1.5 lib/action_cable/connection/internal_channel.rb
actioncable-7.1.4.2 lib/action_cable/connection/internal_channel.rb
actioncable-7.1.4.1 lib/action_cable/connection/internal_channel.rb
actioncable-7.1.4 lib/action_cable/connection/internal_channel.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/actioncable-7.1.3.4/lib/action_cable/connection/internal_channel.rb
tinymce-rails-7.1.2 vendor/bundle/ruby/3.3.0/gems/actioncable-7.1.3.4/lib/action_cable/connection/internal_channel.rb
actioncable-7.1.3.4 lib/action_cable/connection/internal_channel.rb
actioncable-7.1.3.2 lib/action_cable/connection/internal_channel.rb
actioncable-7.1.3.1 lib/action_cable/connection/internal_channel.rb
actioncable-7.1.3 lib/action_cable/connection/internal_channel.rb
actioncable-7.1.2 lib/action_cable/connection/internal_channel.rb
actioncable-7.1.1 lib/action_cable/connection/internal_channel.rb
actioncable-7.1.0 lib/action_cable/connection/internal_channel.rb
actioncable-7.1.0.rc2 lib/action_cable/connection/internal_channel.rb
actioncable-7.1.0.rc1 lib/action_cable/connection/internal_channel.rb
actioncable-7.1.0.beta1 lib/action_cable/connection/internal_channel.rb