module AnyCable::Rails

def compatible_adapter?(adapter)

def compatible_adapter?(adapter)
  ADAPTER_ALIASES.include?(adapter)
end

def deserialize(str, json: false)

If the resulting object is a Hash, make it indifferent
Ruby object.
Deserialize previously serialized value from string to
def deserialize(str, json: false)
  str.yield_self do |val|
    next val unless val.is_a?(String)
    gval = GlobalID::Locator.locate(val)
    return gval if gval
    next val unless json
    JSON.parse(val)
  end.yield_self do |val|
    next val.with_indifferent_access if val.is_a?(Hash)
    val
  end
end

def enabled?

def enabled?
  adapter = ::ActionCable.server.config.cable&.fetch("adapter", nil)
  compatible_adapter?(adapter)
end

def extend_adapter!(adapter)

def extend_adapter!(adapter)
  adapter.extend(Extension)
end

def fetch(identifier)

Find or add a subscription to the list
def fetch(identifier)
  add("identifier" => identifier) unless subscriptions[identifier]
  unless subscriptions[identifier]
    raise "Channel not found: #{ActiveSupport::JSON.decode(identifier).fetch("channel")}"
  end
  subscriptions[identifier]
end

def public_request

def public_request
  request
end

def rejected?

def rejected?
  subscription_rejected?
end

def send_welcome_message

Using public :send_welcome_message causes stack level too deep 🤷🏻‍♂️
def send_welcome_message
  transmit({
    type: ActionCable::INTERNAL[:message_types][:welcome],
    sid: env["anycable.sid"]
  }.compact)
end

def serialize(obj, json: false)

using GlobalID where possible or JSON (if json: true)
Serialize connection/channel state variable to string
def serialize(obj, json: false)
  obj.try(:to_gid_param) || (json ? obj.to_json : obj)
end