Skip to main content

Minigame Management

1 Game Startup Parameter Settings​

Interface Prototype

void setGameStartOptions(Bundle options, OnTJHostHandleListener listener)

Parameter Description

parameterData TypeRequiredAttribute Description
optionsandroid.os.BundleYesGame initialization parameters, the following is the specific parameter list
TJRuntimeConstants.LAUNCH_KEYStringYesGame launch items, supporting three types: game list launch items, QR code scan launch items, and recent launch items.
TJRuntimeConstants.USER_IDStringYesGame User
TJConstants.GAME_ENTRY_JSStringNoGame entry JavaScript file name, value limited to game.js or main.js
TJConstants.ENABLE_DEBUGGERbooleanNoEnable debugging, default value is false
TJConstants.ENABLE_VCONSOLEbooleanNoEnable vConsole. Changing the enable or disable setting requires restarting the game, with the default value being false.
TJConstants.ENABLE_PERFORMANCE_MONITORINGbooleanNoEnable performance monitoring, default value is false
TJConstants.ENABLE_CPU_PROFILERbooleanNoEnable CPU Profile, default value is false
TJConstants.ENABLE_RUNTIME_CSHARP_DEBUGGERbooleanNoEnable C# code debugging, default value is false
TJConstants.NETWORK_TIMEOUTlongNoNetwork timeout, in milliseconds. The default value is 60000
TJConstants.BUILTIN_CUSTOM_SCRIPTS_PATHStringNoPath to load the extension interface file custom.js
TJConstants.SHOW_MENU_LAYOUTbooleanNoEnable menu capsule button, default value is true
TJConstants.PIXEL_RATIOfloatNoSet pixel ratio
TJConstants.ENABLE_INSPECTORbooleanNoEnable Chrome DevTools debugging, default value is false
TJConstants.INSPECTOR_PORTintNoChrome DevTools Debugging Listening Port
TJConstants.INSPECTOR_HOSTStringNoChrome DevTools Debugging Host
TJConstants.INSPECTOR_WAIT_FOR_INSPECTbooleanNoWait for DevTools to connect on startup, default value is false
TJConstants.INSPECTOR_PAGE_INSPECTIONbooleanNoEnable Chrome DevTools Screencast, default value false
TJConstants.DOMAIN_WHITELIST_REQUESTArrayList\<String>NoRequest legal domain names, starting with https://, up to 300 domain names can be filled in
TJConstants.DOMAIN_WHITELIST_SOCKETArrayList\<String>NoValid socket domain names, starting with wss://, can have up to 200 domain names filled in
TJConstants.DOMAIN_WHITELIST_UDPArrayList\<String>NoUDP 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_TCPArrayList\<String>NoA 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_FILEArrayList\<String>NoLegal domains for uploadFile, starting with https://, can fill in 200 domains
TJConstants.ENABLE_TRANSPARENT_MODEbooleanNoDoes it support transparent game background?
TJRuntimeConstants.SHOW_MENU_EXPLORE_BTNbooleanNoWhether to display the capsule button ··· More button
TJRuntimeConstants.SPLASH_ICON_URLStringNoGame Loading Page Image URL
TJRuntimeConstants.SPLASH_GAME_TITLEStringNoGame Title on Game Loading Page
TJRuntimeConstants.SPLASH_CAPSULE_RESERVE_STATUS_BARbooleanNoWhether 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 launchKey field, which needs to be passed as a launch parameter to LAUNCH_KEY when launching the game.

    • launchKey: 67da9d2961b25a25faf0b143
  • 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
  • Recently Played List Launch: The Recently Played object also contains the launchKey field, which is also passed as a launch parameter to LAUNCH_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

parameterData TypeRequiredAttribute Description
onShowMsgStringNoDisplay String
listenerOnTJHostHandleListenerNoonSuccess/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

parameterData TypeRequiredAttribute Description
listenerOnTJHostHandleListenerNoonSuccess/onFailure callback

4 Pause Game​

Pause the game, host state changes to RUNNING .

Interface Prototype

void pause(OnTJHostHandleListener listener)

Parameter Description

parameterData TypeRequiredAttribute Description
listenerOnTJHostHandleListenerNoonSuccess/onFailure callback

5 End Game​

End the game, host state changes to WAITING.

Interface Prototype

void stop(String onHideMsg, OnTJHostHandleListener listener)

Parameter Description

parameterData TypeRequiredAttribute Description
onHideMsgStringNoHidden string
listenerOnTJHostHandleListenerNoonSuccess/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

parameterData TypeRequiredAttribute Description
listenerOnTJFirstFrameRenderedListenerNoFirst 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

parameterData TypeRequiredAttribute Description
listenerOnTJHostGamePackageDownloadHandleListenerNoGame package download callback