Kalevala.Communication.Channel behaviour (kalevala v0.1.0) View Source

A GenServer to handle channel communication

Link to this section Summary

Types

The "topic" in the channel pub/sub

Config is saved and stored in the GenServer, passed in for each callback

Options are for each subscribe/publish request

Functions

Returns a specification to start this module under a supervisor.

Publish a new message

Callbacks

Called during initialization

Called before a message is allowed to publish on the channel

Called before a pid is allowed to subscribe to a channel

Called before a pid is allowed to unsubscribe to a channel

Link to this section Types

Specs

channel_name() :: String.t()

The "topic" in the channel pub/sub

This might be a simple global channel name or something specific to rooms, maybe rooms:id.

Specs

config() :: map()

Config is saved and stored in the GenServer, passed in for each callback

Specs

options() :: map()

Options are for each subscribe/publish request

This may contain information like charcater data

Link to this section Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

publish(pid, message, options)

View Source

Publish a new message

Link to this function

subscribe(pid, channel_name, subscriber_pid, options)

View Source

Subscribe to a new channel

Allows for the callback_module to reject subscription

Link to this function

unsubscribe(pid, channel_name, subscriber_pid, options)

View Source

Unsubscribe to a new channel

Allows for the callback_module to reject unsubscription

Link to this section Callbacks

Specs

init(config()) :: config()

Called during initialization

You can change any of the config you wish on start of the gen server

Link to this callback

publish_request(channel_name, arg2, options, config)

View Source

Specs

publish_request(channel_name(), Kalevala.Event.message(), options(), config()) ::
  :ok

Called before a message is allowed to publish on the channel

Link to this callback

subscribe_request(channel_name, options, config)

View Source

Specs

subscribe_request(channel_name(), options(), config()) :: :ok

Called before a pid is allowed to subscribe to a channel

Link to this callback

unsubscribe_request(channel_name, options, config)

View Source

Specs

unsubscribe_request(channel_name(), options(), config()) :: :ok

Called before a pid is allowed to unsubscribe to a channel