Constants Reference
Reference for all constants used in the Moitribe SDK, including message types for real-time communication and API status codes.
MessageConstants
Constants for real-time multiplayer message types used in MQTT communication.
import { MessageConstants } from '@veniso/moitribe-js';
console.log(MessageConstants.MSG_TYPE_JOIN_ROOM); // 1
console.log(MessageConstants.MSG_TYPE_SEND_RELIABLE_MESSAGE); // 2
Room Management Messages
| Constant | Value | Description |
|---|---|---|
MSG_TYPE_LEAVE_ROOM | 0 | Player leaves a room |
MSG_TYPE_JOIN_ROOM | 1 | Player joins a room |
MSG_TYPE_JOINED_ROOM | 5 | Player successfully joined room |
MSG_TYPE_LEFT_ROOM | 6 | Player successfully left room |
MSG_TYPE_ROOM_CONNECTED | 7 | Room connection established |
MSG_TYPE_ON_ROOM_CONNECTING | 8 | Room connection in progress |
MSG_TYPE_ON_ROOM_AUTOMATCHING | 9 | Room auto-matching in progress |
MSG_TYPE_ON_CONNECTED_TO_ROOM | 14 | Connected to room |
MSG_TYPE_ON_DISCONNECTED_FROM_ROOM | 15 | Disconnected from room |
MSG_TYPE_STILL_CONNECTED_TO_ROOM | 22 | Still connected to room |
MSG_TYPE_NOT_IN_ROOM | 23 | Player not in room |
MSG_TYPE_CONNECTION_LOST | 24 | Connection to room lost |
MSG_TYPE_FORCE_ROOM_CONNECTED | 25 | Force room connection |
MSG_TYPE_REJOINED | 21 | Player rejoined room |
Message Communication
| Constant | Value | Description |
|---|---|---|
MSG_TYPE_SEND_RELIABLE_MESSAGE | 2 | Send reliable message |
MSG_TYPE_SEND_UNRELIABLE_MESSAGE | 3 | Send unreliable message |
Invitation System
| Constant | Value | Description |
|---|---|---|
MSG_TYPE_INVITATION | 4 | Room invitation |
MSG_TYPE_ON_PEER_INVITEDTOROOM | 10 | Peer invited to room |
MSG_TYPE_ON_PEER_DECLINED | 11 | Peer declined invitation |
MSG_TYPE_CHALLENGE | 20 | Challenge message |
Player State Events
| Constant | Value | Description |
|---|---|---|
MSG_TYPE_ON_PEER_JOINED | 12 | Peer joined room |
MSG_TYPE_ON_PEER_LEFT | 13 | Peer left room |
MSG_TYPE_ON_PEERS_CONNECTED | 16 | Peers connected |
MSG_TYPE_ON_PEERS_DISCONNECTED | 17 | Peers disconnected |
MSG_TYPE_ON_P2P_CONNECTED | 18 | P2P connection established |
MSG_TYPE_ON_P2P_DISCONNECTED | 19 | P2P connection lost |
MSG_TYPE_ON_PEER_UNREACHABLE | 30 | Peer unreachable |
MSG_TYPE_ON_PEER_NOW_REACHABLE | 31 | Peer now reachable |
Room Management Events
| Constant | Value | Description |
|---|---|---|
MSG_TYPE_KICK_PLAYERS | 26 | Kick players from room |
MSG_TYPE_ON_KICKED_FROM_ROOM | 27 | Player was kicked from room |
MSG_TYPE_ON_PEER_KICKED_FROM_ROOM | 28 | Peer was kicked from room |
Turn-Based Matches
| Constant | Value | Description |
|---|---|---|
MSG_TYPE_TURN_BASED_MATCH | 5 | Turn-based match message |
Usage Examples
Handling Room Events
// In your RTM callback handlers
function handleRoomMessage(messageType, data) {
switch (messageType) {
case MessageConstants.MSG_TYPE_ON_PEER_JOINED:
console.log('Peer joined:', data.participantID);
break;
case MessageConstants.MSG_TYPE_ON_PEER_LEFT:
console.log('Peer left:', data.participantID);
break;
case MessageConstants.MSG_TYPE_ON_CONNECTED_TO_ROOM:
console.log('Connected to room:', data.roomID);
break;
case MessageConstants.MSG_TYPE_ON_DISCONNECTED_FROM_ROOM:
console.log('Disconnected from room:', data.roomID);
break;
}
}
Message Reliability
// Send reliable message for important game data
const reliableMessage = {
type: MessageConstants.MSG_TYPE_SEND_RELIABLE_MESSAGE,
data: gameCriticalData
};
// Send unreliable message for frequent updates
const unreliableMessage = {
type: MessageConstants.MSG_TYPE_SEND_UNRELIABLE_MESSAGE,
data: positionUpdate
};
StatusCodes
Constants for API response status codes returned by the Moitribe backend.
import { StatusCodes } from '@veniso/moitribe-js';
if (response.reqQuery.statuscode === StatusCodes.STATUS_OK) {
console.log('Request successful');
} else if (response.reqQuery.statuscode === StatusCodes.STATUS_SIGNED_IN_PLAYER_REQUIRED) {
console.log('Authentication required');
}
General Status Codes
| Constant | Value | Description |
|---|---|---|
STATUS_OK | 0 | Request successful |
STATUS_INTERNAL_ERROR | 1 | Internal server error |
STATUS_INCORRECT_GAMEID | 2 | Invalid game ID |
STATUS_API_OBSOLETE | -3 | API version obsolete |
STATUS_API_SERVICE_IS_DOWN | -4 | API service unavailable |
STATUS_INVALID_API_VERSION | -5 | Invalid API version |
STATUS_SIGNED_IN_PLAYER_REQUIRED | -6 | Player authentication required |
STATUS_SIGNED_DELETED_PLAYER | -7 | Player account deleted |
Achievement Status Codes
| Constant | Value | Description |
|---|---|---|
STATUS_ACHIEVEMENT_UNKNOWN | 3001 | Achievement not found |
Turn-Based Match Status Codes
| Constant | Value | Description |
|---|---|---|
STATUS_MATCH_NOT_FOUND | 6506 | Match not found |
STATUS_MULTIPLAYER_ERROR_INVALID_OPERATION | 6004 | Invalid multiplayer operation |
STATUS_MATCH_ERROR_ALREADY_REMATCHED | 6505 | Match already rematched |
STATUS_MATCH_ERROR_OUT_OF_DATE_VERSION | 6503 | Match version out of date |
Real-Time Multiplayer Status Codes
| Constant | Value | Description |
|---|---|---|
STATUS_INVALID_REAL_TIME_ROOM_ID | 7002 | Invalid room ID |
STATUS_REAL_TIME_INACTIVE_ROOM | 7005 | Room is inactive |
STATUS_REAL_TIME_NO_SLOT | 7008 | No available slots in room |
STATUS_REAL_TIME_SIZE_ZERO | 7009 | Room size is zero |
STATUS_REAL_TIME_PLAYER_ALREADY_IN_ROOM | 7010 | Player already in room |
Challenge Status Codes
| Constant | Value | Description |
|---|---|---|
STATUS_CHALLEGE_SCORE_ZERO | 10001 | Challenge score is zero |
STATUS_CHALLEGE_ID_INVALID | 10002 | Invalid challenge ID |
STATUS_CHALLEGE_COMPLETED | 10003 | Challenge already completed |
Feed Status Codes
| Constant | Value | Description |
|---|---|---|
STATUS_FEED_GAME_NOT_IN_CONTENTAPP | 11001 | Game not in content app |
STATUS_FEED_INSUFFICIENT_DATA | 11002 | Insufficient feed data |
STATUS_FEED_INVALID_LEADERBOARD_IDS | 11003 | Invalid leaderboard IDs |
STATUS_FEED_INVALID_TOURNAMENT_IDS | 11004 | Invalid tournament IDs |
Leaderboard Status Codes
| Constant | Value | Description |
|---|---|---|
STATUS_LEADERBOARD_SUBMIT_SCORE_FAILED | 12001 | Score submission failed |
STATUS_LEADERBOARD_SCORE_ZERO | 12002 | Score is zero |
Profile Status Codes
| Constant | Value | Description |
|---|---|---|
STATUS_PROFILE_EMAIL_PHONENO_EXISTS | 13001 | Email or phone already exists |
STATUS_PROFILE_INSUFFICIENT_DETAILS | 13002 | Insufficient profile details |
STATUS_PROFILE_ACCOUNT_NOT_FOUND | 13003 | Account not found |
STATUS_PROFILE_NO_DATA_FOR_UPDATE | 13004 | No data provided for update |
STATUS_PROFILE_OLD_PASSWORD_MISMATCH | 13005 | Old password mismatch |
STATUS_PROFILE_INVALID_CREDENTIALS | 13006 | Invalid credentials |
STATUS_PROFILE_UNSUPPORTED_SOCIAL_PLATFORM | 13007 | Unsupported social platform |
STATUS_PROFACTION_VERIFY_NONE | 13008 | No verification required |
STATUS_INVALID_PLAYER_ID | 13009 | Invalid player ID |
STATUS_INVALID_LOGIN_OPTION | 13010 | Invalid login option |
STATUS_PROFACTION_OTP_PARAM_INVALID | 13011 | Invalid OTP parameters |
STATUS_PROFACTION_OTP_INCORRECT | 13012 | Incorrect OTP |
STATUS_PROFACTION_OTP_UNAVAILABLE | 13013 | OTP unavailable |
STATUS_PROFACTION_CALL_VERIFY_FIRST | 13014 | Call verify first |
Invitation Status Codes
| Constant | Value | Description |
|---|---|---|
STATUS_INVITATION_INVALID_OBJECT | 14001 | Invalid invitation object |
Tournament Status Codes
| Constant | Value | Description |
|---|---|---|
STATUS_TOURNAMENT_NOT_FOUND | 15001 | Tournament not found |
STATUS_TOURNAMENT_OUT_OF_DATE | 15002 | Tournament data out of date |
STATUS_TOURNAMENT_PARTICIPANTS_FULL | 15003 | Tournament participants full |
STATUS_TOURNAMENT_VERIFIED_REQUIRED | 15004 | Tournament verification required |
STATUS_TOURNAMENT_NOT_JOINED | 15005 | Not joined tournament |
STATUS_TOURNAMENT_SEND_SUBTOURNAMENT_ID | 15006 | Send sub-tournament ID |
STATUS_TOURNAMENT_ALREADY_JOINED | 15007 | Already joined tournament |
STATUS_TOURNAMENT_NO_ID_SENT | 15008 | No tournament ID sent |
STATUS_TOURNAMENT_NO_CLAIMS | 15009 | No tournament claims |
Usage Examples
Error Handling
function handleApiResponse(response) {
const statusCode = response.reqQuery?.statuscode;
switch (statusCode) {
case StatusCodes.STATUS_OK:
console.log('Success:', response.data);
break;
case StatusCodes.STATUS_SIGNED_IN_PLAYER_REQUIRED:
console.log('Please authenticate first');
// Redirect to login
break;
case StatusCodes.STATUS_REAL_TIME_NO_SLOT:
console.log('Room is full');
// Try another room or create new one
break;
case StatusCodes.STATUS_LEADERBOARD_SCORE_ZERO:
console.log('Score cannot be zero');
// Validate score before submission
break;
default:
console.error('Error:', response.reqQuery?.msg || 'Unknown error');
}
}
RTM Message Handling
function handleRTMMessage(message) {
const { msgtype, roomid, participantid } = message;
switch (msgtype) {
case MessageConstants.MSG_TYPE_ON_PEER_JOINED:
console.log(`Player ${participantid} joined room ${roomid}`);
break;
case MessageConstants.MSG_TYPE_ON_PEER_LEFT:
console.log(`Player ${participantid} left room ${roomid}`);
break;
case MessageConstants.MSG_TYPE_ON_CONNECTED_TO_ROOM:
console.log(`Connected to room ${roomid}`);
break;
case MessageConstants.MSG_TYPE_ON_DISCONNECTED_FROM_ROOM:
console.log(`Disconnected from room ${roomid}`);
break;
}
}
Validation Before API Calls
function validateScore(score) {
if (score === 0) {
console.error('Score cannot be zero');
return false;
}
return true;
}
function submitScore(leaderboardId, score) {
if (!validateScore(score)) {
return;
}
MoitribeSDK('my-game', 'submitscore', {
leaderboardid: leaderboardId,
score: score
}, (response) => {
if (response.reqQuery?.statuscode === StatusCodes.STATUS_LEADERBOARD_SCORE_ZERO) {
console.error('Server rejected zero score');
}
});
}
tip
Always check status codes in API responses to handle errors gracefully and provide better user experience.
Next Steps
- SDK Methods Reference - All available SDK methods
- Models Reference - Data structures and types
- Callbacks Reference - Callback signatures and patterns