dg-minigame-widget
v1.0.1
Published
A UMD module widget for displaying mini-games, compatible with any JavaScript environment.
Downloads
4
Readme
DG Minigame Widget
The DG Minigame Widget is a JavaScript library designed to provide easy integration of mini-games into websites, supporting multiple languages and dynamic game loading.
Installation
Install using npm:
npm install dg-minigame-widget
How to Use
First, you need to import the dg-minigame-widget and its associated CSS file into your project:
import dgMinigameWidget from "dg-minigame-widget";
import "dg-minigame-widget/dg-minigame-widget.css";
Initialize the Mini-Game Component
You can initialize the mini-game component by providing the necessary options:
dgMinigameWidget.initialize({
displayGameIds: [
"baccarat-mini",
"thai-hi-lo-mini",
"seven-up-down-mini",
// Add more game IDs as needed.
],
lang: "en", // Modify as needed for your target audience.
getGameUrlAsyncFn: async (gameId: string) => {
// This function must be asynchronous and return an object containing the game launch URL.
const response = await fetch(`http://localhost:4000/games/${gameId}`);
const data = await response.json();
return {
id: gameId,
gameLaunchUrl: data.gameLaunchUrl, // Ensure your server response includes 'gameLaunchUrl'.
};
},
gameStatusUrl: "https://xxxx.com/mini-games-status",
// the status url for checking game status
});
API
initialize(options): Initializes the game component, options include:
- Display Game IDs: Set
displayGameIds
to the list of game IDs that you want to include in the widget. - Language: Specify the
lang
option to set the language of the widget. Currently supported languages are English ("en"), Thai ("th"), and Vietnamese ("vn"). - Additional Arguments: Adjust the
getGameUrlAsyncFn
andgameStatusUrl
to match your backend configurations. make sure it return an object withgameLaunchUrl:string