Skip to main content

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

ConstantValueDescription
MSG_TYPE_LEAVE_ROOM0Player leaves a room
MSG_TYPE_JOIN_ROOM1Player joins a room
MSG_TYPE_JOINED_ROOM5Player successfully joined room
MSG_TYPE_LEFT_ROOM6Player successfully left room
MSG_TYPE_ROOM_CONNECTED7Room connection established
MSG_TYPE_ON_ROOM_CONNECTING8Room connection in progress
MSG_TYPE_ON_ROOM_AUTOMATCHING9Room auto-matching in progress
MSG_TYPE_ON_CONNECTED_TO_ROOM14Connected to room
MSG_TYPE_ON_DISCONNECTED_FROM_ROOM15Disconnected from room
MSG_TYPE_STILL_CONNECTED_TO_ROOM22Still connected to room
MSG_TYPE_NOT_IN_ROOM23Player not in room
MSG_TYPE_CONNECTION_LOST24Connection to room lost
MSG_TYPE_FORCE_ROOM_CONNECTED25Force room connection
MSG_TYPE_REJOINED21Player rejoined room

Message Communication

ConstantValueDescription
MSG_TYPE_SEND_RELIABLE_MESSAGE2Send reliable message
MSG_TYPE_SEND_UNRELIABLE_MESSAGE3Send unreliable message

Invitation System

ConstantValueDescription
MSG_TYPE_INVITATION4Room invitation
MSG_TYPE_ON_PEER_INVITEDTOROOM10Peer invited to room
MSG_TYPE_ON_PEER_DECLINED11Peer declined invitation
MSG_TYPE_CHALLENGE20Challenge message

Player State Events

ConstantValueDescription
MSG_TYPE_ON_PEER_JOINED12Peer joined room
MSG_TYPE_ON_PEER_LEFT13Peer left room
MSG_TYPE_ON_PEERS_CONNECTED16Peers connected
MSG_TYPE_ON_PEERS_DISCONNECTED17Peers disconnected
MSG_TYPE_ON_P2P_CONNECTED18P2P connection established
MSG_TYPE_ON_P2P_DISCONNECTED19P2P connection lost
MSG_TYPE_ON_PEER_UNREACHABLE30Peer unreachable
MSG_TYPE_ON_PEER_NOW_REACHABLE31Peer now reachable

Room Management Events

ConstantValueDescription
MSG_TYPE_KICK_PLAYERS26Kick players from room
MSG_TYPE_ON_KICKED_FROM_ROOM27Player was kicked from room
MSG_TYPE_ON_PEER_KICKED_FROM_ROOM28Peer was kicked from room

Turn-Based Matches

ConstantValueDescription
MSG_TYPE_TURN_BASED_MATCH5Turn-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

ConstantValueDescription
STATUS_OK0Request successful
STATUS_INTERNAL_ERROR1Internal server error
STATUS_INCORRECT_GAMEID2Invalid game ID
STATUS_API_OBSOLETE-3API version obsolete
STATUS_API_SERVICE_IS_DOWN-4API service unavailable
STATUS_INVALID_API_VERSION-5Invalid API version
STATUS_SIGNED_IN_PLAYER_REQUIRED-6Player authentication required
STATUS_SIGNED_DELETED_PLAYER-7Player account deleted

Achievement Status Codes

ConstantValueDescription
STATUS_ACHIEVEMENT_UNKNOWN3001Achievement not found

Turn-Based Match Status Codes

ConstantValueDescription
STATUS_MATCH_NOT_FOUND6506Match not found
STATUS_MULTIPLAYER_ERROR_INVALID_OPERATION6004Invalid multiplayer operation
STATUS_MATCH_ERROR_ALREADY_REMATCHED6505Match already rematched
STATUS_MATCH_ERROR_OUT_OF_DATE_VERSION6503Match version out of date

Real-Time Multiplayer Status Codes

ConstantValueDescription
STATUS_INVALID_REAL_TIME_ROOM_ID7002Invalid room ID
STATUS_REAL_TIME_INACTIVE_ROOM7005Room is inactive
STATUS_REAL_TIME_NO_SLOT7008No available slots in room
STATUS_REAL_TIME_SIZE_ZERO7009Room size is zero
STATUS_REAL_TIME_PLAYER_ALREADY_IN_ROOM7010Player already in room

Challenge Status Codes

ConstantValueDescription
STATUS_CHALLEGE_SCORE_ZERO10001Challenge score is zero
STATUS_CHALLEGE_ID_INVALID10002Invalid challenge ID
STATUS_CHALLEGE_COMPLETED10003Challenge already completed

Feed Status Codes

ConstantValueDescription
STATUS_FEED_GAME_NOT_IN_CONTENTAPP11001Game not in content app
STATUS_FEED_INSUFFICIENT_DATA11002Insufficient feed data
STATUS_FEED_INVALID_LEADERBOARD_IDS11003Invalid leaderboard IDs
STATUS_FEED_INVALID_TOURNAMENT_IDS11004Invalid tournament IDs

Leaderboard Status Codes

ConstantValueDescription
STATUS_LEADERBOARD_SUBMIT_SCORE_FAILED12001Score submission failed
STATUS_LEADERBOARD_SCORE_ZERO12002Score is zero

Profile Status Codes

ConstantValueDescription
STATUS_PROFILE_EMAIL_PHONENO_EXISTS13001Email or phone already exists
STATUS_PROFILE_INSUFFICIENT_DETAILS13002Insufficient profile details
STATUS_PROFILE_ACCOUNT_NOT_FOUND13003Account not found
STATUS_PROFILE_NO_DATA_FOR_UPDATE13004No data provided for update
STATUS_PROFILE_OLD_PASSWORD_MISMATCH13005Old password mismatch
STATUS_PROFILE_INVALID_CREDENTIALS13006Invalid credentials
STATUS_PROFILE_UNSUPPORTED_SOCIAL_PLATFORM13007Unsupported social platform
STATUS_PROFACTION_VERIFY_NONE13008No verification required
STATUS_INVALID_PLAYER_ID13009Invalid player ID
STATUS_INVALID_LOGIN_OPTION13010Invalid login option
STATUS_PROFACTION_OTP_PARAM_INVALID13011Invalid OTP parameters
STATUS_PROFACTION_OTP_INCORRECT13012Incorrect OTP
STATUS_PROFACTION_OTP_UNAVAILABLE13013OTP unavailable
STATUS_PROFACTION_CALL_VERIFY_FIRST13014Call verify first

Invitation Status Codes

ConstantValueDescription
STATUS_INVITATION_INVALID_OBJECT14001Invalid invitation object

Tournament Status Codes

ConstantValueDescription
STATUS_TOURNAMENT_NOT_FOUND15001Tournament not found
STATUS_TOURNAMENT_OUT_OF_DATE15002Tournament data out of date
STATUS_TOURNAMENT_PARTICIPANTS_FULL15003Tournament participants full
STATUS_TOURNAMENT_VERIFIED_REQUIRED15004Tournament verification required
STATUS_TOURNAMENT_NOT_JOINED15005Not joined tournament
STATUS_TOURNAMENT_SEND_SUBTOURNAMENT_ID15006Send sub-tournament ID
STATUS_TOURNAMENT_ALREADY_JOINED15007Already joined tournament
STATUS_TOURNAMENT_NO_ID_SENT15008No tournament ID sent
STATUS_TOURNAMENT_NO_CLAIMS15009No 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