Garuda v0.2.5 Garuda.GameSocket

Defines specific game behaviours over Phoenix.Socket

GameSocket extends Phoenix.Socket with extra game behaviours.

Using GameSocket

In user_socket.ex, we can do

defmodule TictactoePhxWeb.UserSocket do
  use Garuda.GameSocket

  game_channel "tictactoe", TictactoePhxWeb.TictactoeChannel, TictactoePhx.TictactoeRoom

end

You might have noticed that instead of use Phoenix.Socket, we are using Garuda.GameSocket and instead of channel, we are using game_channel.

Link to this section Summary

Functions

Defines a game-channel and corresponding game-room name.

Link to this section Functions

Link to this macro

game_channel(channel_name, channel_module, room_module)

(macro)

Defines a game-channel and corresponding game-room name.

  • channel_name - A game-channel name as string, ex "tictactoe"
  • channel_module - The game-channel module handler, ex TictactoePhxWeb.TictactoeChannel
  • game_room_module - The game-room module handler, where core game logic resides, ex TictactoePhx.TictactoeRoom

Example

game_channel "tictactoe", TictactoePhxWeb.TictactoeChannel, TictactoePhx.TictactoeRoom