Skip to main content

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

parameterData TypeRequiredAttribute Description
LAUNCH_KEYStringYesGame launch items, supporting three types: game list launch items, QR code scan launch items, and recent launch items.
USER_IDStringYesGame User
CUSTOM_SCRIPT_FILES[String]NoList of JS script files
CUSTOM_SCRIPT_CONTENTS[String]NoJavascript Text
ENABLE_VCONSOLEBoolNoEnable vConsole. Changing the enable or disable setting requires restarting the game. The default value is false
ENABLE_INSPECTORBoolNoEnable Safari DevTools debugging, default value is false
INSPECTOR_WAIT_FOR_INSPECTBoolNoWait for DevTools to connect on startup, default value is false
ENABLE_DOMAIN_WHITELISTBoolNoEnable the legal domain allowlist, with the default value being false
DOMAIN_WHITELIST_REQUEST[String]NoRequest legal domain names, starting with https://, up to 300 domain names can be filled in
DOMAIN_WHITELIST_SOCKET[String]NoValid socket domain names, starting with wss://, can have up to 200 domain names filled in
DOMAIN_WHITELIST_UDP[String]NoLegal 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]Notcp 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]NoLegal domains for uploadFile, starting with https://, up to 200 domains can be filled in
DOMAIN_WHITELIST_DOWNLOAD_FILE[String]NoLegal domains for downloadFile, starting with https://, up to 200 domains can be filled in
ENABLE_REPORT_MEMORYbooleanNoStatistics memory information, default value is false
ENABLE_REPORT_CPUbooleanNoStatistics cpu information, default value is false
ENABLE_REPORT_FPSbooleanNoStatistics related to frame rate information, including fps, jank, and bigJank, with a default value of false
SPLASH_GAME_TITLEStringNoReplace the game title on the Splash page
SPLASH_ICON_URLStringNoReplace the game icon on the Splash page
SHOW_MENU_EXPLORE_BTNBoolNoOpen the top-right menu button. The default value is true
SHOW_MENU_LAYOUTBoolNoEnable top-right layout, default value is true
ENABLE_TRANSPARENT_MODEBoolNoEnable 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 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

func start(onShowMsg: String, completion: @escaping (Error?) -> Void)

Parameter Description

parameterData TypeRequiredAttribute Description
onShowMsgStringNoDisplay String
completion(Error?) -> VoidNoCallback 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

parameterData TypeRequiredAttribute Description
callback() -> VoidYesFirst 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

parameterData TypeRequiredAttribute Description
onStart() -> VoidYesCallback for the start of game package download
onProgress(progress: Double, totalBytesWritten: Int64, totalBytesExpectedToWrite: Int64) -> VoidYesGame package download progress callback
  • progress: Download Progress
  • totalBytesWritten: Downloaded Size
  • totalBytesExpectedToWrite: File Size
onSuccess() -> VoidYesCallback for successful game package download
onFailure(Error?) -> VoidYesCallback 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

parameterData TypeRequiredAttribute Description
callback(UIInterfaceOrientation, @escaping (Bool) -> VoidYesOrientation change callback