Garuda v0.2.5 Garuda.GameChannel behaviour
Defines specific game behaviours over Phoenix.Channel
.
GameChannel extends Phoenix.Channel
and defines game-behaviours.
Using GameChannel
defmodule TictactoePhxWeb.TictactoeChannel do
use Garuda.GameChannel
@impl true
def on_join(_params, _socket) do
IO.puts("Player Joined")
end
@impl true
def on_rejoin(_params, _socket) do
IO.puts("Player rejoined")
end
@impl true
def authorized?(_params) do
# Custom authorization code
true
end
@impl true
def handle_in("player_move", cell, socket) do
# Handling usual events from client
{:noreply, socket}
end
end
You might have noticed that instead of use Phoenix.Channel
, we are using Garuda.GameChannel
.
Link to this section Summary
Functions
Returns the process id of game-room
Link to this section Functions
Link to this function
rid(socket)
Returns the process id of game-room
- socket - socket state of game-channel
Link to this section Callbacks
Link to this callback
authorized?(params)
Specs
Verifies the channel connection
Channel connection is only established , if authorized?
, returns true.
params
is the object that is send from the client.
Link to this callback
on_join(params, socket)
Specs
handles game-channel join.
on_join
is called after socket connection is established successfully.
Link to this callback
on_rejoin(params, socket)
Specs
handles game-channel re-join.
Called when a player re-joins the game-channel, ex after network reconnection.