Simplificator3000Phoenix.Channel (Simplificator3000 Phoenix v1.8.0)
Summary
Functions
Defines a message handler.
Permissions can be passed via opts
param to validate request's rights.
Event handler receives parsed and validated payload.
A more rich version of the "barebone" message
macro. The difference is that this helper manages to execute your code in a separate linked Task
, prepares ctx
and then automatically sends given response with the metadata and request_id set up.
Data and metadata are also mapped to the serializable versions (using map_response
).
Defines a payload schema for first following message handler (that consumes the schema and prevents further use of this schema).
Payload schema is a map with keys and types.
For schema documentation see Tarams
library.
Creates a handle_info
definition which simplifies the syntax required for this code.
From this
Functions
Defines a message handler.
Permissions can be passed via opts
param to validate request's rights.
Event handler receives parsed and validated payload.
Options
- `:unauthorized_handler` - function to be called when user is not authorized to perform the action.
- `:invalid_params_handler` - function to be called when params are invalid.
- `:permissions` - list of permissions to check.
Examples
1. As a function definition:
```
message event_name(payload, socket) do
# Code
end
```
2. As a function declaration:
```
message(
:event_name,
payload_template,
opts
)
def event_name(payload, socket) do
# Code
end
```
This way you can create event handler by yourself thus allowing you to make use of multiple function pattern matching.
A more rich version of the "barebone" message
macro. The difference is that this helper manages to execute your code in a separate linked Task
, prepares ctx
and then automatically sends given response with the metadata and request_id set up.
Data and metadata are also mapped to the serializable versions (using map_response
).
No longer shall we forget do these extra steps a-ha :).
Extra variables available
ctx
- just the result ofuser_ctx(socket)
call (should contain%UserContext{}
struct with information about current user)channel_pid
- this is the PID of the channel (in case you want to send custom message to this channel)
Defines a payload schema for first following message handler (that consumes the schema and prevents further use of this schema).
Payload schema is a map with keys and types.
For schema documentation see Tarams
library.
Creates a handle_info
definition which simplifies the syntax required for this code.
From this:
def handle_info({:event, param1, param2, ...}, socket) do
...code
{:noreply, socket}
end
To this:
sub event(param1, param2, ..., socket) do
...code
{:noreply, socket}
end