View Source Tamnoon.Methods (Tamnoon v1.0.0-a.1)
Provides default implementations for methods you need to get your Tamnoon server
working - basic state management (with tmnn_get/2
and tmnn_update/2
) and basic handling of
PubSub channels (via tmnn_sub/2
, tmnn_unsub/2
, tmnn_pub/2
, tmnn_subbed_channels/2
)
Using the module
When you
use Tamnoon.Methods
, every method in this module will be imported for you, letting you conveniently make a methods module. SeeTamnoon.MethodManager
for details on making one.
Note: in the documentation of the default methods, the term 'returns' is used both to describe the return value of the function and the value of the server's response.
Summary
Functions
Returns the value of the key under the field "key"
in the request as an atom.
Note: this is NOT a method handler - simply a utility function.
Returns the field with the key specified under the "key"
field
in the request. Returns an error string if there is no such item.
Invoked every 55 seconds by the client in order to prevent idle timeouts.
Will send the request under the "action"
key in the request to every client
in the channel under the "channel"
key.
Subscribes to the channel under the "key"
field in the request. If there is no such
channel, one will be created (with the client subscribed to it).
If the client is already subscribed to the channel nothing will happen.
Returns a list of the channels the client is currently subscribed to.
Returns the current state. Automatically invoked when the connection is started.
Unsubscribes from the channel under the "key"
in the request.
Updates the value of the item with the key at the "key"
field on the request,
setting it to the value at the "val"
key. Returns a tuple with the updated field and
the state, or an error string if there is no such item.
Functions
Returns the value of the key under the field "key"
in the request as an atom.
Note: this is NOT a method handler - simply a utility function.
@spec tmnn_get(map(), map()) :: {field :: map(), state :: map()} | {%{error: error :: String.t()}, state :: map()}
Returns the field with the key specified under the "key"
field
in the request. Returns an error string if there is no such item.
Invoked every 55 seconds by the client in order to prevent idle timeouts.
Will send the request under the "action"
key in the request to every client
in the channel under the "channel"
key.
Subscribes to the channel under the "key"
field in the request. If there is no such
channel, one will be created (with the client subscribed to it).
If the client is already subscribed to the channel nothing will happen.
@spec tmnn_subbed_channels(map(), map()) :: {%{subbed_channels: channels :: [String.t()]}, state :: map()}
Returns a list of the channels the client is currently subscribed to.
Returns the current state. Automatically invoked when the connection is started.
@spec tmnn_unsub(map(), map()) :: {%{unsub: :ok}, state :: map()} | {%{error: error :: String.t()}, state :: map()}
Unsubscribes from the channel under the "key"
in the request.
@spec tmnn_update(map(), map()) :: {new_field :: map(), state :: map()} | {%{error: error :: String.t()}, state :: map()}
Updates the value of the item with the key at the "key"
field on the request,
setting it to the value at the "val"
key. Returns a tuple with the updated field and
the state, or an error string if there is no such item.