Vik.Authority (Vik v0.0.1-rc1)

View Source

Acts as the central authority for active @codemirror/collab sessions. Holds the authoritative master copy of every shard.

This enables real-time collaborative editing across multiple browser windows or devices.

Summary

Types

Session identifiers uniquely identify a collaborative session.

User identifiers uniquely identify every participant in a collaborative session.

Functions

Returns a specification to start this module under a supervisor.

Pulls any changes made since version.

Returns the session with all relevant data for constructing the current CodeMirror document.

Joins a collaboration session.

Pushes new changes starting from version.

Starts the authority.

Types

state()

@opaque state()

suid()

@type suid() :: Vik.slug()

Session identifiers uniquely identify a collaborative session.

For convience, Shard slugs double as valid session identifiers as well.

uid()

@type uid() :: term()

User identifiers uniquely identify every participant in a collaborative session.

version()

@type version() :: non_neg_integer()

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

fetch_changes(suid, version)

@spec fetch_changes(suid(), version()) :: [Vik.Authority.Update.t()] | :error

Pulls any changes made since version.

get_document(suid)

@spec get_document(suid()) :: Vik.Authority.Session.t() | :error

Returns the session with all relevant data for constructing the current CodeMirror document.

join(suid, uid)

@spec join(suid(), uid()) :: :ok | {:error, term()}

Joins a collaboration session.

If not initialised yet, this will create a new session. When empty, the collaboration session will automatically close.

push_changes(suid, version, updates)

@spec push_changes(suid(), version(), [Vik.Authority.Update.t()]) :: :ok | :rejected

Pushes new changes starting from version.

start_link(opts)

@spec start_link([]) :: :ok

Starts the authority.