Sha256: de9a893ebcd6a262d1b84451d77031639558324122aaa3a96aba36675a048495

Contents?: true

Size: 1.26 KB

Versions: 146

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true

module ActionCable
  module Server
    # Collection class for all the connections that have been established on this specific server. Remember, usually you'll run many Action Cable servers, so
    # you can't use this collection as a full list of all of the connections established against your application. Instead, use RemoteConnections for that.
    module Connections # :nodoc:
      BEAT_INTERVAL = 3

      def connections
        @connections ||= []
      end

      def add_connection(connection)
        connections << connection
      end

      def remove_connection(connection)
        connections.delete connection
      end

      # WebSocket connection implementations differ on when they'll mark a connection as stale. We basically never want a connection to go stale, as you
      # then can't rely on being able to communicate with the connection. To solve this, a 3 second heartbeat runs on all connections. If the beat fails, we automatically
      # disconnect.
      def setup_heartbeat_timer
        @heartbeat_timer ||= event_loop.timer(BEAT_INTERVAL) do
          event_loop.post { connections.map(&:beat) }
        end
      end

      def open_connections_statistics
        connections.map(&:statistics)
      end
    end
  end
end

Version data entries

146 entries across 142 versions & 11 rubygems

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