Sha256: c4fa7f47b3a4fe93363ce730ff259795a3a62b141de98cb20865a366f3a980bf

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true

require "stimulus_reflex/installer"

initializer = StimulusReflex::Installer.action_cable_initializer_working_path.read

if StimulusReflex::Installer.gemfile.match?(/gem ['"]permessage_deflate['"]/)
  say "⏩ permessage_deflate already present in Gemfile. Skipping."
else
  StimulusReflex::Installer.add_gem "permessage_deflate@>= 0.1"
end

# add permessage_deflate config to Action Cable initializer
if initializer.exclude? "PermessageDeflate.configure"
  StimulusReflex::Installer.create_or_append(StimulusReflex::Installer.action_cable_initializer_working_path, verbose: false) do
    <<~RUBY
      module ActionCable
        module Connection
          class ClientSocket
            alias_method :old_initialize, :initialize
            def initialize(env, event_target, event_loop, protocols)
              old_initialize(env, event_target, event_loop, protocols)
              @driver.add_extension(
                PermessageDeflate.configure(
                  level: Zlib::BEST_COMPRESSION,
                  max_window_bits: 13
                )
              )
            end
          end
        end
      end
    RUBY
  end

  say "✅ Action Cable initializer patched to deflate websocket traffic"
else
  say "⏩ Action Cable initializer is already patched to deflate websocket traffic. Skipping."
end

StimulusReflex::Installer.complete_step :compression

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
stimulus_reflex-3.5.3 lib/install/compression.rb