Spell.Role behaviour

The Spell.Role module defines the behaviour of a role in spell.

A role specifies the logic for handling groups of commands. A peer is started with one or more roles, which the peer uses to configure its state and handle its messages.

Callbacks

A module must implement all Spell.Role behaviour callbacks, though the `use Spell.Role` directive provides a sane default implementation for each.

Source

Summary

call(roles, role, message, from, peer)

From roles call the role‘s send_message function with the message and the role’s state

collect_features(roles)

Returns a map with the features of the listed roles

map_handle_message(roles, message, peer)

Call the handle_message function for a list of roles

map_init(roles, peer_options)

Call the on_init function for a list of roles. peer_options is the list of options which a peer was initialized with

map_on_close(roles, peer)

Call the on_close function for a list of roles

map_on_open(roles, peer)

Call the on_open function for a list of roles

normalize_role_options(roles, acc \\ [])

Normalize a list of role options by wrapping bare module items with an option tuple. If an unexpected role is encountered, an error tuple is returned

Types

peer_options :: %{roles: %{features: Map.t}}

Functions

call(roles, role, message, from, peer)

Specs:

  • call([{module, any}], module, any, pid, Peer.t) :: {:ok, [{module, any}]} | {:error, :no_role}

From roles call the role‘s send_message function with the message and the role’s state.

Source
collect_features(roles)

Specs:

Returns a map with the features of the listed roles.

Source
map_handle_message(roles, message, peer)

Specs:

  • map_handle_message([{module, any}], Message.t, Peer.t) :: {:ok, [{module, any}]} | {:error, any}

Call the handle_message function for a list of roles.

Source
map_init(roles, peer_options)

Specs:

  • map_init([{module, any}], Keyword.t) :: {:ok, [{module, any}]} | {:error, any}

Call the on_init function for a list of roles. peer_options is the list of options which a peer was initialized with.

Source
map_on_close(roles, peer)

Specs:

  • map_on_close([{module, any}], Peer.t) :: {:ok, [{module, any}]} | {:error, any}

Call the on_close function for a list of roles.

Source
map_on_open(roles, peer)

Specs:

  • map_on_open([{module, any}], Peer.t) :: {:ok, [{module, any}]} | {:error, any}

Call the on_open function for a list of roles.

Source
normalize_role_options(roles, acc \\ [])

Normalize a list of role options by wrapping bare module items with an option tuple. If an unexpected role is encountered, an error tuple is returned.

Source

Callbacks

get_features/1

Specs:

  • get_features(options :: Keyword.t) :: {atom, %{}}

Get the key and features that this role announces. Returns nil if the features announces no features.

Source
handle_call/4

Specs:

  • handle_call(message :: any, from :: pid, peer :: Peer.t, state :: any) :: {:ok, any, any} | {:error, any}

Handle a call from the peer.

Return values

  • {:ok, reply, new_state}: return reply
  • {:error, reason}
Source
handle_message/3

Specs:

  • handle_message(message :: Message.t, peer :: Peer.t, state :: any) :: {:ok, any} | {:error, any}

Handle an incoming WAMP message.

Source
init/2

Specs:

init callback for generating the role’s initial state given options.

Source
on_close/2

Specs:

  • on_close(peer :: Peer.t, state :: any) :: {:ok, any} | {:error, any}

Called when the connection is being closed. Returns the state wrapped in an ok tuple or an error tuple

Source
on_open/2

Specs:

  • on_open(peer :: Peer.t, state :: any) :: {:ok, any} | {:error, any}

Called after the connection is opened. Returns the state wrapped in an ok tuple or an error tuple.

Source