Cauldron2D.Sessions (Cauldron2D v0.1.4)

Copy Markdown View Source

Who is logged in on the node, by whatever kind of client, told to whoever asks.

Cauldron2D.Sessions.track("alice", :terminal)
Cauldron2D.Sessions.list()
#=> [%{id: "alice", kind: :terminal, since: 1789718400, pid: #PID<0.312.0>}]
Cauldron2D.Sessions.subscribe()
receive do
  {:cauldron_sessions, :opened, session} -> ...
  {:cauldron_sessions, :closed, session} -> ...
end

A session is the calling process — a client on an ssh connection, a page in a browser — listed from track/2 until the process exits or tracks again. kind is whatever the client calls itself. A subscribed process hears every opening and closing until it unsubscribes or exits.

Summary

Functions

Returns a specification to start this module under a supervisor.

Every session on the node, oldest first.

Receive every opening and closing in the calling process.

List the calling process as a session of id, of this kind, until it exits.

Stop receiving them.

Types

session()

@type session() :: %{id: term(), kind: atom(), since: integer(), pid: pid()}

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

list()

@spec list() :: [session()]

Every session on the node, oldest first.

subscribe()

@spec subscribe() :: :ok

Receive every opening and closing in the calling process.

track(id, kind)

@spec track(term(), atom()) :: :ok

List the calling process as a session of id, of this kind, until it exits.

unsubscribe()

@spec unsubscribe() :: :ok

Stop receiving them.