Rooms API (BETA)
Build synchronous multiplayer sessions backed by the Venus Rooms service. Create or join rooms, stream updates in real time, and coordinate turn-based or free-form play.
⚠️ Rooms only work inside the Venus host environment. Local mock mode throws helpful errors instead of simulating networking.
Creating & Joining Rooms
import VenusAPI from '@series-inc/venus-sdk/api'
// Create a room explicitly
const createdRoom = await VenusAPI.rooms.createRoomAsync({
maxPlayers: 4,
gameType: 'chess',
isPrivate: false,
name: 'Epic Chess Match',
customMetadata: { skillLevel: 'intermediate' },
data: { turnDuration: 30 },
})
// Join or create via matchmaking defaults
const result = await VenusAPI.rooms.joinOrCreateRoomAsync({
matchCriteria: { gameType: 'chess', hasSpace: true },
createOptions: { maxPlayers: 2, name: 'Quick Match' },
})
// { action: 'joined' | 'created', room, playersJoined }
// Join by invite code
const room = await VenusAPI.rooms.joinRoomByCodeAsync('ABC123')
// List rooms you currently belong to
const rooms = await VenusAPI.rooms.getUserRoomsAsync({ includeArchived: false })Room Data & Messaging
Room messages are for chat or lightweight event broadcasts.
Authoritative game flow (phase/turn order/current player) is managed server-side under room.customMetadata.rules:
room.customMetadata.rules.gameState.phaseis the canonical phase ('waiting'~= lobby,'playing'in-game,'ended'complete).room.customMetadata.rules.hostProfileIdis the canonical “host/arbiter” identity (room creator).For turn-based games,
room.customMetadata.rules.gameStatealso containsturnOrder,currentPlayer, andturnCount.
Quickstart: Ready-up + Start Game (server-authoritative)
The recommended multiplayer pattern is:
Players write intent via
proposeMoveAsync(low-latency direct Firestore write via the host).Server validates and updates authoritative state.
Host/arbiter (the room creator) coordinates a countdown and calls
startRoomGameAsync.
Real-Time Subscriptions
onData fires for authoritative room-state changes, onMessages for chat/game payloads, and onGameEvents for turn-based proposals.
Turn-Based Game Flow
Configuration
Rooms config is delivered by the host during INIT_SDK. You don’t read VenusAPI.config.rooms directly—the SDK blocks that—and instead the Rooms APIs inject these defaults when you omit parameters.
Minimal config (single game type)
gameTypeis sent on create/join calls unless you override it.Host matchmaking and creation defaults are applied when you omit options.
Full config (advanced)
How the SDK applies this configuration
Matchmaking:
joinOrCreateRoomAsyncusesmatchmaking.defaultCriteriaand honorsenableAutoMatch/maxSearchResultswhen you omit criteria.Creation defaults:
createOptionssupplygameType,maxPlayers, and metadata when not provided in the call.Private rooms:
privateMatchDefaults.createOptionsare layered on top ofcreateOptions;allowCustomCodecontrols whether user-suppliedroomCodevalues are accepted.Rules/game type:
gameTypeand optionalrulesPresetare forwarded so the host can enforce rule sets without extra parameters.
Notes
Configuration is host-provided; use
VenusAPI.rooms.*methods and pass overrides only when needed.Per-call overrides take precedence over config defaults for that single call.
Room Properties & Best Practices
VenusRoom includes id, players, maxPlayers, gameType, isPrivate, status, customMetadata, data, timestamps, and admin IDs.
Treat
customMetadata.rules.gameStateas the canonical game lifecycle state:Lobby vs in-game:
phase === 'waiting'(lobby) vsphase === 'playing'(in-game).Turn-based fields:
turnOrder,currentPlayer,turnCount(when applicable).
Treat
customMetadata.rules.hostProfileIdas the canonical room host/arbiter identity.Always
unsubscribe()andleaveRoomAsync()when a player exits to free slots.Pair
proposeMoveAsyncandvalidateMoveAsyncfor peer-validated turn systems; fall back to authoritative arbitration on the server when needed.
Last updated