GameServerWeb.UserChannel (game_server_web v1.0.938)

Copy Markdown

Channel for sending per-user realtime updates (e.g. metadata changes).

Topic: "user:<user_id>" Clients must authenticate the socket connection (JWT) and may only join topics belonging to their own user id.

Online presence

When a user joins the channel their is_online flag is set to true in the database and a "friend_online" event is pushed to every accepted friend's channel. When the last channel process for a user terminates the flag is reset and a "friend_offline" event is pushed.

Notifications

On join the channel pushes all undeleted notifications for the user in chronological order (oldest-first) as individual "notification" events. New notifications arriving while connected are also pushed as "notification".

Hook RPC

Clients can call plugin hooks via "call_hook" push with reply:

push("call_hook", %{plugin: "my_plugin", fn: "my_func", args: [1, 2]})
 reply {:ok, %{data: result}} | {:error, %{error: reason}}

This avoids the HTTP round-trip of POST /api/v1/hooks/call while the socket is connected. The caller context (user) is injected automatically.

Summary

Functions

child_spec(init_arg)

start_link(triplet)