Sha256: df8950069c9d6a6772ae4734baea36ca4b587d2abf7f2b076ad19a1d5b184d0c

Contents?: true

Size: 1.43 KB

Versions: 146

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true

module ActionCable
  module Connection
    # 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})"
            websocket.close
          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

146 entries across 142 versions & 11 rubygems

Version Path
actioncable-7.0.8.6 lib/action_cable/connection/internal_channel.rb
actioncable-6.1.7.10 lib/action_cable/connection/internal_channel.rb
actioncable-6.1.7.9 lib/action_cable/connection/internal_channel.rb
actioncable-7.0.8.5 lib/action_cable/connection/internal_channel.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/actioncable-7.0.8.4/lib/action_cable/connection/internal_channel.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/actioncable-7.0.5.1/lib/action_cable/connection/internal_channel.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/actioncable-7.0.5.1/lib/action_cable/connection/internal_channel.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/actioncable-7.0.5.1/lib/action_cable/connection/internal_channel.rb
actioncable-7.0.8.4 lib/action_cable/connection/internal_channel.rb
actioncable-6.1.7.8 lib/action_cable/connection/internal_channel.rb
actioncable-7.0.8.1 lib/action_cable/connection/internal_channel.rb
actioncable-6.1.7.7 lib/action_cable/connection/internal_channel.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/actioncable-7.0.3.1/lib/action_cable/connection/internal_channel.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/actioncable-7.0.2.3/lib/action_cable/connection/internal_channel.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/actioncable-6.1.6.1/lib/action_cable/connection/internal_channel.rb
actioncable-7.0.8 lib/action_cable/connection/internal_channel.rb
actioncable-7.0.7.2 lib/action_cable/connection/internal_channel.rb
actioncable-6.1.7.6 lib/action_cable/connection/internal_channel.rb
actioncable-7.0.7.1 lib/action_cable/connection/internal_channel.rb
actioncable-6.1.7.5 lib/action_cable/connection/internal_channel.rb