aboutsummaryrefslogtreecommitdiffstats
path: root/lib/action_cable/server/base.rb
blob: 3d1d9e71ffb3d19fdf3e46d84759e32b4e1b602e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
module ActionCable
  module Server
    class Base
      include ActionCable::Server::Broadcasting
      include ActionCable::Server::Connections

      cattr_accessor(:config, instance_accessor: true) { ActionCable::Server::Configuration.new }
      
      def self.logger; config.logger; end
      delegate :logger, to: :config

      def initialize
      end

      def call(env)
        config.connection_class.new(self, env).process
      end

      def worker_pool
        @worker_pool ||= ActionCable::Server::Worker.pool(size: config.worker_pool_size)
      end

      def channel_classes
        @channel_classes ||= begin
          config.channel_paths.each { |channel_path| require channel_path }
          config.channel_class_names.collect { |name| name.constantize }
        end
      end

      def remote_connections
        @remote_connections ||= RemoteConnections.new(self)
      end

      def pubsub
        @pubsub ||= redis.pubsub
      end

      def redis
        @redis ||= EM::Hiredis.connect(config.redis[:url]).tap do |redis|
          redis.on(:reconnect_failed) do
            logger.info "[ActionCable] Redis reconnect failed."
            # logger.info "[ActionCable] Redis reconnected. Closing all the open connections."
            # @connections.map &:close
          end            
        end
      end

      def connection_identifiers
        config.connection_class.identifiers
      end
    end
  end
end