@inappstory/game-center-api 1.0.0-rc.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 InAppStory
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # game-center-api
2
+ API for integration with GameReader (WebView) inside native apps
@@ -0,0 +1 @@
1
+ export declare const asyncQueue: Map<any, any>;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.asyncQueue = void 0;
4
+ exports.asyncQueue = new Map();
package/lib/env.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ import { SemVer } from "semver";
2
+ declare global {
3
+ interface Window {
4
+ Android: any;
5
+ webkit: {
6
+ messageHandlers: Record<string, any>;
7
+ };
8
+ }
9
+ }
10
+ declare const isAndroid: any;
11
+ declare const isIos: any;
12
+ declare const isWeb: boolean;
13
+ declare let iosMh: Record<string, any>;
14
+ declare const isDev: boolean;
15
+ declare const getSdkVersion: () => string | false | null;
16
+ declare const getSemverSdkVersion: () => false | SemVer | null;
17
+ export { isIos, isWeb, isAndroid, iosMh, isDev, getSdkVersion, getSemverSdkVersion };
package/lib/env.js ADDED
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSemverSdkVersion = exports.getSdkVersion = exports.isDev = exports.iosMh = exports.isAndroid = exports.isWeb = exports.isIos = void 0;
4
+ const gameLaunchConfig_1 = require("./gameLaunchConfig");
5
+ const semver = require("semver");
6
+ const isAndroid = window.Android;
7
+ exports.isAndroid = isAndroid;
8
+ // todo как то улучшить detector
9
+ const isIos = window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.gameLoaded;
10
+ exports.isIos = isIos;
11
+ const isWeb = !isAndroid && !isIos;
12
+ exports.isWeb = isWeb;
13
+ let iosMh = {};
14
+ exports.iosMh = iosMh;
15
+ if (isIos) {
16
+ exports.iosMh = iosMh = window.webkit.messageHandlers;
17
+ }
18
+ const isDev = process.env.NODE_ENV === "development";
19
+ exports.isDev = isDev;
20
+ let sdkVersion = false;
21
+ let semverSdkVersion = false;
22
+ const parseSdkVersion = () => {
23
+ try {
24
+ const semverResult = semver.parse(gameLaunchConfig_1.gameLaunchConfig.clientConfig.sdkVersion);
25
+ if (semverResult != null) {
26
+ sdkVersion = gameLaunchConfig_1.gameLaunchConfig.clientConfig.sdkVersion;
27
+ semverSdkVersion = semverResult;
28
+ }
29
+ }
30
+ catch (e) {
31
+ console.error(e);
32
+ }
33
+ };
34
+ const getSdkVersion = () => {
35
+ if (sdkVersion === false || semverSdkVersion === false) {
36
+ parseSdkVersion();
37
+ }
38
+ return sdkVersion;
39
+ };
40
+ exports.getSdkVersion = getSdkVersion;
41
+ const getSemverSdkVersion = () => {
42
+ if (sdkVersion === false || semverSdkVersion === false) {
43
+ parseSdkVersion();
44
+ }
45
+ return semverSdkVersion;
46
+ };
47
+ exports.getSemverSdkVersion = getSemverSdkVersion;
@@ -0,0 +1,7 @@
1
+ import { GameLaunchConfig } from "./gameLaunchConfig.h";
2
+ export declare const gameLaunchConfig: GameLaunchConfig;
3
+ export declare function setGameLaunchConfig(config: GameLaunchConfig): void;
4
+ export declare function getGameInstanceId(): number;
5
+ export declare function getIsDemoMode(): boolean;
6
+ export declare function getSessionId(): string;
7
+ export declare function getApiBaseUrl(): string;
@@ -0,0 +1,35 @@
1
+ import { GameResources } from "./gameResources.h";
2
+ export declare type GameLaunchConfig = {
3
+ gameInstanceId: number;
4
+ gameResources: GameResources;
5
+ projectSlug: string;
6
+ demoMode: boolean;
7
+ projectEnv: "test" | "prod";
8
+ gameDomain: string;
9
+ gameSlug: string;
10
+ gameVersion: string;
11
+ verbose: boolean;
12
+ clientConfig: {
13
+ apiBaseUrl: string;
14
+ apiKey: string;
15
+ appPackageId: string;
16
+ deviceId: string;
17
+ fullScreen: boolean;
18
+ lang: string;
19
+ placeholders: Array<{
20
+ name: string;
21
+ type: "text" | "image";
22
+ value: string;
23
+ }>;
24
+ safeAreaInsets: {
25
+ bottom: number;
26
+ left: number;
27
+ right: number;
28
+ top: number;
29
+ };
30
+ screenOrientation: "portrait" | "landscape";
31
+ sdkVersion: string;
32
+ sessionId: string;
33
+ userAgent: string;
34
+ };
35
+ };
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const t = {
4
+ "gameInstanceId": 29,
5
+ "gameResources": {
6
+ "fonts": {
7
+ "InternalPrimaryFontNormalNormal": "https://cdn.test.inappstory.com/np/file/tf/um/dn/tb6yge0jsjph8u6vnnvsdy1cvg.ttf?k=AQAAAAAAAAAC",
8
+ "InternalPrimaryFontBoldNormal": "https://cdn.test.inappstory.com/np/file/zs/ee/u4/xewee8swl6uop6biaomxsgu9u0.ttf?k=AQAAAAAAAAAC",
9
+ "InternalPrimaryFontNormalItalic": "https://cdn.test.inappstory.com/np/file/tv/zj/cq/vb51rxqvcintwdj7kpsfedgnug.ttf?k=AQAAAAAAAAAC",
10
+ "InternalSecondaryFontNormalNormal": "https://cdn.test.inappstory.com/np/file/96/qy/cc/ipmyidzfrxssd4qccyqdwbul4j.ttf?k=AQAAAAAAAAAC",
11
+ "InternalSecondaryFontBoldNormal": "https://cdn.test.inappstory.com/np/file/dh/uo/ix/4nbuiht7imj0m2afayhukyoh8a.ttf?k=AQAAAAAAAAAC",
12
+ "InternalSecondaryFontBoldItalic": "https://cdn.test.inappstory.com/np/file/ia/lq/qd/hy2s0vpyh0vgqdnjjm4lfoigss.ttf?k=AQAAAAAAAAAC"
13
+ },
14
+ "assets": {
15
+ "boardImage": "https://cs.test.inappstory.com/np/file/rk/mi/dx/kgas5ly0bpudunyiw3wuqtvohn.webp?k=AQAAAAAAAAAC",
16
+ "backgroundImage": "https://cs.test.inappstory.com/np/file/i2/l8/5x/jqxtjth04io7ritifom6hgbtxi.webp?k=AQAAAAAAAAAC"
17
+ }
18
+ },
19
+ "storyId": null,
20
+ "elementId": null,
21
+ "projectSlug": "test",
22
+ "demoMode": false,
23
+ "projectEnv": "test",
24
+ "gameDomain": "https://games.test.inappstory.com/fifteen-puzzle/1.1.0/build/",
25
+ "gameSlug": "fifteen-puzzle",
26
+ "gameVersion": "1.1.0",
27
+ "clientConfig": {
28
+ "apiBaseUrl": "https://api.test.inappstory.ru/",
29
+ "apiKey": "BAEAAAAAAAAANsjZZBYaIThgDx0GIhFYKhdBRhlHFCMoYAkNIm3xDBr2ypZlqafCVsD8EbDWbkyq6HK8GiaPLeadSWY",
30
+ "appPackageId": "com.inappstory.android",
31
+ "deviceId": "293f420fc39908d1",
32
+ "fullScreen": false,
33
+ "gameInstanceId": "29",
34
+ "lang": "ru-RU",
35
+ "placeholders": [
36
+ {
37
+ "name": "sadsad",
38
+ "type": "text",
39
+ "value": "2222222222222222"
40
+ },
41
+ {
42
+ "name": "oooooooooooo",
43
+ "type": "text",
44
+ "value": "ooooooooooo"
45
+ },
46
+ {
47
+ "name": "rrrrrrrrrrr",
48
+ "type": "text",
49
+ "value": "rrrrrrrrrrrrr"
50
+ },
51
+ {
52
+ "name": "zvukomania_username",
53
+ "type": "text",
54
+ "value": "Default username"
55
+ },
56
+ {
57
+ "name": "pppppppppp",
58
+ "type": "text",
59
+ "value": "pppppppppppp"
60
+ },
61
+ {
62
+ "name": "tttttttttt",
63
+ "type": "text",
64
+ "value": "ttttttttttttt"
65
+ },
66
+ {
67
+ "name": "iiiiiiiiiiiiiiii",
68
+ "type": "text",
69
+ "value": "iiiiiiiiiiiiiiiiii"
70
+ },
71
+ {
72
+ "name": "qqqq",
73
+ "type": "text",
74
+ "value": "qqqqqq"
75
+ },
76
+ {
77
+ "name": "uuuuuuuuuuuuu",
78
+ "type": "text",
79
+ "value": "uuuuuuuuuuuuuuuu"
80
+ },
81
+ {
82
+ "name": "wwwwww",
83
+ "type": "text",
84
+ "value": "wwwwwwwwwww"
85
+ },
86
+ {
87
+ "name": "aaaaaaaaaaaaa",
88
+ "type": "text",
89
+ "value": "aaaaaaaaaaaaaaaa"
90
+ },
91
+ {
92
+ "name": "eeeeee",
93
+ "type": "text",
94
+ "value": "eeeeeeeeeeee"
95
+ },
96
+ {
97
+ "name": "username",
98
+ "type": "text",
99
+ "value": "default username'000"
100
+ },
101
+ {
102
+ "name": "zvukomania_avatar",
103
+ "type": "image",
104
+ "value": "https://i1.sndcdn.com/avatars-000102655488-sr66dh-t500x500.jpg"
105
+ },
106
+ {
107
+ "name": "avatar",
108
+ "type": "image",
109
+ "value": "https://i1.sndcdn.com/avatars-000102655488-sr66dh-t500x500.jpg"
110
+ },
111
+ {
112
+ "name": "img1",
113
+ "type": "image",
114
+ "value": "https://snob.ru/indoc/original_images/8f4/glavnai"
115
+ }
116
+ ],
117
+ "safeAreaInsets": {
118
+ "bottom": 16,
119
+ "left": 0,
120
+ "right": 0,
121
+ "top": 0
122
+ },
123
+ "screenOrientation": "portrait",
124
+ "sdkVersion": "1.16.0",
125
+ "sessionId": "A2glAAAAAAAAAQAAAKTI2WQCCQgAAAAamGs7wP4RcYiEwdMi19Z7aE68fT6QW5S18Oe812f6pw",
126
+ "userAgent": "InAppStorySDK/750 Dalvik/2.1.0 (Linux; U; Android 11; XQ-AT51 Build/58.1.A.5.530) Application/258 (com.inappstory.android 3.1.0)"
127
+ },
128
+ "test": "Special' string\" \\b \n \r \t \t / \\",
129
+ "storyLocalData": {}
130
+ };
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getApiBaseUrl = exports.getSessionId = exports.getIsDemoMode = exports.getGameInstanceId = exports.setGameLaunchConfig = exports.gameLaunchConfig = void 0;
4
+ exports.gameLaunchConfig = {};
5
+ function setGameLaunchConfig(config) {
6
+ for (const key in config) {
7
+ // @ts-ignore
8
+ exports.gameLaunchConfig[key] = config[key];
9
+ }
10
+ Object.freeze(exports.gameLaunchConfig);
11
+ }
12
+ exports.setGameLaunchConfig = setGameLaunchConfig;
13
+ function getGameInstanceId() {
14
+ return exports.gameLaunchConfig.gameInstanceId;
15
+ }
16
+ exports.getGameInstanceId = getGameInstanceId;
17
+ function getIsDemoMode() {
18
+ return exports.gameLaunchConfig.demoMode;
19
+ }
20
+ exports.getIsDemoMode = getIsDemoMode;
21
+ function getSessionId() {
22
+ return exports.gameLaunchConfig.clientConfig.sessionId;
23
+ }
24
+ exports.getSessionId = getSessionId;
25
+ function getApiBaseUrl() {
26
+ return exports.gameLaunchConfig.clientConfig.apiBaseUrl;
27
+ }
28
+ exports.getApiBaseUrl = getApiBaseUrl;
@@ -0,0 +1 @@
1
+ export declare const getDynamicResourceAsset: (key: string, defaultValue: any) => any;
@@ -0,0 +1,11 @@
1
+ declare const resourceUrlSymbol: unique symbol;
2
+ declare type ResourceUrlSymbolType = typeof resourceUrlSymbol;
3
+ declare type ResourceUrl<T extends string> = number & {
4
+ [name in ResourceUrlSymbolType]: T;
5
+ };
6
+ export declare type GameResourceItem = Record<string, ResourceUrl<"common">>;
7
+ export declare type GameResources = {
8
+ "fonts": GameResourceItem;
9
+ "assets": GameResourceItem;
10
+ };
11
+ export {};
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const resourceUrlSymbol = Symbol.for("resourceUrl");
4
+ const resourceUrlBrand = (n) => n;
5
+ const t = {
6
+ "gameResources": {
7
+ "fonts": {
8
+ "InternalPrimaryFontNormalNormal": "https://cdn.test.inappstory.com/np/file/tf/um/dn/tb6yge0jsjph8u6vnnvsdy1cvg.ttf?k=AQAAAAAAAAAC",
9
+ "InternalPrimaryFontBoldNormal": "https://cdn.test.inappstory.com/np/file/zs/ee/u4/xewee8swl6uop6biaomxsgu9u0.ttf?k=AQAAAAAAAAAC",
10
+ "InternalPrimaryFontNormalItalic": "https://cdn.test.inappstory.com/np/file/tv/zj/cq/vb51rxqvcintwdj7kpsfedgnug.ttf?k=AQAAAAAAAAAC",
11
+ "InternalSecondaryFontNormalNormal": "https://cdn.test.inappstory.com/np/file/96/qy/cc/ipmyidzfrxssd4qccyqdwbul4j.ttf?k=AQAAAAAAAAAC",
12
+ "InternalSecondaryFontBoldNormal": "https://cdn.test.inappstory.com/np/file/dh/uo/ix/4nbuiht7imj0m2afayhukyoh8a.ttf?k=AQAAAAAAAAAC",
13
+ "InternalSecondaryFontBoldItalic": "https://cdn.test.inappstory.com/np/file/ia/lq/qd/hy2s0vpyh0vgqdnjjm4lfoigss.ttf?k=AQAAAAAAAAAC"
14
+ },
15
+ "assets": {
16
+ "boardImage": "https://cs.test.inappstory.com/np/file/rk/mi/dx/kgas5ly0bpudunyiw3wuqtvohn.webp?k=AQAAAAAAAAAC",
17
+ "backgroundImage": "https://cs.test.inappstory.com/np/file/i2/l8/5x/jqxtjth04io7ritifom6hgbtxi.webp?k=AQAAAAAAAAAC"
18
+ }
19
+ }
20
+ };
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ // todo - get fonts arr and other keys
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.getDynamicResourceAsset = void 0;
5
+ const gameLaunchConfig_1 = require("./gameLaunchConfig");
6
+ const env_1 = require("./env");
7
+ const getDynamicResourceAsset = (key, defaultValue) => {
8
+ const gameInstanceId = gameLaunchConfig_1.gameLaunchConfig.gameInstanceId;
9
+ const assets = gameLaunchConfig_1.gameLaunchConfig?.gameResources?.assets ?? {};
10
+ if (assets[key] != null) {
11
+ if (env_1.isAndroid || env_1.isIos) {
12
+ return `./resources_${gameInstanceId}/${key}`;
13
+ }
14
+ else {
15
+ return assets[key]; // url
16
+ }
17
+ }
18
+ return defaultValue;
19
+ };
20
+ exports.getDynamicResourceAsset = getDynamicResourceAsset;
21
+ const t = {
22
+ "gameResources": {
23
+ "fonts": {
24
+ "InternalPrimaryFontNormalNormal": "https://cdn.test.inappstory.com/np/file/tf/um/dn/tb6yge0jsjph8u6vnnvsdy1cvg.ttf?k=AQAAAAAAAAAC",
25
+ "InternalPrimaryFontBoldNormal": "https://cdn.test.inappstory.com/np/file/zs/ee/u4/xewee8swl6uop6biaomxsgu9u0.ttf?k=AQAAAAAAAAAC",
26
+ "InternalPrimaryFontNormalItalic": "https://cdn.test.inappstory.com/np/file/tv/zj/cq/vb51rxqvcintwdj7kpsfedgnug.ttf?k=AQAAAAAAAAAC",
27
+ "InternalSecondaryFontNormalNormal": "https://cdn.test.inappstory.com/np/file/96/qy/cc/ipmyidzfrxssd4qccyqdwbul4j.ttf?k=AQAAAAAAAAAC",
28
+ "InternalSecondaryFontBoldNormal": "https://cdn.test.inappstory.com/np/file/dh/uo/ix/4nbuiht7imj0m2afayhukyoh8a.ttf?k=AQAAAAAAAAAC",
29
+ "InternalSecondaryFontBoldItalic": "https://cdn.test.inappstory.com/np/file/ia/lq/qd/hy2s0vpyh0vgqdnjjm4lfoigss.ttf?k=AQAAAAAAAAAC"
30
+ },
31
+ "assets": {
32
+ "boardImage": "https://cs.test.inappstory.com/np/file/rk/mi/dx/kgas5ly0bpudunyiw3wuqtvohn.webp?k=AQAAAAAAAAAC",
33
+ "backgroundImage": "https://cs.test.inappstory.com/np/file/i2/l8/5x/jqxtjth04io7ritifom6hgbtxi.webp?k=AQAAAAAAAAAC"
34
+ }
35
+ }
36
+ };
@@ -0,0 +1 @@
1
+ export declare function isFunction(obj: any): boolean;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isFunction = void 0;
4
+ function isFunction(obj) {
5
+ return !!(obj && obj.constructor && obj.call && obj.apply);
6
+ }
7
+ exports.isFunction = isFunction;
@@ -0,0 +1 @@
1
+ export declare function isObject(item: any): boolean;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isObject = void 0;
4
+ function isObject(item) {
5
+ return (typeof item === "object" && !Array.isArray(item) && item != null);
6
+ }
7
+ exports.isObject = isObject;
@@ -0,0 +1 @@
1
+ export declare function merge(obj1: Record<string, any>, obj2: Record<string, any>): Record<string, any>;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.merge = void 0;
4
+ /*
5
+ * Recursively merge properties of two objects
6
+ */
7
+ function merge(obj1, obj2) {
8
+ for (const p in obj2) {
9
+ try {
10
+ // Property in destination object set; update its value.
11
+ if (obj2[p].constructor == Object) {
12
+ obj1[p] = merge(obj1[p], obj2[p]);
13
+ }
14
+ else {
15
+ obj1[p] = obj2[p];
16
+ }
17
+ }
18
+ catch (e) {
19
+ // Property in destination object not set; create it and set its value.
20
+ obj1[p] = obj2[p];
21
+ }
22
+ }
23
+ return obj1;
24
+ }
25
+ exports.merge = merge;
@@ -0,0 +1 @@
1
+ export declare function sendIasApiRequest(method?: string, endpoint?: string, data?: {}): Promise<any>;
package/lib/iasApi.js ADDED
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sendIasApiRequest = void 0;
4
+ const gameLaunchConfig_1 = require("./gameLaunchConfig");
5
+ const prepareHeaders = () => ({
6
+ "Content-Type": "application/json",
7
+ // 'Content-Type': 'application/x-www-form-urlencoded',
8
+ });
9
+ const prepareUrl = (endpoint) => `${gameLaunchConfig_1.gameLaunchConfig.clientConfig.apiBaseUrl}game/${gameLaunchConfig_1.gameLaunchConfig.gameInstanceId}/${endpoint}`;
10
+ async function sendIasApiRequest(method = "GET", endpoint = "", data = {}) {
11
+ // Default options are marked with *
12
+ const response = await fetch(prepareUrl(endpoint), {
13
+ method,
14
+ mode: "cors",
15
+ cache: "no-cache",
16
+ credentials: "omit",
17
+ headers: prepareHeaders(),
18
+ redirect: "follow",
19
+ referrerPolicy: "no-referrer",
20
+ body: JSON.stringify(data), // body data type must match "Content-Type" header
21
+ });
22
+ return response.json(); // parses JSON response into native JavaScript objects
23
+ }
24
+ exports.sendIasApiRequest = sendIasApiRequest;
package/lib/index.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import { getSdkVersion, getSemverSdkVersion, isAndroid, isDev, isIos, isWeb } from "./env";
2
+ import { gameLaunchConfig } from "./gameLaunchConfig";
3
+ import { getDynamicResourceAsset } from "./gameResources";
4
+ import { sendIasApiRequest } from "./iasApi";
5
+ import { gameLocalData } from "./localData";
6
+ import { closeGameReader, createSdkApi } from "./sdkApi";
7
+ import { gameLoadedSdkCallback } from "./sdkApi/initGame";
8
+ import { openUrl } from "./sdkApi/openUrl";
9
+ import { share } from "./sdkApi/share";
10
+ import { vibrate } from "./sdkApi/vibrate";
11
+ export type { ShareData as SDKShareData } from "./sdkApi/share";
12
+ export { createSdkApi, closeGameReader, gameLoadedSdkCallback, gameLaunchConfig, isIos, isWeb, isAndroid, isDev, getSdkVersion, getSemverSdkVersion, gameLocalData, sendIasApiRequest, openUrl, share as sdkShare, vibrate as sdkVibrate, getDynamicResourceAsset };
package/lib/index.js ADDED
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDynamicResourceAsset = exports.sdkVibrate = exports.sdkShare = 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;
4
+ const env_1 = require("./env");
5
+ Object.defineProperty(exports, "getSdkVersion", { enumerable: true, get: function () { return env_1.getSdkVersion; } });
6
+ Object.defineProperty(exports, "getSemverSdkVersion", { enumerable: true, get: function () { return env_1.getSemverSdkVersion; } });
7
+ Object.defineProperty(exports, "isAndroid", { enumerable: true, get: function () { return env_1.isAndroid; } });
8
+ Object.defineProperty(exports, "isDev", { enumerable: true, get: function () { return env_1.isDev; } });
9
+ Object.defineProperty(exports, "isIos", { enumerable: true, get: function () { return env_1.isIos; } });
10
+ Object.defineProperty(exports, "isWeb", { enumerable: true, get: function () { return env_1.isWeb; } });
11
+ const gameLaunchConfig_1 = require("./gameLaunchConfig");
12
+ Object.defineProperty(exports, "gameLaunchConfig", { enumerable: true, get: function () { return gameLaunchConfig_1.gameLaunchConfig; } });
13
+ const gameResources_1 = require("./gameResources");
14
+ Object.defineProperty(exports, "getDynamicResourceAsset", { enumerable: true, get: function () { return gameResources_1.getDynamicResourceAsset; } });
15
+ const iasApi_1 = require("./iasApi");
16
+ Object.defineProperty(exports, "sendIasApiRequest", { enumerable: true, get: function () { return iasApi_1.sendIasApiRequest; } });
17
+ const localData_1 = require("./localData");
18
+ Object.defineProperty(exports, "gameLocalData", { enumerable: true, get: function () { return localData_1.gameLocalData; } });
19
+ const sdkApi_1 = require("./sdkApi");
20
+ Object.defineProperty(exports, "closeGameReader", { enumerable: true, get: function () { return sdkApi_1.closeGameReader; } });
21
+ Object.defineProperty(exports, "createSdkApi", { enumerable: true, get: function () { return sdkApi_1.createSdkApi; } });
22
+ const initGame_1 = require("./sdkApi/initGame");
23
+ Object.defineProperty(exports, "gameLoadedSdkCallback", { enumerable: true, get: function () { return initGame_1.gameLoadedSdkCallback; } });
24
+ const openUrl_1 = require("./sdkApi/openUrl");
25
+ Object.defineProperty(exports, "openUrl", { enumerable: true, get: function () { return openUrl_1.openUrl; } });
26
+ const share_1 = require("./sdkApi/share");
27
+ Object.defineProperty(exports, "sdkShare", { enumerable: true, get: function () { return share_1.share; } });
28
+ const vibrate_1 = require("./sdkApi/vibrate");
29
+ Object.defineProperty(exports, "sdkVibrate", { enumerable: true, get: function () { return vibrate_1.vibrate; } });
@@ -0,0 +1,11 @@
1
+ declare class LocalDataMap<K, V> extends Map<K, V> {
2
+ set(key: K, value: V): this;
3
+ }
4
+ export declare let gameLocalData: LocalDataMap<string, any>;
5
+ export declare const initLocalData: () => Promise<void>;
6
+ declare global {
7
+ interface Window {
8
+ gameInstanceGetLocalDataCb: (id: string, plainData: string) => void;
9
+ }
10
+ }
11
+ export {};
@@ -0,0 +1,152 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.initLocalData = exports.gameLocalData = void 0;
4
+ const uuid_1 = require("uuid");
5
+ const env_1 = require("./env");
6
+ const asyncQueue_1 = require("./asyncQueue");
7
+ const gameLaunchConfig_1 = require("./gameLaunchConfig");
8
+ const Source_1 = require("./sdkApi/web/Source");
9
+ const iasApi_1 = require("./iasApi");
10
+ class LocalDataMap extends Map {
11
+ set(key, value) {
12
+ super.set(key, value);
13
+ setGameLocalData();
14
+ return this;
15
+ }
16
+ }
17
+ exports.gameLocalData = new Map();
18
+ let localDataCreated = false;
19
+ const initLocalData = async () => {
20
+ if (localDataCreated) {
21
+ console.warn("Duplicate call of initLocalData. Skipping");
22
+ }
23
+ exports.gameLocalData = new LocalDataMap(Object.entries(await getClientLocalData()));
24
+ localDataCreated = true;
25
+ };
26
+ exports.initLocalData = initLocalData;
27
+ /**
28
+ * Fetch story local data from client device
29
+ */
30
+ const getClientLocalData = async () => {
31
+ const gameInstanceId = (0, gameLaunchConfig_1.getGameInstanceId)();
32
+ if (env_1.isDev) {
33
+ if (gameInstanceId) {
34
+ const localData = localStorage.getItem("gameCenter_" + gameInstanceId + "_data");
35
+ if (localData) {
36
+ return JSON.parse(localData);
37
+ }
38
+ }
39
+ return {};
40
+ }
41
+ console.log(`call getGameInstanceLocalData with gameInstanceId: ${gameInstanceId}`);
42
+ if (gameInstanceId == null) {
43
+ // Prevent call with incorrect storyId
44
+ console.error("Call getGameInstanceLocalData with empty `gameInstanceId`");
45
+ return {};
46
+ }
47
+ if (env_1.isAndroid) {
48
+ if ("gameInstanceGetLocalData" in window.Android) {
49
+ const localData = window.Android.gameInstanceGetLocalData(gameInstanceId);
50
+ // todo merge with server data
51
+ if (localData) {
52
+ return JSON.parse(localData);
53
+ }
54
+ }
55
+ return {};
56
+ }
57
+ else if (env_1.isIos) {
58
+ const id = (0, uuid_1.v4)();
59
+ if (window.webkit.messageHandlers.gameInstanceGetLocalData !== undefined) {
60
+ // todo merge with server data
61
+ window.webkit.messageHandlers.gameInstanceGetLocalData.postMessage(JSON.stringify({
62
+ id,
63
+ gameInstanceId,
64
+ callback: "gameInstanceGetLocalDataCb",
65
+ }));
66
+ return new Promise((resolve, reject) => {
67
+ asyncQueue_1.asyncQueue.set(id, (data) => resolve(data));
68
+ });
69
+ }
70
+ return {};
71
+ }
72
+ else if (env_1.isWeb) {
73
+ const id = (0, uuid_1.v4)();
74
+ // todo merge with server data
75
+ const plainData = JSON.stringify({
76
+ id,
77
+ gameInstanceId,
78
+ callback: "gameInstanceGetLocalDataCb",
79
+ });
80
+ if (Source_1.webSource.sourceWindow && Source_1.webSource.sourceWindowOrigin) {
81
+ Source_1.webSource.sourceWindow.postMessage(["gameInstanceGetLocalData", plainData], Source_1.webSource.sourceWindowOrigin);
82
+ }
83
+ // fallback
84
+ setTimeout(() => {
85
+ window.gameInstanceGetLocalDataCb(id, "{}");
86
+ }, 1000);
87
+ return new Promise((resolve, reject) => {
88
+ asyncQueue_1.asyncQueue.set(id, (data) => resolve(data));
89
+ });
90
+ }
91
+ };
92
+ window.gameInstanceGetLocalDataCb = function (id, plainData) {
93
+ let localData = {};
94
+ try {
95
+ localData = JSON.parse(plainData);
96
+ }
97
+ catch (e) {
98
+ console.error(e, { inputData: plainData });
99
+ }
100
+ finally {
101
+ if (asyncQueue_1.asyncQueue.has(id)) {
102
+ const cb = asyncQueue_1.asyncQueue.get(id);
103
+ cb(localData);
104
+ asyncQueue_1.asyncQueue.delete(id);
105
+ }
106
+ }
107
+ };
108
+ // api requests wrapper
109
+ const setGameLocalData = async (sendToServer = true) => {
110
+ const data = Object.fromEntries(exports.gameLocalData);
111
+ const sendDataToServer = () => (0, iasApi_1.sendIasApiRequest)("PUT", "instance-user-data", { data });
112
+ const gameInstanceId = (0, gameLaunchConfig_1.getGameInstanceId)();
113
+ if (gameInstanceId == null) {
114
+ // Prevent call with incorrect storyId
115
+ console.error("Call getGameInstanceLocalData with empty `gameInstanceId`");
116
+ return;
117
+ }
118
+ if (process.env.NODE_ENV === "development") {
119
+ const gameInstanceId = (0, gameLaunchConfig_1.getGameInstanceId)();
120
+ if (gameInstanceId) {
121
+ localStorage.setItem("gameCenter_" + gameInstanceId + "_data", JSON.stringify(data));
122
+ if (sendToServer) {
123
+ // todo implement if need it
124
+ }
125
+ }
126
+ return;
127
+ }
128
+ if (env_1.isAndroid) {
129
+ if ("gameInstanceSetLocalData" in window.Android) {
130
+ window.Android.gameInstanceSetLocalData(gameInstanceId, JSON.stringify(data), sendToServer);
131
+ }
132
+ }
133
+ else if (env_1.isIos) {
134
+ if (env_1.iosMh.gameInstanceSetLocalData !== undefined) {
135
+ env_1.iosMh.gameInstanceSetLocalData.postMessage(JSON.stringify({
136
+ gameInstanceId,
137
+ data,
138
+ sendToServer: sendToServer,
139
+ }));
140
+ }
141
+ }
142
+ else if (env_1.isWeb) {
143
+ const plainData = JSON.stringify({
144
+ gameInstanceId,
145
+ data,
146
+ sendToServer: sendToServer,
147
+ });
148
+ if (Source_1.webSource.sourceWindow && Source_1.webSource.sourceWindowOrigin) {
149
+ Source_1.webSource.sourceWindow.postMessage(["gameInstanceSetLocalData", plainData], Source_1.webSource.sourceWindowOrigin);
150
+ }
151
+ }
152
+ };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Public API for SDK
3
+ */
4
+ import { SdkApiCallbacks } from "./index.h";
5
+ export declare const createSdkApi: ({ mounted, beforeUnmount: beforeUnmountCb, onSdkCloseGameReaderIntent, onPause, onResume, onBackGesture, onAudioFocusChange }: Partial<SdkApiCallbacks>) => void;
6
+ export declare const closeGameReader: () => void;
@@ -0,0 +1,9 @@
1
+ export declare type SdkApiCallbacks = {
2
+ mounted: () => void;
3
+ beforeUnmount: () => void;
4
+ onSdkCloseGameReaderIntent: () => void;
5
+ onPause: () => void;
6
+ onResume: () => void;
7
+ onBackGesture: () => void;
8
+ onAudioFocusChange: (focusChange: number) => void;
9
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.closeGameReader = exports.createSdkApi = void 0;
4
+ const initGame_1 = require("./initGame");
5
+ const localData_1 = require("../localData");
6
+ const env_1 = require("../env");
7
+ const Source_1 = require("./web/Source");
8
+ const isFunction_1 = require("../helpers/isFunction");
9
+ const isObject_1 = require("../helpers/isObject");
10
+ let beforeUnmount;
11
+ const createSdkApi = ({ mounted, beforeUnmount: beforeUnmountCb, onSdkCloseGameReaderIntent, onPause, onResume, onBackGesture, onAudioFocusChange }) => {
12
+ beforeUnmount = beforeUnmountCb;
13
+ (0, initGame_1.createInitGame)(async () => (0, localData_1.initLocalData)(), mounted);
14
+ window.closeGameReader = () => {
15
+ if (onSdkCloseGameReaderIntent) {
16
+ onSdkCloseGameReaderIntent();
17
+ }
18
+ else {
19
+ // close important
20
+ sdkCloseGameReader();
21
+ }
22
+ // indicate for sdk
23
+ return true;
24
+ };
25
+ window.pauseUI = function () {
26
+ onPause && onPause();
27
+ };
28
+ window.resumeUI = function () {
29
+ onResume && onResume();
30
+ };
31
+ window.gameReaderGestureBack = function () {
32
+ onBackGesture && onBackGesture();
33
+ // indicate for sdk
34
+ return true;
35
+ };
36
+ window.handleAudioFocusChange = function (focusChange) {
37
+ onAudioFocusChange && onAudioFocusChange(focusChange);
38
+ };
39
+ // create bridge for web-sdk
40
+ if (env_1.isWeb) {
41
+ window.addEventListener("message", event => {
42
+ // if (event.origin !== "http://example.org:8080")
43
+ // return;
44
+ const data = event.data;
45
+ Source_1.webSource.sourceWindow = event.source;
46
+ Source_1.webSource.sourceWindowOrigin = event.origin;
47
+ // enable broadcast for corner case (VK WKWebView)
48
+ if (event.origin === "null" || event.origin == null || !Boolean(event.origin)) {
49
+ Source_1.webSource.sourceWindowOrigin = "*";
50
+ }
51
+ if (Array.isArray(data)) {
52
+ switch (data[0]) {
53
+ case "initGame":
54
+ {
55
+ // TODO - SDK version (second arg)
56
+ (0, isFunction_1.isFunction)(window.initGame) && window.initGame(data[1]);
57
+ }
58
+ break;
59
+ case "closeGameReader":
60
+ {
61
+ window.closeGameReader();
62
+ }
63
+ break;
64
+ case "shareComplete":
65
+ {
66
+ if (data[1]) {
67
+ const parsedData = data[1];
68
+ window.share_complete(parsedData.id, parsedData.isSuccess);
69
+ }
70
+ }
71
+ break;
72
+ case "cb":
73
+ {
74
+ if (data[1] && (0, isObject_1.isObject)(data[1])) {
75
+ const params = data[1];
76
+ // sendApi cb
77
+ if (params["cb"] && params["plainData"]) {
78
+ // @ts-ignore
79
+ window[params["cb"]](params["plainData"]);
80
+ }
81
+ else if (params["cb"] && params["arguments"]) {
82
+ try {
83
+ const args = JSON.parse(params["arguments"]);
84
+ if (Array.isArray(args)) {
85
+ // @ts-ignore
86
+ window[params["cb"]].apply(this, args);
87
+ }
88
+ }
89
+ catch (e) {
90
+ console.error(e);
91
+ }
92
+ }
93
+ }
94
+ }
95
+ break;
96
+ }
97
+ }
98
+ }, false);
99
+ }
100
+ };
101
+ exports.createSdkApi = createSdkApi;
102
+ /**
103
+ * API method for close Reader from game
104
+ */
105
+ const sdkCloseGameReader = (data) => {
106
+ beforeUnmount && beforeUnmount();
107
+ const devPayload = data ?? {};
108
+ const openUrl = null;
109
+ const openStory = data?.openStory != null ? data.openStory : null;
110
+ if (env_1.isAndroid) {
111
+ // {openUrl: null, openStory: {id: 1, slideIndex: 0}}
112
+ const config = JSON.stringify({ openUrl, openStory });
113
+ window.Android.gameComplete(JSON.stringify(data), JSON.stringify(devPayload), config);
114
+ }
115
+ else if (env_1.isIos) {
116
+ // {openUrl: null, openStory: {id: 1, slideIndex: 0}}
117
+ window.webkit.messageHandlers.gameComplete.postMessage(JSON.stringify({
118
+ data: data,
119
+ result: devPayload,
120
+ openUrl,
121
+ openStory
122
+ }));
123
+ }
124
+ else if (env_1.isWeb) {
125
+ if (Source_1.webSource.sourceWindow && Source_1.webSource.sourceWindowOrigin) {
126
+ Source_1.webSource.sourceWindow.postMessage(["gameComplete", data, devPayload, null], Source_1.webSource.sourceWindowOrigin);
127
+ }
128
+ }
129
+ };
130
+ const closeGameReader = () => {
131
+ sdkCloseGameReader();
132
+ };
133
+ exports.closeGameReader = closeGameReader;
@@ -0,0 +1,28 @@
1
+ import { GameLaunchConfig } from "../gameLaunchConfig.h";
2
+ declare global {
3
+ interface Window {
4
+ gameReader: GameReaderInit;
5
+ initGame: (config: GameLaunchConfig) => Promise<void>;
6
+ closeGameReader: () => true;
7
+ pauseUI: () => void;
8
+ resumeUI: () => void;
9
+ gameReaderGestureBack: () => void;
10
+ handleAudioFocusChange: (focusChange: number) => void;
11
+ __debug?: boolean;
12
+ _log: (text: string) => void;
13
+ }
14
+ }
15
+ declare type GameReaderInit = {
16
+ _e: Array<() => void>;
17
+ ready: (cb: () => void) => void;
18
+ };
19
+ export declare const createInitGame: (initLocalData: () => Promise<void>, cb?: () => void) => void;
20
+ declare type GameLoadedSdkConfig = Partial<{
21
+ showClose: boolean;
22
+ backGesture: boolean;
23
+ }>;
24
+ /**
25
+ * API method for remove loader screen from Reader
26
+ */
27
+ export declare const gameLoadedSdkCallback: (config?: Partial<GameLoadedSdkConfig>) => void;
28
+ export {};
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.gameLoadedSdkCallback = exports.createInitGame = void 0;
4
+ const isObject_1 = require("../helpers/isObject");
5
+ const gameLaunchConfig_1 = require("../gameLaunchConfig");
6
+ const env_1 = require("../env");
7
+ const Source_1 = require("./web/Source");
8
+ const gameReader = (function () {
9
+ const self = (window.gameReader || {});
10
+ self._e = self._e || [];
11
+ if (self._e) {
12
+ for (let i = 0; i < self._e.length; i++) {
13
+ setTimeout(self._e[i], 0);
14
+ }
15
+ }
16
+ self.ready = function (cb) {
17
+ cb();
18
+ };
19
+ return self;
20
+ })();
21
+ window.gameReader = gameReader;
22
+ const createInitGame = (initLocalData, cb) => {
23
+ window.initGame = async function (config) {
24
+ if (!(0, isObject_1.isObject)(config)) {
25
+ console.error("Invalid gameConfig");
26
+ return;
27
+ }
28
+ // dto -> model
29
+ (0, gameLaunchConfig_1.setGameLaunchConfig)(config);
30
+ if (gameLaunchConfig_1.gameLaunchConfig.verbose) {
31
+ // @ts-ignore
32
+ window.__config = config;
33
+ }
34
+ await initLocalData();
35
+ cb && cb();
36
+ };
37
+ };
38
+ exports.createInitGame = createInitGame;
39
+ /**
40
+ * API method for remove loader screen from Reader
41
+ */
42
+ const gameLoadedSdkCallback = (config) => {
43
+ let showClose = config?.showClose;
44
+ if (showClose == null) {
45
+ showClose = false;
46
+ }
47
+ let backGesture = config?.backGesture;
48
+ if (backGesture == null) {
49
+ backGesture = true;
50
+ }
51
+ if (env_1.isAndroid) {
52
+ if (window.Android.gameLoaded !== undefined) {
53
+ window.Android.gameLoaded(JSON.stringify({ showClose, backGesture }));
54
+ }
55
+ }
56
+ else if (env_1.isIos) {
57
+ if (env_1.iosMh.gameLoaded !== undefined) {
58
+ env_1.iosMh.gameLoaded.postMessage(JSON.stringify({ showClose, backGesture: false }));
59
+ }
60
+ }
61
+ else if (env_1.isWeb) {
62
+ if (Source_1.webSource.sourceWindow && Source_1.webSource.sourceWindowOrigin) {
63
+ Source_1.webSource.sourceWindow.postMessage(["gameLoaded", JSON.stringify({ showClose, backGesture })], Source_1.webSource.sourceWindowOrigin);
64
+ }
65
+ }
66
+ };
67
+ exports.gameLoadedSdkCallback = gameLoadedSdkCallback;
@@ -0,0 +1 @@
1
+ export declare const openUrl: (url: string) => void;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.openUrl = void 0;
4
+ const env_1 = require("../env");
5
+ const Source_1 = require("./web/Source");
6
+ const openUrl = (url) => {
7
+ if (env_1.isAndroid) {
8
+ if (window.Android.openUrl !== undefined) {
9
+ window.Android.openUrl(JSON.stringify({ url }));
10
+ }
11
+ }
12
+ else if (env_1.isIos) {
13
+ if (env_1.iosMh.openUrl !== undefined) {
14
+ env_1.iosMh.openUrl.postMessage(JSON.stringify({ url }));
15
+ }
16
+ }
17
+ else if (env_1.isWeb) {
18
+ if (Source_1.webSource.sourceWindow && Source_1.webSource.sourceWindowOrigin) {
19
+ Source_1.webSource.sourceWindow.postMessage(["openUrl", JSON.stringify({ url })], Source_1.webSource.sourceWindowOrigin);
20
+ }
21
+ }
22
+ };
23
+ exports.openUrl = openUrl;
@@ -0,0 +1,16 @@
1
+ export declare type ShareData = Partial<{
2
+ title: string | null;
3
+ text: string | null;
4
+ url: string | null;
5
+ files: Array<{
6
+ file: string;
7
+ name: string;
8
+ type: string;
9
+ } | null>;
10
+ }>;
11
+ declare global {
12
+ interface Window {
13
+ share_complete: (requestId: string, isSuccess: boolean) => void;
14
+ }
15
+ }
16
+ export declare const share: (config: ShareData) => Promise<boolean>;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.share = void 0;
4
+ const uuid_1 = require("uuid");
5
+ const asyncQueue_1 = require("../asyncQueue");
6
+ const env_1 = require("../env");
7
+ const Source_1 = require("./web/Source");
8
+ const share = async (config) => {
9
+ return new Promise((resolve, reject) => {
10
+ const id = (0, uuid_1.v4)();
11
+ const handler = () => {
12
+ if (document.visibilityState === "visible") {
13
+ resolve(true);
14
+ if (asyncQueue_1.asyncQueue.has(id)) {
15
+ asyncQueue_1.asyncQueue.delete(id);
16
+ }
17
+ }
18
+ };
19
+ if (env_1.isAndroid) {
20
+ if ("share" in window.Android) {
21
+ window.Android.share(id, JSON.stringify(config));
22
+ }
23
+ }
24
+ else if (env_1.isIos) {
25
+ if (env_1.iosMh.share && env_1.iosMh.share.postMessage) {
26
+ env_1.iosMh.share.postMessage(JSON.stringify({ id: id, config: config }));
27
+ }
28
+ }
29
+ else if (env_1.isWeb) {
30
+ if (config.files && Array.isArray(config.files) && config.files.length > 0) {
31
+ if (Source_1.webSource.sourceWindow && Source_1.webSource.sourceWindowOrigin) {
32
+ Source_1.webSource.sourceWindow.postMessage(["share", id, config], Source_1.webSource.sourceWindowOrigin);
33
+ }
34
+ }
35
+ else {
36
+ if (Source_1.webSource.sourceWindow && Source_1.webSource.sourceWindowOrigin) {
37
+ Source_1.webSource.sourceWindow.postMessage(["share", id, config], Source_1.webSource.sourceWindowOrigin);
38
+ }
39
+ }
40
+ }
41
+ asyncQueue_1.asyncQueue.set(id, (plainData) => {
42
+ resolve(plainData);
43
+ });
44
+ });
45
+ };
46
+ exports.share = share;
47
+ window.share_complete = function (requestId, isSuccess) {
48
+ try {
49
+ if (asyncQueue_1.asyncQueue.has(requestId)) {
50
+ const cb = asyncQueue_1.asyncQueue.get(requestId);
51
+ cb(isSuccess);
52
+ asyncQueue_1.asyncQueue.delete(requestId);
53
+ }
54
+ }
55
+ catch (e) {
56
+ console.error(e, { inputData: { requestId, isSuccess } });
57
+ }
58
+ };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * https://developer.mozilla.org/en-US/docs/Web/API/Vibration_API
3
+ * accept 200 | [200, 100, 200] | null | 0, [0]
4
+ *
5
+ * @param duration
6
+ * @param fallbackStyle
7
+ */
8
+ export declare const vibrate: (duration: number | Array<number> | null, fallbackStyle?: "impactLight" | "impactMedium" | "impactHeavy" | "selection" | "notificationSuccess" | "notificationWarning" | "notificationError") => void;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.vibrate = void 0;
4
+ const env_1 = require("../env");
5
+ /**
6
+ * https://developer.mozilla.org/en-US/docs/Web/API/Vibration_API
7
+ * accept 200 | [200, 100, 200] | null | 0, [0]
8
+ *
9
+ * @param duration
10
+ * @param fallbackStyle
11
+ */
12
+ const vibrate = (duration, fallbackStyle) => {
13
+ var allowedFallback = ["impactLight", "impactMedium", "impactHeavy", "selection", "notificationSuccess", "notificationWarning", "notificationError"];
14
+ let pattern = [];
15
+ if (!Array.isArray(duration)) {
16
+ if (duration == null || duration == 0) {
17
+ // send empty array to sdk
18
+ // Calling Navigator.vibrate() with a value of 0, an empty array, or an array containing all zeros will cancel any currently ongoing vibration pattern.
19
+ }
20
+ else {
21
+ pattern.push(duration);
22
+ }
23
+ }
24
+ else {
25
+ if (duration.filter(Boolean).length === 0) {
26
+ // send empty array to sdk
27
+ // Calling Navigator.vibrate() with a value of 0, an empty array, or an array containing all zeros will cancel any currently ongoing vibration pattern.
28
+ }
29
+ else {
30
+ pattern = duration;
31
+ }
32
+ }
33
+ const patternResult = pattern.map(_ => parseInt(_));
34
+ // if IS_MOBILE
35
+ if (env_1.isIos) {
36
+ if (fallbackStyle == null || allowedFallback.indexOf(fallbackStyle) === -1) {
37
+ //@ts-ignore
38
+ fallbackStyle = allowedFallback[0];
39
+ }
40
+ if (window.webkit.messageHandlers.haptic && window.webkit.messageHandlers.haptic.postMessage) {
41
+ window.webkit.messageHandlers.haptic.postMessage(JSON.stringify({ pattern: pattern, fallbackStyle: fallbackStyle, enableVibrateFallback: false }));
42
+ }
43
+ // @deprecated
44
+ // if (window.webkit.messageHandlers.vibrate !== undefined) {
45
+ // window.webkit.messageHandlers.vibrate.postMessage(JSON.stringify(patternResult));
46
+ // }
47
+ }
48
+ else {
49
+ if (window.navigator.vibrate) {
50
+ window.navigator.vibrate(patternResult);
51
+ }
52
+ }
53
+ };
54
+ exports.vibrate = vibrate;
@@ -0,0 +1,11 @@
1
+ declare class Source {
2
+ constructor();
3
+ get sourceWindowOrigin(): string | null;
4
+ set sourceWindowOrigin(value: string | null);
5
+ get sourceWindow(): Window | null;
6
+ set sourceWindow(value: Window | null);
7
+ private _sourceWindow;
8
+ private _sourceWindowOrigin;
9
+ }
10
+ export declare const webSource: Source;
11
+ export {};
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.webSource = void 0;
4
+ class Source {
5
+ constructor() {
6
+ }
7
+ get sourceWindowOrigin() {
8
+ return this._sourceWindowOrigin;
9
+ }
10
+ set sourceWindowOrigin(value) {
11
+ this._sourceWindowOrigin = value;
12
+ }
13
+ get sourceWindow() {
14
+ return this._sourceWindow;
15
+ }
16
+ set sourceWindow(value) {
17
+ this._sourceWindow = value;
18
+ }
19
+ _sourceWindow = null;
20
+ _sourceWindowOrigin = null;
21
+ }
22
+ exports.webSource = new Source();
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@inappstory/game-center-api",
3
+ "version": "1.0.0-rc.1",
4
+ "description": "",
5
+ "dependencies": {
6
+ "semver": "^7.3.8"
7
+ },
8
+ "devDependencies": {
9
+ "@tsconfig/recommended": "^1.0.2",
10
+ "@types/semver": "^7.5.0",
11
+ "npm": "latest"
12
+ },
13
+ "scripts": {
14
+ "build": "tsc",
15
+ "test": "echo \"Error: no test specified\" && exit 1",
16
+ "format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
17
+ "lint": "tslint -p tsconfig.json"
18
+ },
19
+ "files": [
20
+ "lib/**/*"
21
+ ],
22
+ "main": "lib/index.js",
23
+ "types": "lib/index.d.ts",
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "https://github.com/inappstory/game-center-api"
27
+ },
28
+ "bugs": {
29
+ "url": "https://github.com/inappstory/game-center-api/issues"
30
+ }
31
+ }