Installation
Learn how to install the Moitribe JavaScript SDK in your project using different methods.
Prerequisites
Before installing the SDK, ensure you have:
- A Moitribe account and game ID (contact the Veniso team)
- Node.js 14+ (for npm installation)
- A modern web browser or Node.js environment
Installation Methods
NPM Installation (Recommended)
Install the SDK as a dependency in your project:
npm install @veniso/moitribe-js
The SDK is currently a private package. Contact the Veniso team for access credentials.
Git Repository Installation
Install directly from the Git repository:
npm install git+ssh://git@github.com:veniso/moitribe-js-sdk.git
Or add to your package.json:
{
"dependencies": {
"@veniso/moitribe-js": "git+ssh://git@github.com:veniso/moitribe-js-sdk.git"
}
}
Local Path Installation (Development)
For local development or testing:
npm install /path/to/moitribe-js-sdk
CDN Installation
Include the SDK directly in your HTML file:
<!DOCTYPE html>
<html>
<head>
<title>My Game</title>
</head>
<body>
<!-- Your game content -->
<!-- Moitribe SDK -->
<script src="node_modules/@veniso/moitribe-js/dist/moitribe-sdk.min.js"></script>
<script>
// SDK is available as MoitribeSDK
console.log('Moitribe SDK loaded:', typeof MoitribeSDK);
</script>
</body>
</html>
Usage by Environment
Browser (ES6 Modules)
Import the SDK in modern JavaScript:
import MoitribeSDK from '@veniso/moitribe-js';
// Initialize the SDK
MoitribeSDK('your-game-id', 'init', {
loginCallback: (result) => {
if (result.success) {
console.log('Player logged in:', result.playerdata);
}
}
});
Browser (CommonJS)
For older bundlers or require syntax:
const MoitribeSDK = require('@veniso/moitribe-js');
// Initialize the SDK
MoitribeSDK('your-game-id', 'init', {
loginCallback: (result) => {
if (result.success) {
console.log('Player logged in:', result.playerdata);
}
}
});
Browser (Script Tag)
When using the CDN or script tag:
<script src="node_modules/@veniso/moitribe-js/dist/moitribe-sdk.min.js"></script>
<script>
// SDK is available globally as MoitribeSDK
MoitribeSDK('your-game-id', 'init', {
loginCallback: function(result) {
if (result.success) {
console.log('Player logged in:', result.playerdata);
}
}
});
</script>
Node.js
Use the SDK in Node.js applications:
const MoitribeSDK = require('@veniso/moitribe-js');
// Initialize the SDK
MoitribeSDK('your-game-id', 'init', {
loginCallback: (result) => {
if (result.success) {
console.log('Player logged in:', result.playerdata);
}
}
});
TypeScript
Import with full type support:
import MoitribeSDK, {
GameInitParams,
SignedInProfile
} from '@veniso/moitribe-js';
// Initialize with types
const params: GameInitParams = {
loginCallback: (result: { success: boolean; playerdata?: SignedInProfile }) => {
if (result.success && result.playerdata) {
console.log('Player:', result.playerdata.name);
}
}
};
MoitribeSDK('your-game-id', 'init', params);
Build Tools Configuration
Webpack
The SDK works out of the box with Webpack. No special configuration needed:
// webpack.config.js
module.exports = {
// Your webpack configuration
resolve: {
extensions: ['.js', '.ts', '.json']
}
};
Vite
Add to your Vite project:
// vite.config.js
import { defineConfig } from 'vite';
export default defineConfig({
// Your Vite configuration
optimizeDeps: {
include: ['@veniso/moitribe-js']
}
});
Rollup
Configure Rollup to bundle the SDK:
// rollup.config.js
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
export default {
input: 'src/main.js',
output: {
file: 'dist/bundle.js',
format: 'iife'
},
plugins: [
resolve(),
commonjs()
]
};
Parcel
Parcel works with zero configuration:
npm install @veniso/moitribe-js
// src/index.js
import MoitribeSDK from '@veniso/moitribe-js';
MoitribeSDK('your-game-id', 'init', {
loginCallback: (result) => console.log(result)
});
TypeScript Configuration
If using TypeScript, ensure your tsconfig.json includes:
{
"compilerOptions": {
"target": "ES2015",
"module": "ESNext",
"moduleResolution": "node",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"skipLibCheck": true
}
}
The SDK includes full TypeScript definitions, so you'll get autocomplete and type checking automatically.
Verifying Installation
After installation, verify the SDK is working:
import MoitribeSDK, { VERSION } from '@veniso/moitribe-js';
console.log('Moitribe SDK Version:', VERSION); // Should print: 1.4.2
Troubleshooting Installation
Module Not Found Error
If you see "Cannot find module '@veniso/moitribe-js'":
- Ensure the package is installed:
npm list @veniso/moitribe-js - Delete
node_modulesand reinstall:rm -rf node_modules && npm install - Check that you have access to the private repository
Type Definition Errors
If TypeScript can't find type definitions:
- Ensure
@types/nodeis installed:npm install --save-dev @types/node - Check your
tsconfig.jsonincludes"esModuleInterop": true - Restart your TypeScript server/IDE
Bundle Size Issues
If your bundle is too large:
- Ensure you're using the production build
- Enable tree-shaking in your bundler
- Use dynamic imports for RTM features if not needed immediately
For the smallest bundle size, import only what you need:
import { GameService, LeaderboardService } from '@veniso/moitribe-js';
Next Steps
Now that you have the SDK installed, learn how to:
- Initialize the SDK and understand basic concepts
- Authenticate players using OTP or social login
- Submit scores to leaderboards
- Create multiplayer rooms for real-time gameplay
Continue to Getting Started to initialize the SDK.