Skip to main content

Matchmaker

TODO: Link to test game

TODO: Link to test game source code

Lobby lifecycle

TODO: Diagram

Client

Connect to rivet matchmaking and find a lobby with the 'default' gamemode, then connect to its websocket.

let clientApi = new mm.MatchmakerService({});

let res = await clientApi.findLobby({
gameModes: ['default'],
preventAutoCreateLobby: false
});

let port = res.lobby.ports['default'];
let token = res.lobby.player.token;
let gameIndex = 0;

let wsProtocol = port.useTls ? 'wss:' : 'ws:';
let url = `${wsProtocol}//${port.hostname}:${port.port}/?gameIndex=${gameIndex}`;
if (token != null) url += `&token=${token}`;

let ws = new WebSocket(url);

Server

Mark a lobby as ready to accept players from Rivet

let rivetServer = new rivet.MatchmakerService({});

await rivetServer.lobbyReady({});

Mark a player as connected/disconnected (parse playerToken from URL query)

await rivetServer.playerConnected({ playerToken });
await rivetServer.playerDisconnected({ playerToken });

Player lifecycle

TODO: Diagram