@inappstory/game-center-api 1.2.1 → 1.2.2
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/README.md +66 -1
- package/lib/index.d.ts +3 -7
- package/lib/index.js +1 -3
- package/lib/sdkApi/initGame.d.ts +1 -6
- package/lib/sdkApi/initGame.js +26 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -30,16 +30,81 @@ createSdkApi({
|
|
|
30
30
|
onBackGesture: () => {
|
|
31
31
|
/* Call on Android back gesture */
|
|
32
32
|
},
|
|
33
|
+
gameShouldForeground: () => {
|
|
34
|
+
/* splash animation finished, now we can start bg music and etc */
|
|
35
|
+
},
|
|
33
36
|
});
|
|
34
37
|
```
|
|
35
38
|
|
|
36
39
|
## Game first render
|
|
37
40
|
|
|
38
41
|
```tsx
|
|
42
|
+
const gameLoaded = () => {
|
|
43
|
+
if (GameCenterApi.isSdkSupportGameShouldForegroundCallback()) {
|
|
44
|
+
GameCenterApi.gameLoadedSdkCallback();
|
|
45
|
+
} else {
|
|
46
|
+
// fallback for old sdk versions
|
|
47
|
+
gameShouldForeground();
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const gameStarted = () => {
|
|
52
|
+
setTimeout(() => {
|
|
53
|
+
// Wait for render complete - then remove native loader screen
|
|
54
|
+
if (GameCenterApi.isSdkSupportGameShouldForegroundCallback()) {
|
|
55
|
+
GameCenterApi.gameShouldForegroundCallback();
|
|
56
|
+
} else {
|
|
57
|
+
GameCenterApi.gameLoadedSdkCallback();
|
|
58
|
+
}
|
|
59
|
+
}, 50);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const gameShouldForeground = () => {
|
|
63
|
+
// splash animation finished, now we can start bg music and etc
|
|
64
|
+
gameStarted();
|
|
65
|
+
};
|
|
66
|
+
|
|
39
67
|
// calling gameLoadedSdkCallback removes the loading screen
|
|
40
68
|
import { gameLoadedSdkCallback } from "@inappstory/game-center-api";
|
|
41
69
|
|
|
42
70
|
const rootElement = document.getElementById("root");
|
|
43
71
|
const root = createRoot(rootElement!);
|
|
44
|
-
root.render(<AppWithCallbackAfterRender cb={
|
|
72
|
+
root.render(<AppWithCallbackAfterRender cb={gameLoaded} />);
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Get user ID
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
import GameCenterApi from "@inappstory/game-center-api";
|
|
79
|
+
// call only after mounted event (from GameCenterApi.createSdkApi
|
|
80
|
+
const getUserId = () => GameCenterApi.gameLaunchConfig.clientConfig.userId;
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Get placeholder
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
import GameCenterApi, { type PlaceholderType, Placeholder } from "@inappstory/game-center-api";
|
|
87
|
+
// call only after mounted event (from GameCenterApi.createSdkApi
|
|
88
|
+
const getPlaceholder = (name: string, type: PlaceholderType): Placeholder | undefined => {
|
|
89
|
+
return GameCenterApi.gameLaunchConfig.clientConfig.placeholders.find(placeholder => placeholder.name === name && placeholder.type === type);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const avatarUrl = getPlaceholder("avatar", PlaceholderType.IMAGE);
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Open url
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
import GameCenterApi from "@inappstory/game-center-api";
|
|
99
|
+
|
|
100
|
+
// closeGameReader - close or not GameReader
|
|
101
|
+
const openUrl = (url: string) => GameCenterApi.openUrl({ url, closeGameReader: true });
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Close game
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
import GameCenterApi from "@inappstory/game-center-api";
|
|
108
|
+
|
|
109
|
+
const closeGame = () => GameCenterApi.closeGameReader();
|
|
45
110
|
```
|
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, gameLoadFailedSdkCallback, gameShouldForegroundCallback,
|
|
7
|
+
import { gameLoadedSdkCallback, gameLoadFailedSdkCallback, gameShouldForegroundCallback, gameOnForeground } from "./sdkApi/initGame";
|
|
8
8
|
import { openUrl } from "./sdkApi/openUrl";
|
|
9
9
|
import { share } from "./sdkApi/share";
|
|
10
10
|
import { vibrate } from "./sdkApi/vibrate";
|
|
@@ -23,7 +23,7 @@ export type { RequestInfo as APIRequestInfo, Response as APIResponse } from "./i
|
|
|
23
23
|
export type { Placeholder, GameLaunchConfig };
|
|
24
24
|
export type { ProjectFontFamily } from "./gameResources";
|
|
25
25
|
export type { ResourceInterface } from "./ResourceManager";
|
|
26
|
-
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, openFilePicker, FilePickerResultType, isFilePickerResultFileList, isFilePickerResultLocalFileList, isLocalFile, hasFilePickerApi, gameShouldForegroundCallback,
|
|
26
|
+
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, openFilePicker, FilePickerResultType, isFilePickerResultFileList, isFilePickerResultLocalFileList, isLocalFile, hasFilePickerApi, gameShouldForegroundCallback, gameOnForeground, };
|
|
27
27
|
declare const GameCenterApi: {
|
|
28
28
|
createSdkApi: ({ mounted, beforeUnmount: beforeUnmountCb, onSdkCloseGameReaderIntent, onPause, onResume, onBackGesture, onAudioFocusChange, filterPlaceholders, gameShouldForeground, }: Partial<{
|
|
29
29
|
mounted: () => void;
|
|
@@ -37,10 +37,7 @@ declare const GameCenterApi: {
|
|
|
37
37
|
gameShouldForeground: () => void;
|
|
38
38
|
}>) => void;
|
|
39
39
|
closeGameReader: (data?: import("./sdkApi").CloseGameReaderOptions | undefined) => void;
|
|
40
|
-
gameLoadedSdkCallback: (
|
|
41
|
-
showClose: boolean;
|
|
42
|
-
backGesture: boolean;
|
|
43
|
-
}>> | undefined) => void;
|
|
40
|
+
gameLoadedSdkCallback: () => void;
|
|
44
41
|
gameLoadFailedSdkCallback: (reason: string, canTryReload: boolean) => void;
|
|
45
42
|
gameLaunchConfig: GameLaunchConfig;
|
|
46
43
|
isIos: any;
|
|
@@ -90,7 +87,6 @@ declare const GameCenterApi: {
|
|
|
90
87
|
showClose: boolean;
|
|
91
88
|
backGesture: boolean;
|
|
92
89
|
}>> | undefined) => void;
|
|
93
|
-
isSdkSupportGameShouldForegroundCallback: () => boolean | undefined;
|
|
94
90
|
gameOnForeground: Promise<void>;
|
|
95
91
|
};
|
|
96
92
|
export { GameCenterApi as default };
|
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.gameOnForeground = exports.
|
|
3
|
+
exports.default = exports.gameOnForeground = exports.gameShouldForegroundCallback = exports.hasFilePickerApi = exports.isLocalFile = exports.isFilePickerResultLocalFileList = exports.isFilePickerResultFileList = exports.FilePickerResultType = exports.openFilePicker = 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; } });
|
|
@@ -33,7 +33,6 @@ const initGame_1 = require("./sdkApi/initGame");
|
|
|
33
33
|
Object.defineProperty(exports, "gameLoadedSdkCallback", { enumerable: true, get: function () { return initGame_1.gameLoadedSdkCallback; } });
|
|
34
34
|
Object.defineProperty(exports, "gameLoadFailedSdkCallback", { enumerable: true, get: function () { return initGame_1.gameLoadFailedSdkCallback; } });
|
|
35
35
|
Object.defineProperty(exports, "gameShouldForegroundCallback", { enumerable: true, get: function () { return initGame_1.gameShouldForegroundCallback; } });
|
|
36
|
-
Object.defineProperty(exports, "isSdkSupportGameShouldForegroundCallback", { enumerable: true, get: function () { return initGame_1.isSdkSupportGameShouldForegroundCallback; } });
|
|
37
36
|
Object.defineProperty(exports, "gameOnForeground", { enumerable: true, get: function () { return initGame_1.gameOnForeground; } });
|
|
38
37
|
const openUrl_1 = require("./sdkApi/openUrl");
|
|
39
38
|
Object.defineProperty(exports, "openUrl", { enumerable: true, get: function () { return openUrl_1.openUrl; } });
|
|
@@ -101,7 +100,6 @@ const GameCenterApi = {
|
|
|
101
100
|
isLocalFile: filePicker_h_1.isLocalFile,
|
|
102
101
|
hasFilePickerApi: filePicker_1.hasFilePickerApi,
|
|
103
102
|
gameShouldForegroundCallback: initGame_1.gameShouldForegroundCallback,
|
|
104
|
-
isSdkSupportGameShouldForegroundCallback: initGame_1.isSdkSupportGameShouldForegroundCallback,
|
|
105
103
|
gameOnForeground: initGame_1.gameOnForeground,
|
|
106
104
|
};
|
|
107
105
|
exports.default = GameCenterApi;
|
package/lib/sdkApi/initGame.d.ts
CHANGED
|
@@ -27,14 +27,10 @@ type GameReaderInit = {
|
|
|
27
27
|
ready: (cb: () => void) => void;
|
|
28
28
|
};
|
|
29
29
|
export declare const createInitGame: (initLocalData: () => Promise<void>, mounted?: () => void) => void;
|
|
30
|
-
type GameLoadedSdkConfig = Partial<{
|
|
31
|
-
showClose: boolean;
|
|
32
|
-
backGesture: boolean;
|
|
33
|
-
}>;
|
|
34
30
|
/**
|
|
35
31
|
* API method for remove loader screen from Reader
|
|
36
32
|
*/
|
|
37
|
-
export declare const gameLoadedSdkCallback: (
|
|
33
|
+
export declare const gameLoadedSdkCallback: () => void;
|
|
38
34
|
export declare const gameLoadFailedSdkCallback: (reason: string, canTryReload: boolean) => void;
|
|
39
35
|
export declare const createGameShouldForeground: (gameShouldForeground: () => void) => void;
|
|
40
36
|
type GameShouldForegroundConfig = Partial<{
|
|
@@ -45,6 +41,5 @@ type GameShouldForegroundConfig = Partial<{
|
|
|
45
41
|
* API method for remove loader screen from Reader
|
|
46
42
|
*/
|
|
47
43
|
export declare const gameShouldForegroundCallback: (config?: Partial<GameShouldForegroundConfig>) => void;
|
|
48
|
-
export declare const isSdkSupportGameShouldForegroundCallback: () => boolean | undefined;
|
|
49
44
|
export declare const gameOnForeground: Promise<void>;
|
|
50
45
|
export {};
|
package/lib/sdkApi/initGame.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.gameOnForeground = exports.
|
|
3
|
+
exports.gameOnForeground = exports.gameShouldForegroundCallback = exports.createGameShouldForeground = exports.gameLoadFailedSdkCallback = exports.gameLoadedSdkCallback = exports.createInitGame = void 0;
|
|
4
4
|
const isObject_1 = require("../helpers/isObject");
|
|
5
5
|
const gameLaunchConfig_1 = require("../gameLaunchConfig");
|
|
6
6
|
const env_1 = require("../env");
|
|
@@ -138,7 +138,17 @@ exports.createInitGame = createInitGame;
|
|
|
138
138
|
/**
|
|
139
139
|
* API method for remove loader screen from Reader
|
|
140
140
|
*/
|
|
141
|
-
const gameLoadedSdkCallback = (
|
|
141
|
+
const gameLoadedSdkCallback = () => {
|
|
142
|
+
if (isSdkSupportGameShouldForegroundCallback()) {
|
|
143
|
+
gameLoadedSdkCallbackInternal();
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
/** Old sdk - call shouldForeground, emulate new sdk */
|
|
147
|
+
window.gameShouldForeground();
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
exports.gameLoadedSdkCallback = gameLoadedSdkCallback;
|
|
151
|
+
const gameLoadedSdkCallbackInternal = (config) => {
|
|
142
152
|
window.gameLoadingInfo.state = "before call gameLoadedSdkCallback";
|
|
143
153
|
window.gameLoadingInfo.description = "";
|
|
144
154
|
try {
|
|
@@ -152,7 +162,7 @@ const gameLoadedSdkCallback = (config) => {
|
|
|
152
162
|
}
|
|
153
163
|
if (env_1.isAndroid) {
|
|
154
164
|
if (window.Android.gameLoaded !== undefined) {
|
|
155
|
-
if (
|
|
165
|
+
if (isSdkSupportGameShouldForegroundCallback()) {
|
|
156
166
|
window.Android.gameLoaded();
|
|
157
167
|
}
|
|
158
168
|
else {
|
|
@@ -163,7 +173,7 @@ const gameLoadedSdkCallback = (config) => {
|
|
|
163
173
|
}
|
|
164
174
|
else if (env_1.isIos) {
|
|
165
175
|
if (env_1.iosMh.gameLoaded !== undefined) {
|
|
166
|
-
if (
|
|
176
|
+
if (isSdkSupportGameShouldForegroundCallback()) {
|
|
167
177
|
env_1.iosMh.gameLoaded.postMessage("");
|
|
168
178
|
}
|
|
169
179
|
else {
|
|
@@ -174,7 +184,7 @@ const gameLoadedSdkCallback = (config) => {
|
|
|
174
184
|
}
|
|
175
185
|
else if (env_1.isWeb) {
|
|
176
186
|
if (Source_1.webSource.sourceWindow && Source_1.webSource.sourceWindowOrigin) {
|
|
177
|
-
if (
|
|
187
|
+
if (isSdkSupportGameShouldForegroundCallback()) {
|
|
178
188
|
Source_1.webSource.sourceWindow.postMessage(["gameLoaded"], Source_1.webSource.sourceWindowOrigin);
|
|
179
189
|
}
|
|
180
190
|
else {
|
|
@@ -192,7 +202,7 @@ const gameLoadedSdkCallback = (config) => {
|
|
|
192
202
|
window.gameLoadingInfo.state = "after call gameLoadedSdkCallback";
|
|
193
203
|
window.gameLoadingInfo.description = "";
|
|
194
204
|
window.gameLoadingInfo.loaded = true;
|
|
195
|
-
if (!
|
|
205
|
+
if (!isSdkSupportGameShouldForegroundCallback()) {
|
|
196
206
|
gameOnForegroundResolve();
|
|
197
207
|
}
|
|
198
208
|
}
|
|
@@ -206,7 +216,6 @@ const gameLoadedSdkCallback = (config) => {
|
|
|
206
216
|
console.error(e);
|
|
207
217
|
}
|
|
208
218
|
};
|
|
209
|
-
exports.gameLoadedSdkCallback = gameLoadedSdkCallback;
|
|
210
219
|
window.gameLoadingInfo = {
|
|
211
220
|
loaded: false,
|
|
212
221
|
state: "gameReader API created",
|
|
@@ -245,6 +254,16 @@ exports.createGameShouldForeground = createGameShouldForeground;
|
|
|
245
254
|
* API method for remove loader screen from Reader
|
|
246
255
|
*/
|
|
247
256
|
const gameShouldForegroundCallback = (config) => {
|
|
257
|
+
if (isSdkSupportGameShouldForegroundCallback()) {
|
|
258
|
+
gameShouldForegroundCallbackInternal(config);
|
|
259
|
+
}
|
|
260
|
+
else {
|
|
261
|
+
/** For old sdk - use gameLoadedSdkCallbackInternal with config (for remove splash) */
|
|
262
|
+
gameLoadedSdkCallbackInternal(config);
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
exports.gameShouldForegroundCallback = gameShouldForegroundCallback;
|
|
266
|
+
const gameShouldForegroundCallbackInternal = (config) => {
|
|
248
267
|
let showClose = config?.showClose;
|
|
249
268
|
if (showClose == null) {
|
|
250
269
|
showClose = false;
|
|
@@ -276,7 +295,6 @@ const gameShouldForegroundCallback = (config) => {
|
|
|
276
295
|
}
|
|
277
296
|
gameOnForegroundResolve();
|
|
278
297
|
};
|
|
279
|
-
exports.gameShouldForegroundCallback = gameShouldForegroundCallback;
|
|
280
298
|
const isSdkSupportGameShouldForegroundCallback = () => {
|
|
281
299
|
if (env_1.isAndroid) {
|
|
282
300
|
return "gameShouldForegroundCallback" in window.Android;
|
|
@@ -296,7 +314,6 @@ const isSdkSupportGameShouldForegroundCallback = () => {
|
|
|
296
314
|
return support;
|
|
297
315
|
}
|
|
298
316
|
};
|
|
299
|
-
exports.isSdkSupportGameShouldForegroundCallback = isSdkSupportGameShouldForegroundCallback;
|
|
300
317
|
let gameOnForegroundResolve = () => { };
|
|
301
318
|
let gameOnForegroundReject = () => { };
|
|
302
319
|
exports.gameOnForeground = new Promise((resolve, reject) => {
|