Create Standard Room
Create a Standard Room to start a multiplayer session with a fixed number of players. This method is ideal for creating public rooms with auto-matching or private rooms for invited players.
Method Signature
MoitribeSDK(gameId, 'createstandardroom', params, callback)
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
variant | number | No | Game mode variant (0-255) |
min_automatch_players | number | No | Minimum players for auto-matching |
max_automatch_players | number | No | Maximum players for auto-matching |
invitedPlayerIDs | string[] | No | Array of player IDs to invite |
exclusive_bitmask | string | No | 8-bit mask for player roles |
onRoomCreated | function | Yes | Callback when room is created |
onMessageReceived | function | Yes | Callback for incoming messages |
onPeerJoined | function | Yes | Callback when players join |
onPeerLeft | function | Yes | Callback when players leave |
onLeftRoom | function | Yes | Callback when you leave room |
Examples
Public Auto-Match Room
Create a public room that automatically matches 2-4 players:
- JavaScript
- TypeScript
MoitribeSDK('my-game-id', 'createstandardroom', {
variant: 1,
min_automatch_players: 2,
max_automatch_players: 4,
onRoomCreated: (status, room) => {
if (status) {
console.log('Room created:', room.roomID);
console.log('Waiting for players...');
} else {
console.error('Failed to create room');
}
},
onMessageReceived: (messageData, senderID, isReliable) => {
console.log('Message from', senderID);
// Handle incoming game data
},
onPeerJoined: (room, participantList) => {
console.log('Player joined. Total:', participantList.length);
},
onPeerLeft: (room, participantList) => {
console.log('Player left. Total:', participantList.length);
},
onLeftRoom: (status, roomID) => {
console.log('Left room:', roomID);
}
}, (result) => {
console.log('Create room request sent:', result);
});
import MoitribeSDK from '@veniso/moitribe-js';
import type { Room, RTMStandardParams } from '@veniso/moitribe-js';
const params: RTMStandardParams = {
variant: 1,
min_automatch_players: 2,
max_automatch_players: 4,
onRoomCreated: (status: boolean, room: Room) => {
if (status) {
console.log('Room created:', room.roomID);
console.log('Waiting for players...');
} else {
console.error('Failed to create room');
}
},
onMessageReceived: (messageData: ArrayBuffer, senderID: string, isReliable: boolean) => {
console.log('Message from', senderID);
// Handle incoming game data
},
onPeerJoined: (room: Room, participantList: string[]) => {
console.log('Player joined. Total:', participantList.length);
},
onPeerLeft: (room: Room, participantList: string[]) => {
console.log('Player left. Total:', participantList.length);
},
onLeftRoom: (status: boolean, roomID: string) => {
console.log('Left room:', roomID);
}
};
MoitribeSDK('my-game-id', 'createstandardroom', params, (result) => {
console.log('Create room request sent:', result);
});
Private Invitation Room
Create a private room and invite specific players:
- JavaScript
- TypeScript
MoitribeSDK('my-game-id', 'createstandardroom', {
variant: 0,
invitedPlayerIDs: ['player123', 'player456', 'player789'],
exclusive_bitmask: '00000001',
onRoomCreated: (status, room) => {
if (status) {
console.log('Private room created:', room.roomID);
console.log('Share this invitation code with friends');
}
},
onMessageReceived: (messageData, senderID, isReliable) => {
// Handle game messages
},
onPeerJoined: (room, participantList) => {
console.log('Invited player joined the room');
},
onPeerLeft: (room, participantList) => {
console.log('Player left the room');
},
onLeftRoom: (status, roomID) => {
console.log('You left the private room');
}
}, (result) => {
console.log('Private room creation result:', result);
});
import MoitribeSDK from '@veniso/moitribe-js';
import type { Room, RTMStandardParams } from '@veniso/moitribe-js';
const params: RTMStandardParams = {
variant: 0,
invitedPlayerIDs: ['player123', 'player456', 'player789'],
exclusive_bitmask: '00000001',
onRoomCreated: (status: boolean, room: Room) => {
if (status) {
console.log('Private room created:', room.roomID);
console.log('Share this invitation code with friends');
}
},
onMessageReceived: (messageData: ArrayBuffer, senderID: string, isReliable: boolean) => {
// Handle game messages
},
onPeerJoined: (room: Room, participantList: string[]) => {
console.log('Invited player joined the room');
},
onPeerLeft: (room: Room, participantList: string[]) => {
console.log('Player left the room');
},
onLeftRoom: (status: boolean, roomID: string) => {
console.log('You left the private room');
}
};
MoitribeSDK('my-game-id', 'createstandardroom', params, (result) => {
console.log('Private room creation result:', result);
});
Response Format
The callback receives a response object:
{
success: boolean;
room?: Room; // Room object if successful
error?: string; // Error message if failed
}
Room Object
When a room is successfully created, you'll receive a Room object containing:
{
roomID: string; // Unique room identifier
creatorID: string; // Your player ID
status: RoomStatus; // Current room status
variant: number; // Game mode variant
autoMatchWaitSeconds: number; // Auto-match wait time
participants: Participant[]; // Array of players
isAutoMatch: boolean; // True for public rooms
// ... other room properties
}
Auto-Matching Behavior
When using auto-matching:
- The room waits for
min_automatch_playersto start - Maximum of
max_automatch_playerscan join - Players are matched based on skill and availability
- Room status changes from
AUTO_MATCHINGtoCONNECTINGtoACTIVE
Error Handling
Common errors and their meanings:
- Invalid Parameters: Required parameters are missing
- Player Not Authenticated: User needs to authenticate first
- Room Creation Failed: Server-side error during creation
- Invalid Variant: Variant number is out of range (0-255)
warning
Always implement the onRoomCreated callback to handle both success and failure cases. The room creation is asynchronous, so you'll need to wait for the callback before proceeding with game logic.
Best Practices
- Set reasonable auto-match ranges (e.g., 2-4 players for most games)
- Use variants to distinguish different game modes
- Implement proper error handling for all callbacks
- Show loading states while waiting for auto-matching
- Handle room lifecycle events gracefully