Cauldron2D.Drafter.Chat (Cauldron2D.Drafter v0.1.3)

Copy Markdown View Source

Chat rooms for a served game: one process, any number of rooms, the last messages kept.

Cauldron2D.Drafter.Chat.ensure_started()
Cauldron2D.Drafter.Chat.join(:lobby)
Cauldron2D.Drafter.Chat.say(:lobby, "alice", "hello")

A process that joined a room receives {:chat, room, %{from: name, text: text, at: ms}} for every message said in it, and stops receiving when it leaves or exits. history/1 is the last 100 messages, oldest first.

Summary

Functions

Returns a specification to start this module under a supervisor.

Start the chat server registered under this module, or leave a running one be.

The last messages in room, oldest first.

Receive room's messages in the calling process.

Stop receiving room's messages.

Say text in room as from.

Types

message()

@type message() :: %{from: String.t(), text: String.t(), at: integer()}

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

ensure_started()

@spec ensure_started() :: :ok

Start the chat server registered under this module, or leave a running one be.

history(room)

@spec history(term()) :: [message()]

The last messages in room, oldest first.

join(room)

@spec join(term()) :: :ok

Receive room's messages in the calling process.

leave(room)

@spec leave(term()) :: :ok

Stop receiving room's messages.

say(room, from, text)

@spec say(term(), String.t(), String.t()) :: :ok

Say text in room as from.