Minigame Management
1 Game Startup Parameter Settings
Interface Prototype
void setGameStartOptions(Bundle options, OnTJHostHandleListener listener)
Parameter Description
| parameter | Data Type | Required | Attribute Description |
|---|---|---|---|
| options | android.os.Bundle | Yes | Game initialization parameters, the following is the specific parameter list |
| TJRuntimeConstants.LAUNCH_KEY | String | Yes | Game launch items, supporting three types: game list launch items, QR code scan launch items, and recent launch items. |
| TJRuntimeConstants.USER_ID | String | Yes | Game User |
| TJConstants.GAME_ENTRY_JS | String | No | Game entry JavaScript file name, value limited to game.js or main.js |
| TJConstants.ENABLE_DEBUGGER | boolean | No | Enable debugging, default value is false |
| TJConstants.ENABLE_VCONSOLE | boolean | No | Enable vConsole. Changing the enable or disable setting requires restarting the game, with the default value being false. |
| TJConstants.ENABLE_PERFORMANCE_MONITORING | boolean | No | Enable performance monitoring, default value is false |
| TJConstants.ENABLE_CPU_PROFILER | boolean | No | Enable CPU Profile, default value is false |
| TJConstants.ENABLE_RUNTIME_CSHARP_DEBUGGER | boolean | No | Enable C# code debugging, default value is false |
| TJConstants.NETWORK_TIMEOUT | long | No | Network timeout, in milliseconds. The default value is 60000 |
| TJConstants.BUILTIN_CUSTOM_SCRIPTS_PATH | String | No | Path to load the extension interface file custom.js |
| TJConstants.SHOW_MENU_LAYOUT | boolean | No | Enable menu capsule button, default value is true |
| TJConstants.PIXEL_RATIO | float | No | Set pixel ratio |
| TJConstants.ENABLE_INSPECTOR | boolean | No | Enable Chrome DevTools debugging, default value is false |
| TJConstants.INSPECTOR_PORT | int | No | Chrome DevTools Debugging Listening Port |
| TJConstants.INSPECTOR_HOST | String | No | Chrome DevTools Debugging Host |
| TJConstants.INSPECTOR_WAIT_FOR_INSPECT | boolean | No | Wait for DevTools to connect on startup, default value is false |
| TJConstants.INSPECTOR_PAGE_INSPECTION | boolean | No | Enable Chrome DevTools Screencast, default value false |
| TJConstants.DOMAIN_WHITELIST_REQUEST | ArrayList\<String> | No | Request legal domain names, starting with https://, up to 300 domain names can be filled in |
| TJConstants.DOMAIN_WHITELIST_SOCKET | ArrayList\<String> | No | Valid socket domain names, starting with wss://, can have up to 200 domain names filled in |
| TJConstants.DOMAIN_WHITELIST_UDP | ArrayList\<String> | No | UDP legal domain names, starting with udp://, can fill in 200 domain names. Note: IP addresses obtained through DNS resolution can also pass the allowlist |
| TJConstants.DOMAIN_WHITELIST_TCP | ArrayList\<String> | No | A valid TCP domain name, starting with tcp://, can have up to 200 domain names filled in. Note: IP addresses obtained through DNS resolution can also pass the allowlist |
| TJConstants.DOMAIN_WHITELIST_UPLOAD_FILE | ArrayList\<String> | No | Legal domains for uploadFile, starting with https://, can fill in 200 domains |
| TJConstants.ENABLE_TRANSPARENT_MODE | boolean | No | Does it support transparent game background? |
| TJRuntimeConstants.SHOW_MENU_EXPLORE_BTN | boolean | No | Whether to display the capsule button ··· More button |
| TJRuntimeConstants.SPLASH_ICON_URL | String | No | Game Loading Page Image URL |
| TJRuntimeConstants.SPLASH_GAME_TITLE | String | No | Game Title on Game Loading Page |
| TJRuntimeConstants.SPLASH_CAPSULE_RESERVE_STATUS_BAR | boolean | No | Whether the capsule button additionally reserves the height of the system status bar at the top |
Code Example
private TJHostHandle hostHandle;
...
Bundle bundle = new Bundle();
bundle.putString(TJConstants.GAME_ID, "gameid");
gameHandle.setGameStartOptions(bundle, new OnTJHostHandleListener() {
@Override
public void onSuccess() {
// startGame();
}
@Override
public void onFailure(Throwable throwable) {
Log.e(TAG, "Host set game start options failure", throwable);
}
});
1.1 Explanation of Game Launch Parameter LAUNCH_KEY
Currently, the game supports three startup methods: startup from the game list, startup by scanning a QR code, and startup from the recently played list.
-
Game list launch: The object returned by the game list interface contains the
launchKeyfield, which needs to be passed as a launch parameter toLAUNCH_KEYwhen launching the game.- launchKey:
67da9d2961b25a25faf0b143
- launchKey:
-
QR Code Scanning Launch: The result of scanning the QR code is passed as a launch parameter to
LAUNCH_KEY.- QR code scanning result:
https://minihost.tuanjie.cn/api/game_app/67da9d2961b25a25faf0b143/temp_session/a0f06587-3def-4a3a-95b2-89286bc325fa/start
- QR code scanning result:
-
Recently Played List Launch: The Recently Played object also contains the
launchKeyfield, which is also passed as a launch parameter toLAUNCH_KEY. For details, refer to Recently Played List-
launchKey when game list starts:
67da9d2961b25a25faf0b143 -
When the QR code scanning experience is launched, launchKey:
67da9d2961b25a25faf0b143:67dcc8227ae013b09d23ad23
-
2 Start the Game
Load and compile game resources, the game interface is visible but not interactive, and the host state changes to RUNNING.
Interface Prototype
void start(String onShowMsg, OnTJHostHandleListener listener)
Parameter Description
| parameter | Data Type | Required | Attribute Description |
|---|---|---|---|
| onShowMsg | String | No | Display String |
| listener | OnTJHostHandleListener | No | onSuccess/onFailure callback |
3 Run/Resume Game
The game can be interacted with or resume running when the app switches to the foreground, and the host state changes to PLAYING .
Interface Prototype
void play(OnTJHostHandleListener listener)
Parameter Description
| parameter | Data Type | Required | Attribute Description |
|---|---|---|---|
| listener | OnTJHostHandleListener | No | onSuccess/onFailure callback |
4 Pause Game
Pause the game, host state changes to RUNNING .
Interface Prototype
void pause(OnTJHostHandleListener listener)
Parameter Description
| parameter | Data Type | Required | Attribute Description |
|---|---|---|---|
| listener | OnTJHostHandleListener | No | onSuccess/onFailure callback |
5 End Game
End the game, host state changes to WAITING.
Interface Prototype
void stop(String onHideMsg, OnTJHostHandleListener listener)
Parameter Description
| parameter | Data Type | Required | Attribute Description |
|---|---|---|---|
| onHideMsg | String | No | Hidden string |
| listener | OnTJHostHandleListener | No | onSuccess/onFailure callback |
6 Set Host First Frame Rendering Listener
Provides a callback after the host's first frame is rendered
Interface Prototype
void setOnFirstFrameRenderedListener(OnTJFirstFrameRenderedListener listener)
Parameter Description
| parameter | Data Type | Required | Attribute Description |
|---|---|---|---|
| listener | OnTJFirstFrameRenderedListener | No | First Frame Callback |
7 Set the callback for host game package download
Provides a callback mechanism for downloading the host game package. This callback will only be triggered when the game package is downloaded for the first time. If the game package is only read from the cache, this callback will not be triggered.
Interface Prototype
void setOnGamePackageDownloadListener(OnTJHostGamePackageDownloadHandleListener listener)
Parameter Description
| parameter | Data Type | Required | Attribute Description |
|---|---|---|---|
| listener | OnTJHostGamePackageDownloadHandleListener | No | Game package download callback |