Class: ApplicationCable::Connection

Inherits:
ActionCable::Connection::Base
  • Object
show all
Defined in:
app/channels/application_cable/connection.rb

Overview

Action Cable connection for real-time WebSocket features.

Currently used for:

  • Turbo Streams in CRM (retailer probe updates, sibling retailers tab)

Authentication:

  • CRM: Requires authenticated employee account (via Warden/Devise)
  • WWW: Not currently supported (connections rejected)

Future WWW Implementation (Option 2 - Lazy Connection):
When implementing real-time features for WWW (e.g., chat system):

  1. Don't auto-connect - wait until after globals.json establishes session
  2. Add visitor-based identification for anonymous users:
    identified_by :current_account, :current_visitor
  3. In primeval.js, create cable connection after globals.json:
    if (data.csrf) { window.App.cable = createConsumer('/cable') }
  4. Consider signed streams (Turbo 8+) for anonymous subscriptions

Action Cable base connection.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#wardenWarden::Proxy (readonly)

Returns the Warden proxy for the connecting request.

Returns:

  • (Warden::Proxy)

    the Warden proxy for the connecting request



32
33
34
# File 'app/channels/application_cable/connection.rb', line 32

def warden
  @warden
end

Instance Method Details

#connectvoid

This method returns an undefined value.

Authenticates the WebSocket connection.

Rejects any connection that is not from the CRM subdomain with an
authenticated employee account, then identifies the connection by the
Warden user and stores the Warden proxy.



41
42
43
44
45
46
47
# File 'app/channels/application_cable/connection.rb', line 41

def connect
  # Only allow connections from CRM subdomain with authenticated users
  reject_unauthorized_connection unless crm_subdomain? && authenticated_user?

  self. = env['warden'].user
  @warden = env['warden']
end