Schedule broadcast to sockets

Hi There,

I am building a multiplayer game where I need to timeout some actions for example “roll a dice” so if a user doesn’t roll a dice within the specified time then its the next player’s turn.

My set up is

A Dynamic Supervisor -> Game Server -> A phoenix channel for each game

Now users are connected to a game channel and game is in play, Since I am new to all this elixir/genserver thing, I don’t know how to broadcast after a certain time.

What I know

  • How to schedule a message in future in gen servers
  • A channel is also a process

What I wonder about

  • Is there any way to send a message from the game server to game channel? so I can broadcast from there
  • Or should I schedule it in game channel itself?
  • I tried scheduling it in the game channel but I don’t know how to get the socket in init callback? Do I even need this or I will get it anyhow automatically in handle_info callback of the game channel (Does a channel even have the GenServer behaviour)?

Please bear with me if anything sounds stupid as I am still learning it.

I‘d investigate :genstatem for game logic instead of using a genserver. It also supports many timeout options.