This SDK lets developers integrate their game with VIT-RIN which is a digital wallet that collects game scores and rewards players.
Follow these steps to just start integrating:
Use any package manager like npm or yarn to install the JavaScript SDK.
Npm:
npm i @vit-rin/games-js
Yarn:
yarn add @vit-rin/games-js
Import as ES module:
import { VitGames } from "@vit-rin/games-js";
Import from CDN:
<script src="https://cdn.jsdelivr.net/npm/@vit-rin/games-js@latest/build/vitgames.browser.js"></script>
Create new instance of VitGames and pass your game ID to it:
const vitrin = new VitGames({ gameId: "YOUR_GAME_ID" });
By default, The SDK automatically checks and handles authentication. If you need to turn it off, set autoCheckAuth
to false
in the options.
{
autoCheckAuth: false;
}
By default, The SDK automatically raises and handles ads. If you need to turn it off, set autoOpenAds
to false
in the options.
{
autoOpenAds: false;
}
These callbacks used to control the game. They are called when the game is started, paused, resumed, replayed, muted, or unmuted.
For best results, You should have at least 3 callbacks for startCallback
, pauseCallback
, resumeCallback
.
If you don't set replayCallback
, the startCallback
will be called instead.
By ignoring the pauseCallback
or resumeCallback
or muteCallback
or unmuteCallback
callbacks, the relevant controls in UI such as the pause button or the mute button will be disabled.
var vitrin = new VitGames({
startCallback: myStartGame,
pauseCallback: myPauseGame,
resumeCallback: myResumeGame,
replayCallback: myResetGame,
muteCallback: myMuteGame,
unmuteCallback: myUnmuteGame,
});
Let SDK be synced with current score by setting it in every score increment. Call set()
method of the score object and pass the score number.
vitrin.score.set(SCORE_NUMBER);
When the game is ended, call ended()
method of the game object to end the game and send the score to server and get the result.
vitrin.game.ended();
Here is the default options:
export const DefaultOptions: OptionsType = {
gameId: null,
startCallback: undefined,
pauseCallback: undefined,
resumeCallback: undefined,
replayCallback: undefined,
muteCallback: undefined,
unmuteCallback: undefined,
useUI: true,
preventDefault: true,
autoCheckAuth: true,
autoOpenAds: true,
};
git clone git@github.com:vit-rin/vitrin-games-js.git
cd ./vitrin-games-js/
npm i
To build UMD bundles, run:
npm run build