Define a New Module
Let's define a new module in the game code.
We'll cover the following...
Channel module
The first thing we need is a Channel module. Let’s get one started at islands_interface/lib/islands_interface_web/channels/game_channel.ex
:
defmodule IslandsInterfaceWeb.GameChannel do
use IslandsInterfaceWeb, :channel
alias IslandsEngine.{Game, GameSupervisor}
To make it behave like a Channel, we use IslandsInterfaceWeb :channel
. This triggers the existing channel/0
function in the IslandsInterfaceWeb
module, located at islands_interface/lib/islands_interface_web/islands_interface_web.ex
.
def channel do
quote do
use Phoenix.Channel
import IslandsInterfaceWeb.Gettext
end
end
We later work with the Game
and GameSupervisor
modules, so we need to alias them here. ...