JavaScript SDK — Rooms

Rooms — mp.rooms

create
await mp.rooms.create(playerToken, roomName, { password?, maxPlayers?, hostSwitch?, realtime?, rules?, playerData? })

Creates a room — the creator becomes host. realtime:true enables the WS/UDP channel; rules/playerData carry game JSON.

list
await mp.rooms.list({ search?, limit? })

Public room browser — no player token needed.

join
await mp.rooms.join(playerToken, roomId, { password?, joinToken?, playerData? })

Joins a room by id — password for protected rooms, joinToken for invite flows.

players
await mp.rooms.players(playerToken)

Lists occupants of the player's current room.

leave / heartbeat / current
await mp.rooms.leave(playerToken)
await mp.rooms.heartbeat(playerToken)
await mp.rooms.current(playerToken)

Leave the room, keep membership alive, read current room state.

stop / kick / password (host)
await mp.rooms.stop(playerToken)
await mp.rooms.kick(playerToken, playerId)
await mp.rooms.password(playerToken, password)

Host controls: stop the room, remove a player, set/clear the room password.

Room lifecycle and host controls

A room is one live game session. Create makes the caller the host; list browses public rooms without needing a player token; join enters by id — with a password for protected rooms. Players lists the occupants of the caller's current room, and leave, heartbeat and current manage the membership lifecycle.

The host gets the controls: stop the room, kick a member, set or clear the password. Room custom data holds shared state — map, mode, phase — that members read to stay in sync, and matchmaking lobbies spawn a linked room when the host starts.

  • Send heartbeat on an interval while joined — lapsed memberships get cleaned up server-side.
  • Room titles are validated against your game's room rules at creation, same pipeline as player names.
  • Choose rooms for direct create-and-join flows, matchmaking when players need a browsable lobby first.
  • Every call returns a Promise — await inside async functions. In browsers requests run over fetch with CORS; on Node.js 22.12+ the identical API uses the built-in fetch.