Sha256: 9d02de4259bc07e7f0cfce65e128b914343c6ba92bcba6142b1a1aedcda74658

Contents?: true

Size: 1.23 KB

Versions: 19

Compression:

Stored size: 1.23 KB

Contents

require "action_cable/engine"
require_relative "./connection"
require_relative "./reload_channel"

module Lookbook
  class Cable
    attr_reader :engine_mount_path, :server, :logger

    def initialize(engine_mount_path, logger: Lookbook.logger)
      @engine_mount_path = engine_mount_path
      @logger = logger

      logger.info "Initializing websocket"

      if Gem::Version.new(Rails.version) >= Gem::Version.new(6.0)
        @server = ActionCable::Server::Base.new config: cable_config
      else
        @server = ActionCable::Server::Base.new
        @server.config = cable_config
      end
    end

    def broadcast(message, payload = nil)
      logger.debug message.to_s
      server.broadcast(message.to_s, payload.to_h)
    end

    def mount_path
      "/cable"
    end

    def full_mount_path
      "#{engine_mount_path}/#{mount_path}".gsub("//", "/")
    end

    def mountable?
      true
    end

    alias_method :mounted?, :mountable?

    protected

    def cable_config
      cable = ActionCable::Server::Configuration.new
      cable.cable = {adapter: "async"}.with_indifferent_access
      cable.mount_path = nil
      cable.connection_class = -> { Lookbook::Connection }
      cable.logger = logger
      cable
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
lookbook-2.0.5 lib/lookbook/cable/cable.rb
lookbook-2.0.4 lib/lookbook/cable/cable.rb
lookbook-2.0.3 lib/lookbook/cable/cable.rb
lookbook-2.0.2 lib/lookbook/cable/cable.rb
lookbook-2.0.1 lib/lookbook/cable/cable.rb
lookbook-2.0.0 lib/lookbook/cable/cable.rb
lookbook-2.0.0.rc.3 lib/lookbook/cable/cable.rb
lookbook-2.0.0.rc.2 lib/lookbook/cable/cable.rb
lookbook-2.0.0.rc.1 lib/lookbook/cable/cable.rb
lookbook-2.0.0.beta.9 lib/lookbook/cable/cable.rb
lookbook-2.0.0.beta.8 lib/lookbook/cable/cable.rb
lookbook-2.0.0.beta.7 lib/lookbook/cable/cable.rb
lookbook-2.0.0.beta.6 lib/lookbook/cable/cable.rb
lookbook-2.0.0.beta.5 lib/lookbook/cable/cable.rb
lookbook-2.0.0.beta.4 lib/lookbook/cable/cable.rb
lookbook-2.0.0.beta.3 lib/lookbook/cable/cable.rb
lookbook-2.0.0.beta.2 lib/lookbook/cable/cable.rb
lookbook-2.0.0.beta.1 lib/lookbook/cable/cable.rb
lookbook-2.0.0.beta.0 lib/lookbook/cable/cable.rb