Lightning.Collaboration.Session (Lightning v2.14.5-pre1)

View Source

Manages individual user sessions for collaborative workflow editing.

A Session acts as a bridge between a parent process (typically a Phoenix channel) and a SharedDoc process that manages the Y.js CRDT document. Each user editing a workflow has their own Session process that handles:

  • User presence tracking via Lightning.Workflows.Presence
  • Bi-directional Y.js message routing between parent and SharedDoc
  • Connection management to existing SharedDoc processes via Registry lookup
  • Workflow document initialization with database data when needed
  • Cleanup when the parent process disconnects

Sessions are temporary processes that monitor their parent and terminate when the parent disconnects, ensuring proper cleanup of presence tracking and SharedDoc observers.

Summary

Types

start_opts()

@type start_opts() :: [
  workflow_id: String.t(),
  user: Lightning.Accounts.User.t(),
  parent_pid: pid()
]

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

get_doc(session_pid)

Get the current document.

initialize_workflow_document(doc, workflow_id)

lookup_shared_doc(workflow_id)

send_yjs_message(session_pid, chunk)

start_link(args, opt \\ [])

start_sync(session_pid, chunk)

stop(session_pid)

Start a new session for a workflow.

The session will be started as a child of the Collaboration.Supervisor.

Options

  • workflow_id - The id of the workflow to start the session for.
  • user - The user to start the session for.
  • parent_pid - The pid of the parent process. Defaults to the current process.

stop_shared_doc(session_pid)

update_doc(session_pid, fun)