Skip to content

apps/nakama: Nakama's runtime module ​

What the platform adds to the Nakama server of the Compose stack (Technical specs §9.6, §9.9; Social, Deploying). One TypeScript file, src/index.ts, with no imports: Nakama's JavaScript runtime loads one plain script and calls its InitModule.

WhatWhenDoes
The ChannelMessageSend before-hookA client says something on a chat channelOn a game room's channel (a room channel named room-…), asks the API whether it may be read (POST /moderation/chat {texts, room} with the room secret: a room the API opened as private is let through, the rest goes to the moderator). Hidden, or unchecked: dropped, never delivered. Other channels pass.
The foi_chat_keep RPCThe API keeps a party's or a direct messageSends it, as the player who wrote it, on the party's room channel (party-…) or on the two players' direct channel, kept in their history. The API calls it with the runtime's HTTP key (NAKAMA_HTTP_KEY).

The runtime's environment names the API and the room secret: --runtime.env "foi_api_url=http://api:8080" and --runtime.env "foi_room_secret=…" (deploy/compose.yaml).

Build ​

console
npm run -w apps/nakama build   # dist/index.js

build.mjs strips the types with Node's own stripTypeScriptTypes (no compiler, no dependency) and drops the exports, so the functions are the top-level declarations Nakama looks for. The stack's Nakama image (deploy/Dockerfile, target nakama) builds it and copies it to /nakama/data/modules/index.js; nothing built is committed. The source keeps to the syntax Nakama's JavaScript engine reads (no optional chaining) and declares the few parts of Nakama's runtime it uses.

src/index.test.ts runs the hook and the RPC against a fake Nakama, and builds the script and runs it as a plain script.