Skip to main content

Type Definitions

The Moitribe JavaScript SDK provides comprehensive TypeScript definitions for all its APIs, models, and utilities.

Core Types​

CallbackFunction​

The fundamental callback type used throughout the SDK:

type CallbackFunction<T = any> = (result: T) => void;

Usage:

const myCallback: CallbackFunction<{ success: boolean }> = (result) => {
console.log('Success:', result.success);
};

APIResponse​

Generic API response structure:

interface APIResponse<T = any> {
reqQuery?: {
statuscode: number;
msg?: string;
};
profile?: any;
gamespcfcreq?: any;
[key: string]: any;
}

Model Types​

Player​

Represents a game player:

interface Player {
playerID: string; // Player's unique ID
playerName: string; // Player's display name
iconImageURL: string; // URL to player's icon image
lastPlayerTimestamp: number; // Last active timestamp (10 digit)
title: string; // Player's title/rank
}

Example:

const player: Player = {
playerID: 'player_123',
playerName: 'Alex',
iconImageURL: 'https://example.com/icon.png',
lastPlayerTimestamp: 1703123456,
title: 'Champion'
};

SignedInProfile​

Complete profile information for authenticated players:

interface SignedInProfile {
id: string; // Player's unique ID
bannerimgland: string; // Landscape banner image URL
bannerimgport: string; // Portrait banner image URL
name: string; // Player's display name
title: string; // Player's title/rank
profileicon: string; // Profile icon URL
profilehiresimg: string; // High-resolution profile image URL
level: string; // Player's level
friends: string[]; // Array of friend IDs
}

Example:

const profile: SignedInProfile = {
id: 'player_123',
bannerimgland: 'https://example.com/banner-land.jpg',
bannerimgport: 'https://example.com/banner-port.jpg',
name: 'Alex',
title: 'Master Player',
profileicon: 'https://example.com/icon.png',
profilehiresimg: 'https://example.com/hires.jpg',
level: '42',
friends: ['player_456', 'player_789']
};

Room​

Real-time multiplayer room information:

interface Room {
id: string; // Room unique ID
name: string; // Room display name
status: RoomStatus; // Current room status
maxPlayers: number; // Maximum number of players
currentPlayers: number; // Current number of players
variant: number; // Room variant/game mode
creatorId: string; // Room creator's ID
creationTime: number; // Room creation timestamp
}

Participant​

Room participant information:

interface Participant {
id: string; // Participant unique ID
playerID: string; // Player's ID
playerName: string; // Player's name
status: ParticipantStatus; // Participant status
joinedTime: number; // When participant joined
isReady: boolean; // Ready status
}

Leaderboard Types​

LeaderboardMeta​

Leaderboard metadata information:

interface LeaderboardMeta {
id: string; // Leaderboard ID
name: string; // Leaderboard display name
description: string; // Leaderboard description
sortOrder: 'asc' | 'desc'; // Score sorting order
scoreType: 'integer' | 'float' | 'time'; // Score type
daily: boolean; // Has daily timespan
weekly: boolean; // Has weekly timespan
allTime: boolean; // Has all-time timespan
}

LeaderboardScoreData​

Individual score entry:

interface LeaderboardScoreData {
rank: number; // Score rank
playerID: string; // Player's ID
playerName: string; // Player's name
score: number; // Score value
scoreTag: string; // Additional score metadata
timestamp: number; // When score was achieved
}

Parameter Types​

GameInitParams​

SDK initialization parameters:

interface GameInitParams {
div?: string; // Parent div ID (deprecated)
playerid?: string; // Player ID if authenticated
channelid?: string; // Channel ID
noui?: boolean; // Disable UI (always true)
tpparams?: ThirdPartyParams; // Third-party parameters
social?: SocialLoginParams; // Social login credentials
loginCallback?: CallbackFunction | UnityCallback;
connectionCallbacks?: ConnectionCallbacks;
isUnity?: boolean; // Unity integration flag
unityGameInstanceName?: string; // Unity game instance
rtmTest?: boolean; // RTM testing mode
}

ThirdPartyParams​

Third-party platform integration:

interface ThirdPartyParams {
muniqueid?: string; // Unique ID from third-party platform
mautologin?: boolean; // Auto-login flag
mchanid?: string; // Channel ID
username?: string; // Username
}

SocialLoginParams​

Social login configuration:

interface SocialLoginParams {
socialplat: string; // Social platform (google/facebook)
id: string; // Social platform user ID
name?: string; // User's name
email?: string; // User's email
picture?: string; // User's profile picture URL
}

ConnectionCallbacks​

Connection state monitoring:

interface ConnectionCallbacks {
onConnectionLost?: (errorCode: number, errorMsg: string) => void;
onConnected?: (isReconnect: boolean, URI: string) => void;
onSuccessConnect?: () => void;
onFailureConnect?: () => void;
}

LeaderboardParams​

Leaderboard operation parameters:

interface LeaderboardParams {
leaderboardid?: string; // Leaderboard ID
score?: number; // Score value
collection?: number; // Collection (0=social, 1=global)
timespan?: number; // Timespan (0=all-time, 1=weekly, 2=daily)
maxresults?: number; // Maximum results to return
onlyData?: boolean; // Return only data without metadata
callback?: CallbackFunction;
}

ScoreSubmitParams​

Score submission parameters:

interface ScoreSubmitParams {
leaderboardid: string; // Leaderboard ID (required)
score: number; // Score value (required)
scoretag?: string; // Additional score metadata
callback?: CallbackFunction;
}

TournamentParams​

Tournament operation parameters:

interface TournamentParams {
tournamentid?: string; // Tournament ID
subtournamentid?: string; // Sub-tournament ID
callback?: CallbackFunction;
}

Real-Time Multiplayer Types​

RTMStandardParams​

Standard room creation parameters:

interface RTMStandardParams {
maxPlayers: number; // Maximum players (required)
variant: number; // Room variant (required)
minPlayers?: number; // Minimum players (optional)
}

RTMEndlessParams​

Endless room creation parameters:

interface RTMEndlessParams {
maxPlayers: number; // Maximum players (required)
variant: number; // Room variant (required)
}

RealTimeMessage​

Real-time message structure:

interface RealTimeMessage {
senderId: string; // Message sender ID
data: ArrayBuffer; // Message data
isReliable: boolean; // Message reliability
timestamp: number; // Message timestamp
}

Utility Types​

StorageData​

Local storage data structure:

interface StorageData {
playerid: string; // Player ID
playerinfo: any; // Player information
}

UnityCallback​

Unity integration callback:

interface UnityCallback {
object_name: string; // Unity object name
method_name: string; // Unity method name
}

Enums​

RoomStatus​

Room status values:

enum RoomStatus {
LOBBY = 0, // In lobby
PLAYING = 1, // Playing
FINISHED = 2 // Finished
}

ParticipantStatus​

Participant status values:

enum ParticipantStatus {
INVITED = 0, // Invited
JOINED = 1, // Joined
READY = 2, // Ready
PLAYING = 3, // Playing
DISCONNECTED = 4 // Disconnected
}

LogLevel​

Logging levels:

enum LogLevel {
DEBUG = 1, // Debug messages
INFO = 2, // Info messages
ERROR = 3 // Error messages
}

Type Guards​

Create type guards for better type safety:

const isSignedInProfile = (obj: any): obj is SignedInProfile => {
return obj &&
typeof obj.id === 'string' &&
typeof obj.name === 'string' &&
Array.isArray(obj.friends);
};

const isPlayer = (obj: any): obj is Player => {
return obj &&
typeof obj.playerID === 'string' &&
typeof obj.playerName === 'string' &&
typeof obj.iconImageURL === 'string';
};

// Usage
const handleProfile = (profile: any) => {
if (isSignedInProfile(profile)) {
console.log('Valid profile:', profile.name);
// TypeScript knows this is SignedInProfile
}
};

Next Steps​

tip

Use TypeScript's type inference and type guards to ensure runtime type safety when working with API responses.