The developer docs are written in English and Spanish. You are reading the English version.

Multiplayer: invites, rooms and presence

Gamealia does not run your game servers: your multiplayer backend (Colyseus, WebSockets, WebRTC signalling...) stays yours. The SDK gives you what is around it: invite links, a public list of open rooms, and friends who see what each other is playing.

Declare your servers in the listing's backendHosts, so the autotest knows they are yours.

If your server checks the Origin of WebSocket or HTTP requests, allow exactly these two:

  • https://<your-slug>.gamealia.app: your game's own origin, where players play it;
  • https://gamealia-cdn.tinchogon34.workers.dev: previews, the autotest and older links.

Never allow *.gamealia.app: every other game is served from there too.

An invite link opens your game on the portal and passes a room code to it: https://gamealia.app/game/<slug>?room=<CODE>. Codes are 1-32 characters of A-Z a-z 0-9 _ -.

// The host made a room on your server:
const link = await Gamealia.room.inviteLink(room.code);
copyToClipboard(link);
// Or let the portal show its own invite sheet (copy, share):
Gamealia.room.showInvite(room.code);

A player who arrives with a code gets it at startup, and while playing when they join a room from the portal:

const { joinRoom } = await Gamealia.init(); // same as Gamealia.room.getJoinCode()
if (joinRoom) connectToRoom(joinRoom);

Gamealia.on("roomJoin", (code) => connectToRoom(code));

In the mock, inviteLink(code) returns the current URL with ?gamealia_join=<code>, and opening such a URL sets joinRoom, so you can test joins with two browser tabs.

Open rooms

Publish a room the public can join. The portal lists it on your game page and in the home's "Open rooms now" row, with the player count:

Gamealia.room.publish({ code: "K7Q2", name: "Tino's room", players: 1, max: 4, inProgress: false });
// Players join or leave: publish again with the new count.
// Full, started or closed:
Gamealia.room.unpublish();

The SDK repeats the last publish every 15 s while the game is open; the portal drops a room it has not heard from for 30 s, so a closed tab disappears on its own. One page publishes one room: publishing another code replaces it. Names are cut to 64 characters.

Friends and presence

Signed-in players can add friends. Friends see who is online, which game they are playing and a Join button when the friend's room is published and joinable. Players who joined the same room code show up in each other's "Recently played with" list.

Gamealia.presence.setStatus(text) adds a short status ("Level 3", "Waiting for players") that friends see next to the game. It is cut to 64 characters and sent at most once every 2 s; an empty text clears it.

Listing

Set multiplayer: { min, max } (players per room) in the listing and the multiplayer tag, so players can filter for it. Use null for single-player games.

Starter

gamealia new my-game --template multiplayer (or gamealia_create_project with template: "multiplayer") creates a small game with rooms, invites and the open rooms list already wired.