Subpackage Loading
JSBridge APIs for managing the download and execution of subpackages.
Note: The difference between TTMinis.game.preDownloadSubpackage and TTMinis.game.loadSubpackage:
TTMinis.game.preDownloadSubpackageonly downloads the code package without automatically executing the code.TTMinis.game.loadSubpackagewill automatically execute the code after downloading the code package.
TTMinis.game.preDownloadSubpackage(opts)
Triggers subpackage pre-download.
Parameters
Field | Type | Description | Required |
|
| The name of the subpackage | Yes |
|
| Callback function called when the subpackage download succeeds | Yes |
|
| Callback function called when the subpackage download fails | Yes |
|
| Callback function called when the subpackage download ends (called on both success and failure) | Yes |
Returns
A PreDownloadSubpackageTask instance for monitoring the subpackage pre-download progress.
Example
var task = TTMinis.game.preDownloadSubpackage({
name: "ModuleA", success(res) {
console.log("load subpackage success", res)
TTMinis.game.loadSubpackage({
name: "ModuleA", success(res) {
console.log(res)
},
})
}, fail(res) {
console.log("load subpackage fail", res)
}
})
task.onProgressUpdate(res => {
console.log(res.progress)
console.log(res.totalBytesWritten)
console.log(res.totalBytesExpectedToWrite)
})TTMinis.game.loadSubpackage(opts)
Triggers subpackage loading and execution.
Parameters
Field | Type | Description | Required |
|
| The name of the subpackage | Yes |
|
| Callback function called when the subpackage loading succeeds | Yes |
|
| Callback function called when the subpackage loading fails | Yes |
|
| Callback function called when the subpackage loading ends (called on both success and failure) | Yes |
Returns
A LoadSubpackageTask instance for monitoring the subpackage loading progress.
Note: The difference between TTMinis.game.preDownloadSubpackage and TTMinis.game.loadSubpackage is that preDownloadSubpackage only downloads the code package without executing the code, while loadSubpackage downloads and automatically executes the code after download completes.
LoadSubpackageTask.onProgressUpdate(listener)
Registers a listener for subpackage loading progress change events.
Parameters
Field | Type | Description | Required |
|
| The listener function for subpackage loading progress change events | Yes |
Listener callback parameters
Field | Type | Description |
|
| Subpackage download progress percentage |
|
| Number of bytes downloaded so far |
|
| Total number of bytes expected to be downloaded |
PreDownloadSubpackageTask.onProgressUpdate(listener)
Registers a listener for subpackage pre-download progress change events.
Parameters
Field | Type | Description | Required |
|
| The listener function for subpackage pre-download progress change events | Yes |
Listener callback parameters
Field | Type | Description |
|
| Subpackage download progress percentage |
|
| Number of bytes downloaded so far |
|
| Total number of bytes expected to be downloaded |