Sha256: 0174ff50fe69e31e6d18869faf6841a3255d3b78e7b7817dc2eb9082d4d214da

Contents?: true

Size: 1.4 KB

Versions: 31

Compression:

Stored size: 1.4 KB

Contents

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

31 entries across 31 versions & 4 rubygems

Version Path
actioncable-5.0.7.2 lib/action_cable/connection/internal_channel.rb
actioncable-5.0.7.1 lib/action_cable/connection/internal_channel.rb
actioncable-5.0.7 lib/action_cable/connection/internal_channel.rb
actioncable-5.0.6 lib/action_cable/connection/internal_channel.rb
actioncable-5.0.6.rc1 lib/action_cable/connection/internal_channel.rb
actioncable-5.0.5 lib/action_cable/connection/internal_channel.rb
actioncable-5.0.5.rc2 lib/action_cable/connection/internal_channel.rb
actioncable-5.0.5.rc1 lib/action_cable/connection/internal_channel.rb
actioncable-5.0.4 lib/action_cable/connection/internal_channel.rb
actioncable-5.0.4.rc1 lib/action_cable/connection/internal_channel.rb
actioncable-5.0.3 lib/action_cable/connection/internal_channel.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/actioncable-5.0.2/lib/action_cable/connection/internal_channel.rb
actioncable-5.0.2 lib/action_cable/connection/internal_channel.rb
actioncable-5.0.2.rc1 lib/action_cable/connection/internal_channel.rb
autocompl-0.2.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/actioncable-5.0.1/lib/action_cable/connection/internal_channel.rb
autocompl-0.2.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/actioncable-5.0.1/lib/action_cable/connection/internal_channel.rb
autocompl-0.2.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/actioncable-5.0.1/lib/action_cable/connection/internal_channel.rb
autocompl-0.1.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/actioncable-5.0.1/lib/action_cable/connection/internal_channel.rb
autocompl-0.1.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/actioncable-5.0.1/lib/action_cable/connection/internal_channel.rb
autocompl-0.1.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/actioncable-5.0.1/lib/action_cable/connection/internal_channel.rb