Minigame Management
1 Game Startup Parameter Settings
1.1 Initialize game startup parameters
Interface Prototype
func setGameStartOptions(options: [String: Any], completion: @escaping (HostRuntimeError?) -> Void)
Parameter Description
| parameter | Data Type | Required | Attribute Description |
|---|---|---|---|
LAUNCH_KEY | String | Yes | Game launch items, supporting three types: game list launch items, QR code scan launch items, and recent launch items. |
USER_ID | String | Yes | Game User |
CUSTOM_SCRIPT_FILES | [String] | No | List of JS script files |
CUSTOM_SCRIPT_CONTENTS | [String] | No | Javascript Text |
ENABLE_VCONSOLE | Bool | No | Enable vConsole. Changing the enable or disable setting requires restarting the game. The default value is false |
ENABLE_INSPECTOR | Bool | No | Enable Safari DevTools debugging, default value is false |
INSPECTOR_WAIT_FOR_INSPECT | Bool | No | Wait for DevTools to connect on startup, default value is false |
ENABLE_DOMAIN_WHITELIST | Bool | No | Enable the legal domain allowlist, with the default value being false |
DOMAIN_WHITELIST_REQUEST | [String] | No | Request legal domain names, starting with https://, up to 300 domain names can be filled in |
DOMAIN_WHITELIST_SOCKET | [String] | No | Valid socket domain names, starting with wss://, can have up to 200 domain names filled in |
DOMAIN_WHITELIST_UDP | [String] | No | Legal UDP domain names, starting with udp://, can have up to 200 domain names filled in. Note: IP addresses obtained through DNS resolution can also pass the allowlist |
DOMAIN_WHITELIST_TCP | [String] | No | tcp legal domain names, starting with tcp://, can fill in 200 domain names. Note: IP addresses obtained through DNS resolution can also pass the allowlist |
DOMAIN_WHITELIST_UPLOAD_FILE | [String] | No | Legal domains for uploadFile, starting with https://, up to 200 domains can be filled in |
DOMAIN_WHITELIST_DOWNLOAD_FILE | [String] | No | Legal domains for downloadFile, starting with https://, up to 200 domains can be filled in |
ENABLE_REPORT_MEMORY | boolean | No | Statistics memory information, default value is false |
ENABLE_REPORT_CPU | boolean | No | Statistics cpu information, default value is false |
ENABLE_REPORT_FPS | boolean | No | Statistics related to frame rate information, including fps, jank, and bigJank, with a default value of false |
SPLASH_GAME_TITLE | String | No | Replace the game title on the Splash page |
SPLASH_ICON_URL | String | No | Replace the game icon on the Splash page |
SHOW_MENU_EXPLORE_BTN | Bool | No | Open the top-right menu button. The default value is true |
SHOW_MENU_LAYOUT | Bool | No | Enable top-right layout, default value is true |
ENABLE_TRANSPARENT_MODE | Bool | No | Enable game transparent background, default value is false |
Code Example
func setGameStartOptions() {
if let gameHandle {
var options: [String: Any] = [
TJConstants.LAUNCH_KEY: launchKey,
TJConstants.USER_ID: "gust",
TJConstants.ENABLE_VCONSOLE: true,
]
gameHandle.setGameStartOptions(options: options) { error in
guard error == nil else {
return
}
}
}
}
1.2 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
func start(onShowMsg: String, completion: @escaping (Error?) -> Void)
Parameter Description
| parameter | Data Type | Required | Attribute Description |
|---|---|---|---|
onShowMsg | String | No | Display String |
completion | (Error?) -> Void | No | Callback after start |
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
func play()
4 Pause Game
Pause the game, host state changes to RUNNING .
Interface Prototype
func pause()
5 End Game
End the game, host state changes to WAITING.
Interface Prototype
func stop()
6 Set Host First Frame Rendering Listener
Provides a callback after the host's first frame is rendered
Interface Prototype
func setOnFirstFrameRenderedListener(callback: @escaping () -> Void)
Parameter Description
| parameter | Data Type | Required | Attribute Description |
|---|---|---|---|
callback | () -> Void | Yes | 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
func setOnGamePackageDownloadListener(
onStart: @escaping () -> Void,
onProgress: @escaping (Double, Int64, Int64) -> Void,
onSuccess: @escaping () -> Void,
onFailure: @escaping (Error?) -> Void)
Parameter Description
| parameter | Data Type | Required | Attribute Description |
|---|---|---|---|
onStart | () -> Void | Yes | Callback for the start of game package download |
onProgress | (progress: Double, totalBytesWritten: Int64, totalBytesExpectedToWrite: Int64) -> Void | Yes | Game package download progress callback
|
onSuccess | () -> Void | Yes | Callback for successful game package download |
onFailure | (Error?) -> Void | Yes | Callback for game package download failure |
8. Set up the host game to listen for screen orientation changes
Interface Prototype
func setOnGameChangeOrientationListener(
callback: @escaping (UIInterfaceOrientation, @escaping (Bool) -> Void)
Parameter Description
| parameter | Data Type | Required | Attribute Description |
|---|---|---|---|
callback | (UIInterfaceOrientation, @escaping (Bool) -> Void | Yes | Orientation change callback |