@inappstory/game-center-api 1.0.8 → 1.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/ResourceManager.d.ts +7 -0
- package/lib/ResourceManager.js +38 -16
- package/lib/index.d.ts +3 -2
- package/lib/index.js +3 -1
- package/package.json +2 -2
package/lib/ResourceManager.d.ts
CHANGED
|
@@ -17,6 +17,13 @@ export declare class ResourceManager {
|
|
|
17
17
|
private addResourceToCacheTree;
|
|
18
18
|
private createCacheTree;
|
|
19
19
|
cacheAllResources(): Promise<void>;
|
|
20
|
+
cacheResource({ uri, originUri, resouceKeys, onSuccess, onFail, }: {
|
|
21
|
+
uri: string;
|
|
22
|
+
originUri?: string;
|
|
23
|
+
resouceKeys?: string[];
|
|
24
|
+
onSuccess: (objectUrl: string | null) => void;
|
|
25
|
+
onFail: () => void;
|
|
26
|
+
}): Promise<void>;
|
|
20
27
|
private createObjectUrlByUri;
|
|
21
28
|
revokeCache(): void;
|
|
22
29
|
}
|
package/lib/ResourceManager.js
CHANGED
|
@@ -45,17 +45,26 @@ class ResourceManager {
|
|
|
45
45
|
const promise = ((resourceForFetch, relatedResources) => {
|
|
46
46
|
return new Promise(async (resolve, reject) => {
|
|
47
47
|
const resouceKeys = relatedResources.map(resource => resource.key);
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
48
|
+
const uri = resourceForFetch.getUri();
|
|
49
|
+
const originUri = resourceForFetch.getOriginUri();
|
|
50
|
+
await this.cacheResource({
|
|
51
|
+
uri,
|
|
52
|
+
originUri,
|
|
53
|
+
resouceKeys,
|
|
54
|
+
onSuccess: objectUrl => {
|
|
55
|
+
if (objectUrl === null) {
|
|
56
|
+
resolve();
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
for (const resource of relatedResources) {
|
|
60
|
+
resource.setCacheUri(objectUrl);
|
|
61
|
+
}
|
|
62
|
+
resolve();
|
|
63
|
+
},
|
|
64
|
+
onFail: () => {
|
|
65
|
+
reject(`Can't load resource for [${resouceKeys.join(", ")}]`);
|
|
66
|
+
},
|
|
67
|
+
});
|
|
59
68
|
});
|
|
60
69
|
})(resourceForFetch, relatedResources);
|
|
61
70
|
promises.push(promise);
|
|
@@ -64,18 +73,31 @@ class ResourceManager {
|
|
|
64
73
|
for (const resList of this.resLists)
|
|
65
74
|
resList["onCacheDone"]();
|
|
66
75
|
}
|
|
67
|
-
async
|
|
68
|
-
|
|
69
|
-
|
|
76
|
+
async cacheResource({ uri, originUri = uri, resouceKeys = ["outerResource"], onSuccess, onFail, }) {
|
|
77
|
+
let objectUrl = await this.createObjectUrlByUri(uri, resouceKeys);
|
|
78
|
+
if (objectUrl === null && uri !== originUri)
|
|
79
|
+
objectUrl = await this.createObjectUrlByUri(originUri, resouceKeys);
|
|
80
|
+
if (objectUrl === null) {
|
|
81
|
+
const image = new Image();
|
|
82
|
+
image.onload = () => onSuccess(null);
|
|
83
|
+
image.onerror = () => onFail();
|
|
84
|
+
image.src = originUri;
|
|
85
|
+
}
|
|
86
|
+
else
|
|
87
|
+
onSuccess(objectUrl);
|
|
88
|
+
}
|
|
89
|
+
async createObjectUrlByUri(uri, resouceKeys) {
|
|
90
|
+
if (!uri)
|
|
91
|
+
throw `Resource uri for [${resouceKeys.join(", ")}] can't be empty string`;
|
|
70
92
|
try {
|
|
71
|
-
const response = await (0, fetchLocalFile_1.fetchLocalFile)(
|
|
93
|
+
const response = await (0, fetchLocalFile_1.fetchLocalFile)(uri);
|
|
72
94
|
if (response != null)
|
|
73
95
|
return URL.createObjectURL(await response.blob());
|
|
74
96
|
else
|
|
75
97
|
throw "";
|
|
76
98
|
}
|
|
77
99
|
catch (err) {
|
|
78
|
-
console.warn(`Error to fetch ${
|
|
100
|
+
console.warn(`Error to fetch ${uri} for related images [${resouceKeys.join(", ")}]`, err);
|
|
79
101
|
return null;
|
|
80
102
|
}
|
|
81
103
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { getDynamicResourceAsset, getDynamicResourceFont, getProjectFontFamilySt
|
|
|
4
4
|
import { sendIasApiRequest } from "./iasApi";
|
|
5
5
|
import { gameLocalData } from "./localData";
|
|
6
6
|
import { closeGameReader, createSdkApi, reloadGameReader } from "./sdkApi";
|
|
7
|
-
import { gameLoadedSdkCallback } from "./sdkApi/initGame";
|
|
7
|
+
import { gameLoadedSdkCallback, gameLoadFailedSdkCallback } from "./sdkApi/initGame";
|
|
8
8
|
import { openUrl } from "./sdkApi/openUrl";
|
|
9
9
|
import { share } from "./sdkApi/share";
|
|
10
10
|
import { vibrate } from "./sdkApi/vibrate";
|
|
@@ -20,7 +20,7 @@ export type { RequestInfo as APIRequestInfo, Response as APIResponse } from "./i
|
|
|
20
20
|
export type { Placeholder, GameLaunchConfig };
|
|
21
21
|
export type { ProjectFontFamily } from "./gameResources";
|
|
22
22
|
export type { ResourceInterface } from "./ResourceManager";
|
|
23
|
-
export { createSdkApi, closeGameReader, gameLoadedSdkCallback, gameLaunchConfig, isIos, isWeb, isAndroid, isDev, getSdkVersion, getSemverSdkVersion, gameLocalData, sendIasApiRequest, openUrl, share, vibrate, getDynamicResourceAsset, getDynamicResourceFont, getProjectFontFamilyStylesheet, getIsDemoMode, getSessionId, getApiBaseUrl, ScreenOrientation, PlaceholderType, fetchLocalFile, openStory, ResourceManager, dynamicResourceAssets, dynamicResourceFonts, staticResourcesImagePlaceholders, StaticResourceList, eventGame, reloadGameReader, };
|
|
23
|
+
export { createSdkApi, closeGameReader, gameLoadedSdkCallback, gameLoadFailedSdkCallback, gameLaunchConfig, isIos, isWeb, isAndroid, isDev, getSdkVersion, getSemverSdkVersion, gameLocalData, sendIasApiRequest, openUrl, share, vibrate, getDynamicResourceAsset, getDynamicResourceFont, getProjectFontFamilyStylesheet, getIsDemoMode, getSessionId, getApiBaseUrl, ScreenOrientation, PlaceholderType, fetchLocalFile, openStory, ResourceManager, dynamicResourceAssets, dynamicResourceFonts, staticResourcesImagePlaceholders, StaticResourceList, eventGame, reloadGameReader, };
|
|
24
24
|
declare const GameCenterApi: {
|
|
25
25
|
createSdkApi: ({ mounted, beforeUnmount: beforeUnmountCb, onSdkCloseGameReaderIntent, onPause, onResume, onBackGesture, onAudioFocusChange, filterPlaceholders, }: Partial<{
|
|
26
26
|
mounted: () => void;
|
|
@@ -37,6 +37,7 @@ declare const GameCenterApi: {
|
|
|
37
37
|
showClose: boolean;
|
|
38
38
|
backGesture: boolean;
|
|
39
39
|
}>> | undefined) => void;
|
|
40
|
+
gameLoadFailedSdkCallback: (reason: string, canTryReload: boolean) => void;
|
|
40
41
|
gameLaunchConfig: GameLaunchConfig;
|
|
41
42
|
isIos: any;
|
|
42
43
|
isWeb: boolean;
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = exports.reloadGameReader = exports.eventGame = exports.StaticResourceList = exports.staticResourcesImagePlaceholders = exports.dynamicResourceFonts = exports.dynamicResourceAssets = exports.ResourceManager = exports.openStory = exports.fetchLocalFile = exports.PlaceholderType = exports.ScreenOrientation = exports.getApiBaseUrl = exports.getSessionId = exports.getIsDemoMode = exports.getProjectFontFamilyStylesheet = exports.getDynamicResourceFont = exports.getDynamicResourceAsset = exports.vibrate = exports.share = exports.openUrl = exports.sendIasApiRequest = exports.gameLocalData = exports.getSemverSdkVersion = exports.getSdkVersion = exports.isDev = exports.isAndroid = exports.isWeb = exports.isIos = exports.gameLaunchConfig = exports.gameLoadedSdkCallback = exports.closeGameReader = exports.createSdkApi = void 0;
|
|
3
|
+
exports.default = exports.reloadGameReader = exports.eventGame = exports.StaticResourceList = exports.staticResourcesImagePlaceholders = exports.dynamicResourceFonts = exports.dynamicResourceAssets = exports.ResourceManager = exports.openStory = exports.fetchLocalFile = exports.PlaceholderType = exports.ScreenOrientation = exports.getApiBaseUrl = exports.getSessionId = exports.getIsDemoMode = exports.getProjectFontFamilyStylesheet = exports.getDynamicResourceFont = exports.getDynamicResourceAsset = exports.vibrate = exports.share = exports.openUrl = exports.sendIasApiRequest = exports.gameLocalData = exports.getSemverSdkVersion = exports.getSdkVersion = exports.isDev = exports.isAndroid = exports.isWeb = exports.isIos = exports.gameLaunchConfig = exports.gameLoadFailedSdkCallback = exports.gameLoadedSdkCallback = exports.closeGameReader = exports.createSdkApi = void 0;
|
|
4
4
|
const env_1 = require("./env");
|
|
5
5
|
Object.defineProperty(exports, "getSdkVersion", { enumerable: true, get: function () { return env_1.getSdkVersion; } });
|
|
6
6
|
Object.defineProperty(exports, "getSemverSdkVersion", { enumerable: true, get: function () { return env_1.getSemverSdkVersion; } });
|
|
@@ -31,6 +31,7 @@ Object.defineProperty(exports, "createSdkApi", { enumerable: true, get: function
|
|
|
31
31
|
Object.defineProperty(exports, "reloadGameReader", { enumerable: true, get: function () { return sdkApi_1.reloadGameReader; } });
|
|
32
32
|
const initGame_1 = require("./sdkApi/initGame");
|
|
33
33
|
Object.defineProperty(exports, "gameLoadedSdkCallback", { enumerable: true, get: function () { return initGame_1.gameLoadedSdkCallback; } });
|
|
34
|
+
Object.defineProperty(exports, "gameLoadFailedSdkCallback", { enumerable: true, get: function () { return initGame_1.gameLoadFailedSdkCallback; } });
|
|
34
35
|
const openUrl_1 = require("./sdkApi/openUrl");
|
|
35
36
|
Object.defineProperty(exports, "openUrl", { enumerable: true, get: function () { return openUrl_1.openUrl; } });
|
|
36
37
|
const share_1 = require("./sdkApi/share");
|
|
@@ -52,6 +53,7 @@ const GameCenterApi = {
|
|
|
52
53
|
createSdkApi: sdkApi_1.createSdkApi,
|
|
53
54
|
closeGameReader: sdkApi_1.closeGameReader,
|
|
54
55
|
gameLoadedSdkCallback: initGame_1.gameLoadedSdkCallback,
|
|
56
|
+
gameLoadFailedSdkCallback: initGame_1.gameLoadFailedSdkCallback,
|
|
55
57
|
gameLaunchConfig: gameLaunchConfig_1.gameLaunchConfig,
|
|
56
58
|
isIos: env_1.isIos,
|
|
57
59
|
isWeb: env_1.isWeb,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inappstory/game-center-api",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.10",
|
|
4
4
|
"description": "",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"semver": "^7.3.8",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
26
26
|
"lint": "prettier --check .",
|
|
27
27
|
"format": "prettier --write .",
|
|
28
|
-
"prepare": "husky"
|
|
28
|
+
"prepare": "node .husky/install.mjs"
|
|
29
29
|
},
|
|
30
30
|
"files": [
|
|
31
31
|
"lib/**/*"
|