Module: LiteCable::AnyCable::Connection::InstanceMethods

Defined in:
lib/lite_cable/anycable.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#handle_channel_command(identifier, command, data) ⇒ Object

rubocop: disable Metrics/MethodLength



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/lite_cable/anycable.rb', line 38

def handle_channel_command(identifier, command, data)
  channel = subscriptions.add(identifier, false)
  case command
  when "subscribe"
    !subscriptions.send(:subscribe_channel, channel).nil?
  when "unsubscribe"
    subscriptions.remove(identifier)
    true
  when "message"
    subscriptions.perform_action identifier, data
    true
  else
    false
  end
rescue LiteCable::Connection::Subscriptions::Error,
       LiteCable::Channel::Error,
       LiteCable::Channel::Registry::Error => e
  log(:error, log_fmt("Connection command failed: #{e}"))
  close
  false
end

#initialize(socket, subscriptions: nil, **hargs) ⇒ Object



27
28
29
30
31
# File 'lib/lite_cable/anycable.rb', line 27

def initialize(socket, subscriptions: nil, **hargs)
  super(socket, **hargs)
  # Initialize channels if any
  subscriptions&.each { |id| @subscriptions.add(id, false) }
end

#requestObject



33
34
35
# File 'lib/lite_cable/anycable.rb', line 33

def request
  @request ||= Rack::Request.new(socket.env)
end