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

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

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

Functions

Returns a specification to start this module under a supervisor.

Publish a new message

Link to this section Types

@type 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.

@type config() :: map()

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

@type options() :: map()

Options are for each subscribe/publish request

This may contain information like charcater data

Link to this section Callbacks

@callback 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, message, options, config)

View Source
@callback 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
@callback 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
@callback unsubscribe_request(channel_name(), options(), config()) :: :ok

Called before a pid is allowed to unsubscribe to a channel

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