Raxol.Demo.SessionManager (Raxol v2.6.0)

View Source

GenServer managing demo terminal sessions. Enforces session limits and handles automatic cleanup.

Summary

Functions

Returns a specification to start this module under a supervisor.

Creates a new session for the given IP address. Returns {:ok, session_id} or {:error, reason}.

Registers a session with a pre-generated session_id. Used when the LiveView creates the session_id before channel join. Returns {:ok, session_id} or {:error, reason}.

Removes a session.

Returns current session count.

Returns session count for an IP.

Starts the session manager.

Refreshes session timeout (called on activity).

Checks if a session exists and belongs to the given IP. Returns {:ok, session_id} or {:error, reason}.

Types

ip_address()

@type ip_address() :: String.t()

session_id()

@type session_id() :: String.t()

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

create_session(ip_address)

@spec create_session(ip_address()) :: {:ok, session_id()} | {:error, atom()}

Creates a new session for the given IP address. Returns {:ok, session_id} or {:error, reason}.

register_session(session_id, ip_address)

@spec register_session(session_id(), ip_address()) ::
  {:ok, session_id()} | {:error, atom()}

Registers a session with a pre-generated session_id. Used when the LiveView creates the session_id before channel join. Returns {:ok, session_id} or {:error, reason}.

remove_session(session_id)

@spec remove_session(session_id()) :: :ok

Removes a session.

session_count()

@spec session_count() :: non_neg_integer()

Returns current session count.

sessions_for_ip(ip_address)

@spec sessions_for_ip(ip_address()) :: non_neg_integer()

Returns session count for an IP.

start_link(opts \\ [])

Starts the session manager.

touch_session(session_id)

@spec touch_session(session_id()) :: :ok

Refreshes session timeout (called on activity).

validate_session(session_id, ip_address)

@spec validate_session(session_id(), ip_address()) ::
  {:ok, session_id()} | {:error, atom()}

Checks if a session exists and belongs to the given IP. Returns {:ok, session_id} or {:error, reason}.