UNPKG

gamelet-pixui-frame

Version:

pixui开发者框架

850 lines 39.8 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype); return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (g && (g = 0, op[0] && (_ = 0)), _) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.AppGameletAPI = void 0; /** * ------------------------------------------------------- * GameletAPI 基础接口 * + 注意其中有一些async异步函数, 为保证时序调用可以await等待 * ------------------------------------------------------- */ var igameletapi_1 = require("./interfaces/igameletapi"); var jssdk_gameletapi_1 = require("./impl/jssdkimpl/jssdk_gameletapi"); var unitygameletapi_1 = require("./impl/unitysdkimpl/unitygameletapi"); var uegameletapi_1 = require("./impl/uesdkimpl/uegameletapi"); var pxidegameletapi_1 = require("./impl/pxideimpl/pxidegameletapi"); var utilities_1 = require("./utilities/utilities"); var unsupported_gameletapi_1 = require("./impl/unsupportedimpl/unsupported_gameletapi"); //@ts-ignore var packageJson = __importStar(require("../../../package.json")); // export * from "../thirdparty/thirdparyt" var GameletAPIImpl = /** @class */ (function () { function GameletAPIImpl() { console.log("[GameletAPI constructor] packageJson.version:".concat(packageJson.version)); if (window.navigator.userAgent.search('PixUI') >= 0) { /** * 环境筛选,区分执行环境是 unity潘多拉、 GameletSDK、 pxIDE、 未支持环境(浏览器) * 目前为了兼容各种模拟器的环境不同把默认环境切换为模拟器,后续旧版模拟器废弃掉后会把默认环境切换到 UNSUPPORT_SDK */ // pxIDE使用 pxExtConfig if (globalThis.pxExtConfig) { var pxExtConfig = JSON.parse(globalThis.pxExtConfig); globalThis._sdk_info = pxExtConfig['_sdk_info']; } // @ts-ignore 西米哥要求置空创建 crash 的接口 external.crash = undefined; if ((0, utilities_1.getQueryParam)("_sdk_info") == "openplatform_unity") { // running on unity this.SDKType = igameletapi_1.RuntimeSDK.UNITY_SDK; this.gameletAPIInst = unitygameletapi_1.UnityGameletAPI.getInstance(); console.log("[GameletAPI constructor] 运行环境: PandoraUnity_SDK"); } else if ((0, utilities_1.getQueryParam)("_sdk_info") == "openplatform_ue") { // running on UE this.SDKType = igameletapi_1.RuntimeSDK.UE_SDK; this.gameletAPIInst = uegameletapi_1.UEGameletAPI.getInstance(); console.log("[GameletAPI constructor] 运行环境: PandoraUE_SDK"); } else if (window["___ns_openplatform"] || (0, utilities_1.getQueryParam)("env_runtimeEnv") == "jssdk") { // runing on js-sdk this.SDKType = igameletapi_1.RuntimeSDK.GAMELET_SDK; this.gameletAPIInst = jssdk_gameletapi_1.JSSDKGameletAPI.getInstance(); console.log("[GameletAPI constructor] \u8FD0\u884C\u73AF\u5883: GAMELET_SDK InnerVerson:".concat((0, utilities_1.getGameletInnerVersion)())); } else if ((0, utilities_1.getQueryParam)("_sdk_info") == "openplatform_pxide" || globalThis._sdk_info == "openplatform_pxide") { // running on pxIDE this.SDKType = igameletapi_1.RuntimeSDK.PXIDE_SDK; this.gameletAPIInst = pxidegameletapi_1.PxIDEGameletAPI.getInstance(); console.log("[GameletAPI constructor] 运行环境: PxIDE"); } else { // user set unsupport_sdk this.SDKType = igameletapi_1.RuntimeSDK.UNSUPPORT_SDK; this.gameletAPIInst = unsupported_gameletapi_1.UnsupportedGameletAPI.getInstance(); console.log("[GameletAPI constructor] 运行环境: UNSUPPORT_SDK"); } } else { // running on web-explorer this.SDKType = igameletapi_1.RuntimeSDK.UNSUPPORT_SDK; this.gameletAPIInst = unsupported_gameletapi_1.UnsupportedGameletAPI.getInstance(); console.log("[GameletAPI constructor] 运行环境: UNSUPPORT_SDK"); } } /** * 是否可以调用小应用平台SDK API * @returns true/false */ GameletAPIImpl.prototype.canUsePlatformAPI = function () { return this.gameletAPIInst.canUsePlatformAPI(); }; /** * 获取运行时环境. * @returns 字符串类型的运行环境标识 * + 在 JS-SDK 中返回 jssdk-appwindow / jssdk-preprocessor * + unitySDK 中返回 unity * + PxIDE 中返回 PxIDE */ GameletAPIImpl.prototype.getRuntimeEnv = function () { return this.gameletAPIInst.getRuntimeEnv(); }; /** * 获取向其他页面发送消息的完整事件名 * 本接口目前仅JS-SDK可用,unitySDK会反会空字符串 * @param evt 自定义事件 * @returns 完整的事件名 */ GameletAPIImpl.prototype.genAppScopeEventName = function (evt) { return this.gameletAPIInst.genAppScopeEventName(evt); }; /** * 获取小应用 appID, appID 是开发者在管理点申请的小应用id */ GameletAPIImpl.prototype.getAppID = function () { return this.gameletAPIInst.getAppID(); }; /** * deprecated 本接口即将废弃,请改为使用 getAppID */ GameletAPIImpl.prototype.getAppId = function () { return this.getAppID(); }; /** * 获取小应用appKey, appKey信息是运行时SDK注入的,开发者使用本接口直接获取即可 */ GameletAPIImpl.prototype.getAppKey = function () { return this.gameletAPIInst.getAppKey(); }; /** * 获取小应用appName, appName是在管理端申请小应用时填写的英文名 */ GameletAPIImpl.prototype.getAppName = function () { return this.gameletAPIInst.getAppName(); }; /** * 获取小应用appVersion, 比如"0.0.1" */ GameletAPIImpl.prototype.getAppVersion = function () { return this.gameletAPIInst.getAppVersion(); }; /** * 获取管理端开发配置中设置的entranceConfig的指定字段. * 因为entranceConfig是k-v格式,本方法接收key返回value */ GameletAPIImpl.prototype.getAppEntranceConfig = function (key) { return this.gameletAPIInst.getAppEntranceConfig(key); }; /** * 获取打开页面的open消息 * 通常open消息是游戏发过来的, 是一个JSON字符串, 其中可带一些活动需要的信息 */ GameletAPIImpl.prototype.getOpenArgs = function () { return this.gameletAPIInst.getOpenArgs(); }; /** * 获取小应用正式/测试环境,本环境对应着小应用管理端上正式/测试发布 * @returns true:正式环境 false:测试环境 */ GameletAPIImpl.prototype.getIsProductEnvironment = function () { return this.gameletAPIInst.getIsProductEnvironment(); }; /** * 获取小应用是否白名单发布 * @returns true:白名单发布 false:按区服发布 */ GameletAPIImpl.prototype.getIsHitBackendWhitelist = function () { return this.gameletAPIInst.getIsHitBackendWhitelist(); }; /** * 是当前环境否支持callbroker */ GameletAPIImpl.prototype.getIsSupportCallbroker = function () { return this.gameletAPIInst.getIsSupportCallbroker(); }; /** * 获取平台描述符 * @returns pc/android/mac/ios */ GameletAPIImpl.prototype.getPlatformDesc = function () { return this.gameletAPIInst.getPlatformDesc(); }; /** * 获取引擎信息和版本,返回值是一个JsonString */ GameletAPIImpl.prototype.getEntryInfo = function () { return this.gameletAPIInst.getEntryInfo(); }; /** * 获取管理端配置的Faas地址 * @returns 返回地址或者"" */ GameletAPIImpl.prototype.getFaasAddr = function () { return this.gameletAPIInst.getFaasAddr(); }; /** * 获取用户登录态 * @returns 登录态Object */ GameletAPIImpl.prototype.getUserData = function () { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { return [2 /*return*/, this.gameletAPIInst.getUserData()]; }); }); }; /** * 刷新 token */ GameletAPIImpl.prototype.refreshUserDataTokens = function () { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { return [2 /*return*/, this.gameletAPIInst.refreshUserDataTokens()]; }); }); }; /** * 暂存数据 * 本接口把数据暂存在内存中,当杀进程或是logout时数据会丢失。 * 本接口主要用来在数据虚拟机和页面虚拟机,或是多个页面虚拟机之间传递数据。 * 本接口仅接收string类型数据,object请JSON.stringfy()序列化后再保存。 * 数据以k-v格式记录,不同appid以相同key记录的数据不会产生冲突 * 取数据使用getDataStash */ GameletAPIImpl.prototype.setDataStash = function (key, value) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { return [2 /*return*/, this.gameletAPIInst.setDataStash(key, value)]; }); }); }; /** * 获取暂存的数据 */ GameletAPIImpl.prototype.getDataStash = function (key) { return __awaiter(this, void 0, void 0, function () { var _this = this; return __generator(this, function (_a) { return [2 /*return*/, new Promise(function (resolve) { _this.gameletAPIInst.getDataStash(key).then(function (data) { if (data === undefined) resolve(''); else resolve(data); }).catch(function (err) { return resolve(''); }); })]; }); }); }; /** * 清除暂存的数据 */ GameletAPIImpl.prototype.clearDataStash = function () { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { return [2 /*return*/, this.gameletAPIInst.clearDataStash()]; }); }); }; /** * 持久化存储数据。 * 2022.12之后新接入和升级GameletSDK的业务可使用此接口,PandoraUnitySDK 可使用本接口 * 数据以app为维度隔离存储, 可以在同一个app的不同页面对数据进行操作。不同app不能相互读取数据。存储的信息如15天不更新,会自动清除。 * 读取数据使用readCookie * @param customerName 自定义key * @param content 数据内容 * @returns 如需等待数据存储完毕需使用await */ GameletAPIImpl.prototype.writeCookie = function (customerName, content) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: if (!!content) return [3 /*break*/, 2]; return [4 /*yield*/, this.gameletAPIInst.deleteCookie(customerName, this.getAppID())]; case 1: // 数据为空时直接删除Cookie return [2 /*return*/, _a.sent()]; case 2: return [4 /*yield*/, this.gameletAPIInst.writeCookie(customerName, content, this.getAppID())]; case 3: return [2 /*return*/, _a.sent()]; } }); }); }; /** * 读取持久化数据接口 * 2022.12之后新接入和升级GameletSDK的业务可使用此接口, PandoraUnitySDK 可使用本接口 * @param customerName 自定义key * @returns 数据内容,需使用await */ GameletAPIImpl.prototype.readCookie = function (customerName) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.gameletAPIInst.readCookie(customerName, this.getAppID())]; case 1: return [2 /*return*/, _a.sent()]; } }); }); }; /** * 按角色持久化存储数据。 * 2022.12之后新接入和升级GameletSDK的业务可使用此接口,PandoraUnitySDK 可使用本接口 * 数据以app+roleId为维度隔离存储,。存储的信息如15天不更新,会自动清除。 * 读取数据使用 readRoleCookie */ GameletAPIImpl.prototype.writeRoleCookie = function (customerName, content) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: if (!!content) return [3 /*break*/, 2]; return [4 /*yield*/, this.gameletAPIInst.deleteCookie(customerName, this.getAppID())]; case 1: // 数据为空时直接删除Cookie return [2 /*return*/, _a.sent()]; case 2: return [4 /*yield*/, this.gameletAPIInst.writeRoleCookie(customerName, content, this.getAppID())]; case 3: // 获取用户 openId + roleId return [2 /*return*/, _a.sent()]; } }); }); }; /** * 读取角色维度的持久化数据接口 * 2022.12之后新接入和升级GameletSDK的业务可使用此接口, PandoraUnitySDK 可使用本接口 * @param customerName 自定义key * @returns 数据内容,需使用await */ GameletAPIImpl.prototype.readRoleCookie = function (customerName) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.gameletAPIInst.readRoleCookie(customerName, this.getAppID())]; case 1: return [2 /*return*/, _a.sent()]; } }); }); }; /** * 删除指定key的持久化内容,可以删除 writeCookie/writeRoleCookie 存储的内容 * 2022.12之后新接入和升级GameletSDK的业务可使用此接口, PandoraUnitySDK[无此接口, 调用无效] * @param customerName 自定义key * @returns 如需等待数据删除完毕需使用await */ GameletAPIImpl.prototype.deleteCookie = function (customerName) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.gameletAPIInst.deleteCookie(customerName, this.getAppID())]; case 1: return [2 /*return*/, _a.sent()]; } }); }); }; /** * 监听游戏发送事件 */ GameletAPIImpl.prototype.addOnGameCommandListener = function (func) { this.gameletAPIInst.addOnGameCommandListener(func); }; /** * 移除游戏事件的监听 * 关闭页面时要移除监听事件 */ GameletAPIImpl.prototype.removeOnGameCommandListener = function (func) { this.gameletAPIInst.removeOnGameCommandListener(func); }; /** * 监听服务端push事件 */ GameletAPIImpl.prototype.addOnSrvPushDataListener = function (func) { this.gameletAPIInst.addOnSrvPushDataListener(func); }; /** * 移除服务端事件的监听 * 关闭页面时要移除监听事件 */ GameletAPIImpl.prototype.removeOnSrvPushDataListener = function (func) { this.gameletAPIInst.removeOnSrvPushDataListener(func); }; /** * 自定义消息事件,可以用于页面间消息传递 * @param evt 事件名 * @param func 回调函数 */ GameletAPIImpl.prototype.addEventListener = function (evt, func) { this.gameletAPIInst.addEventListener(evt, func); }; /** * 移除自定义消息事件 * @param evt 事件名 * @param func 回调函数 */ GameletAPIImpl.prototype.removeEventListener = function (evt, func) { this.gameletAPIInst.removeEventListener(evt, func); }; /** * 触发自定义事件 * @param evt 事件名 * @param args 参数,通常参数是一个JSON字符串 */ GameletAPIImpl.prototype.dispatchEvent = function (evt) { var _a; var args = []; for (var _i = 1; _i < arguments.length; _i++) { args[_i - 1] = arguments[_i]; } (_a = this.gameletAPIInst).dispatchEvent.apply(_a, __spreadArray([evt], args, false)); }; /** * 增加本页面事件监听,此接口只适用于同一页面的事件处理 * 注意:数据虚拟机和页面虚拟机是两个页面,不适用于本方法 * @param evt 事件名 * @param func 回调函数 */ GameletAPIImpl.prototype.addLocalEventListener = function (evt, func) { this.gameletAPIInst.addLocalEventListener(evt, func); }; /** * 移除本页面事件监听,此接口只适用于同一页面的事件处理 * 注意:数据虚拟机和页面虚拟机是两个页面,不适用于本方法 * @param evt 事件名 * @param func 回调函数 */ GameletAPIImpl.prototype.removeLocalEventListener = function (evt, func) { this.gameletAPIInst.removeLocalEventListener(evt, func); }; /** * 触发自定义页面内事件 * @param evt 事件名 * @param args 参数,通常参数是一个JSON字符串 */ GameletAPIImpl.prototype.dispatchLocalEvent = function (evt) { var _a; var args = []; for (var _i = 1; _i < arguments.length; _i++) { args[_i - 1] = arguments[_i]; } (_a = this.gameletAPIInst).dispatchLocalEvent.apply(_a, __spreadArray([evt], args, false)); }; /** * 给游戏发送协议 * @param msg 协议体,是一个JSON字符串 */ GameletAPIImpl.prototype.callGame = function (msg) { this.gameletAPIInst.callGame(msg); }; /** * 打开一个新页面。具体逻辑是首先使用appID查询活动,当 appID 无法查询到活动信息时,则使用appName查找活动并打开对应页面。 * 注意:数据虚拟机中打开活动页面只能在白名单发布中使用 * @param appID 新页面的appid, 如果希望使用appName打开页面,appID可以填-1 * @param extend 扩展字段。k-v形式.支持打开指定页面 {appPage:"pageName"} , Unity需指定父节点层级 {parentPath:"父节点层级"} */ GameletAPIImpl.prototype.open = function (appID, extend) { this.gameletAPIInst.open(appID, extend); }; /** * 关闭页面。如果不传入appID默认调用window.close()关闭自身 * 注意:正常活动页面应直接调用window.close()关闭自身。此接口提供给地址栏使用,使用时请务必确认关闭逻辑符合预期。 * @param appID 被关闭页面的appid, 如果不填则关闭本页面 * @param extend 扩展字段。k-v形式.支持关闭指定页面 {appPage:"pageName"} */ GameletAPIImpl.prototype.close = function (appID, extend) { this.gameletAPIInst.close(appID, extend); }; /** * 调用broker长连接 * @param commandId 命令字 * @param subCommandId 子命令字 * @param req 请求结构体 * @param callback 回调函数 */ GameletAPIImpl.prototype.callApplicationBroker = function (commandId, subCommandId, req, callback) { this.gameletAPIInst.callApplicationBroker(commandId, subCommandId, req, callback); }; /** * * ------------------------------------------------------- * 数据上报相关接口 * ------------------------------------------------------- */ /** * [for GameletSDK 1.2.0] 统计数据上报接口,主要用于经分等统计。上报渠道会根据游ATM, TDM, Intl 的接入渠道自动选择 * 2022.12之后新接入和升级GameletSDK的业务可使用此接口,旧版GameletSDK和PandoraUnitySDK活动仍使用reportToATM/reportXXXToTDM做统计和监控上报 * @param iType 行为类型, 从可以1开始 * @param iChangjingId 行为中文名称,比如活动曝光 * @param iGoodsId 礼包信息,填写礼包id * @param iCountId 任务信息 * @param iFee 购买信息,填写购买数量 * @param iFlowId 推荐信息,填写推荐指标id * @param extendList 保留字段,扩展字段是一个数组(不要用object), 数组每个成员为name/value形式,例如:[{"name":"reserve0","value":"0"}, {"name":"reserve1","value":"1"}, ...],name和value的值都是字符串类型。默认支持10个扩展字段(reserve0~reserve9),需按顺序填写,多余的字段会被忽略,不会落在表里。 * 注意:1.value字段必须为string类型;2.如果扩展字段为空的话,默认不传参数即可,不要传{} * 特别注意:extendList 中的 name 必须是 reserve0 ~ reserve9, 必须从0开始保持连续,不要跳跃 */ GameletAPIImpl.prototype.reportStatsV2 = function (iType, iChangjingId, iGoodsId, iCountId, iFee, iFlowId, extendList, appID) { this.gameletAPIInst.reportStatsV2(iType, iChangjingId, iGoodsId.toString(), iCountId, iFee, iFlowId, extendList, appID); }; /** * [for GameletSDK 1.2.0] 监控上报接口,主要用于监控小应用状态。上报渠道会根据游ATM, TDM, Intl 的接入渠道自动选择 * 2022.12之后新接入和升级GameletSDK的业务可使用此接口,旧版GameletSDK和PandoraUnitySDK活动仍使用reportToATM/reportXXXToTDM做统计和监控上报 * 监控上报 * @param tag 用户自定义tag. 由字母,下划线,数字组成,长度小于32个字符 * @param content 上报内容,累加类型可以填'' * @param itype 0: 数值累加型, 2:字符串上报 */ GameletAPIImpl.prototype.reportMonitorV2 = function (tag, content, itype) { this.gameletAPIInst.reportMonitorV2(tag, content, itype); }; /** * [预留接口,暂不使用] 通过FAAS接口上报自定义字符串,注意控制上报数量 * @param content 上报的字符串内容 * @param tag 标签. 注意标签仅支持英文, 数字, 下划线 */ GameletAPIImpl.prototype.faasReportStringToTDM = function (content, tag) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { return [2 /*return*/, this.gameletAPIInst.faasReportStringToTDM(content, tag)]; }); }); }; /** * [预留接口,暂不使用] 通过FAAS接口上报累加类型 * @param tag 标签. 注意标签仅支持英文, 数字, 下划线 */ GameletAPIImpl.prototype.faasReportNumberToTDM = function (tag) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { return [2 /*return*/, this.gameletAPIInst.faasReportNumberToTDM(tag)]; }); }); }; /** * [for GameletSDK, PandoraUnitySDK] ATM 经分上报接口 * 相比 reportStats 精简了参数 * @param iType 行为类型, 从可以1开始 * @param iChangjingId 行为中文名称,比如活动曝光 * @param iGoodsId 礼包信息,填写礼包id * @param iCountId 任务信息 * @param iFee 购买信息,填写购买数量 * @param iFlowId 推荐信息,填写推荐指标id * @param extendList 保留字段,扩展字段是一个数组(不要用object), 数组每个成员为name/value形式,例如:[{"name":"reserve0","value":"0"}, {"name":"reserve1","value":"1"}, ...],name和value的值都是字符串类型。默认支持10个扩展字段(reserve0~reserve9),需按顺序填写,多余的字段会被忽略,不会落在表里。 * 注意:1.value字段必须为string类型;2.如果扩展字段为空的话,默认不传参数即可,不要传{} * 特别注意:2.extendList 中的 name 必须是 reserve0 ~ reserve9, 必须从0开始保持连续,不要跳跃 */ GameletAPIImpl.prototype.reportToATM = function (userdata, iType, iChangjingId, iGoodsId, iCountId, iFee, iFlowId, extendList) { this.gameletAPIInst.reportStats(userdata, 0, 0, iType, this.getAppID(), 0, "", "0", iChangjingId, iGoodsId, iCountId, iFee, 0, iFlowId, extendList); }; /** * [for GameletSDK, PandoraUnitySDK] ATM 经分上报接口,全参数 * 和 reportToATM 底层逻辑一致 * 特别注意:extendList 中的 name 必须是 reserve0 ~ reserve9, 必须从0开始保持连续,不要跳跃 */ GameletAPIImpl.prototype.reportStats = function (userdata, iModule, iChannelID, iType, iActId, iJumpType, sJumpURL, sRecommendID, sChangjingID, iGoodsID, iCountID, iFee, iActStyle, iFlowID, sExtendList) { this.gameletAPIInst.reportStats(userdata, iModule, iChannelID, iType, iActId, iJumpType, sJumpURL, sRecommendID, sChangjingID, iGoodsID, iCountID, iFee, iActStyle, iFlowID, sExtendList); }; /** * [Only for GameletSDK] 传入小应用的appID, appKey. 校验通过后返回应用信息. 如果传入的 appID 不存在或者 appKey 校验失败会报错并返回 {} * 传入信息正确时返回的app信息 * { * appID:number, * appName:string, * appVersion:string, * appKey:string * } */ GameletAPIImpl.prototype.getAppInfo = function (appID, appKey) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { // @ts-ignore return [2 /*return*/, this.gameletAPIInst.getAppInfo(appID, appKey)]; }); }); }; /** * [Only for GameletSDK] 查询活动加载状态(可查询其他活动) * @param appID 活动id * @returns * { * appEntranceExecuted: puerts活动是否已开始执行, * appPreprocessStarted: pixui活动虚拟机是否已启动, * } */ GameletAPIImpl.prototype.queryAppStatus = function (appID) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { // @ts-ignore return [2 /*return*/, this.gameletAPIInst.queryAppStatus(appID)]; }); }); }; /** * [Only for GameletSDK] 缓存资源到本地(存储时效15天) * @param url 资源地址 * @param callback 完成回调 */ GameletAPIImpl.prototype.cacheAsset = function (url, callback) { if (this.SDKType == igameletapi_1.RuntimeSDK.GAMELET_SDK) { this.gameletAPIInst.cacheAsset(url, callback); } }; /** * [Only for GameletSDK] 查询资源是否缓存 * @param url 资源地址 */ GameletAPIImpl.prototype.isAssetCached = function (url) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: if (!(this.SDKType == igameletapi_1.RuntimeSDK.GAMELET_SDK)) return [3 /*break*/, 2]; return [4 /*yield*/, this.gameletAPIInst.isAssetCached(url)]; case 1: return [2 /*return*/, _a.sent()]; case 2: return [2 /*return*/, false]; } }); }); }; /** * [Only for GameletSDK] 获取资源缓存路径 * @param url 资源地址 */ GameletAPIImpl.prototype.getAssetCachePath = function (url) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: if (!(this.SDKType == igameletapi_1.RuntimeSDK.GAMELET_SDK)) return [3 /*break*/, 2]; return [4 /*yield*/, this.gameletAPIInst.getAssetCachePath(url)]; case 1: return [2 /*return*/, _a.sent()]; case 2: return [2 /*return*/, '']; } }); }); }; /** * [Only for GameletSDK] 保存资源到本地(永久) * @param url 资源地址 * @param callback 完成回调 */ GameletAPIImpl.prototype.storeAsset = function (url, callback) { if (this.SDKType == igameletapi_1.RuntimeSDK.GAMELET_SDK) { this.gameletAPIInst.storeAsset(url, callback); } }; /** * [Only for GameletSDK] 查询资源是否保存 * @param url 资源地址 */ GameletAPIImpl.prototype.isAssetStored = function (url) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: if (!(this.SDKType == igameletapi_1.RuntimeSDK.GAMELET_SDK)) return [3 /*break*/, 2]; return [4 /*yield*/, this.gameletAPIInst.isAssetStored(url)]; case 1: return [2 /*return*/, _a.sent()]; case 2: return [2 /*return*/, false]; } }); }); }; /** * [Only for GameletSDK] 获取资源保存路径 * @param url 资源地址 */ GameletAPIImpl.prototype.getAssetStorePath = function (url) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: if (!(this.SDKType == igameletapi_1.RuntimeSDK.GAMELET_SDK)) return [3 /*break*/, 2]; return [4 /*yield*/, this.gameletAPIInst.getAssetStorePath(url)]; case 1: return [2 /*return*/, _a.sent()]; case 2: return [2 /*return*/, '']; } }); }); }; /** * [Only for GameletSDK] 获取JSSDK版本号(只支持在前置虚拟机中使用) */ GameletAPIImpl.prototype.getJSSDKVersion = function () { if (this.SDKType == igameletapi_1.RuntimeSDK.GAMELET_SDK) { return this.gameletAPIInst.getJSSDKVersion(); } return ''; }; /** * ------------------------------------------------------- * Pandora-Unity-SDK 开发预留接口 * ------------------------------------------------------- */ /** * [for PandoraUnitySDK] 上报异常信息到TDM,在小应用管理端 监控及告警 - 应用监控 - 标签: JSScriptException 下查询 * @param content 异常信息字符串 */ GameletAPIImpl.prototype.reportJSExceptionStringToTDM = function (content) { this.gameletAPIInst.reportJSExceptionStringToTDM(content); }; /** * [for PandoraUnitySDK] 上报自定义字符串,注意控制上报数量 * @param content 上报的字符串内容 * @param tag 标签. 注意标签仅支持英文, 数字, 下划线 */ GameletAPIImpl.prototype.reportStringToTDM = function (content, tag) { this.gameletAPIInst.reportStringToTDM(content, tag); }; /** * [for PandoraUnitySDK] 上报累加类型 * @param tag 标签. 注意标签仅支持英文, 数字, 下划线 */ GameletAPIImpl.prototype.reportNumberToTDM = function (tag) { this.gameletAPIInst.reportNumberToTDM(tag); }; /** * [for PandoraUnitySDK/UE_SDK] Pandora-Unity-SDK/UE_SDK 预留扩展方法 * 示例: await GameletAPI.gameCustomFunction("Common.IsProductEnvironment") */ GameletAPIImpl.prototype.gameCustomFunction = function (functionName) { var args = []; for (var _i = 1; _i < arguments.length; _i++) { args[_i - 1] = arguments[_i]; } return __awaiter(this, void 0, void 0, function () { var _a; return __generator(this, function (_b) { if (this.SDKType == igameletapi_1.RuntimeSDK.UNITY_SDK || this.SDKType == igameletapi_1.RuntimeSDK.UE_SDK) { return [2 /*return*/, (_a = this.gameletAPIInst).gameCustomFunction.apply(_a, __spreadArray([functionName], args, false))]; } return [2 /*return*/]; }); }); }; /** * [for GameletSDK] 仅允许GameletSDK使用, 根据 Appid 获取资源路径 (只支持在前置虚拟机中使用) * @returns */ GameletAPIImpl.prototype.getResourcePath = function () { if (this.SDKType == igameletapi_1.RuntimeSDK.GAMELET_SDK) { // @ts-ignore return this.gameletAPIInst.getResourcePath(); } return ""; }; /** * [for PxIDE][for PandoraUnitySDK][for GameletSDK] 扩展方法, 仅当多个活动存在一个页面下时才允许调用,如不确定请咨询SDK同学 * 在PxIDE和PandoraUnitySDK, GameletSDK中运行时允许用户通过本接口设置小应用环境. * 在PxIDE中运行时, 建议设置所有的环境,包括appInfo中的所有值以及isProductEnvironment,以便faas请求能够从后台拉取到数据。 * 在PandoraUnitySDK, GameletSDK中运行时,需要设置appInfo完整数据, 但不要设置 isProductEnvironment 环境信息 * * @param appInfo 用户设置的app信息,结构如下 * { * appID:number, * appName:string, * appVersion:string, * appKey:string * } * @param isProductEnvironment 选填,设置是否正式环境 */ GameletAPIImpl.prototype.setGameletAppEnv = function (appInfo, isProductEnvironment) { if (this.SDKType == igameletapi_1.RuntimeSDK.PXIDE_SDK || this.SDKType == igameletapi_1.RuntimeSDK.UNITY_SDK || this.SDKType == igameletapi_1.RuntimeSDK.GAMELET_SDK) { // @ts-ignore return this.gameletAPIInst.setGameletAppEnv(appInfo, isProductEnvironment); } }; /** * ------------------------------------------------------- * 模拟器(PxIDE/PxDEV)开发预留接口, 非模拟器运行时调用以下接口无效 * ------------------------------------------------------- */ /** * [for PxIDE] 在PxIDE中运行时允许用户通过本接口设置userdata字段 */ GameletAPIImpl.prototype.setUserData = function (userdata) { if (this.SDKType == igameletapi_1.RuntimeSDK.PXIDE_SDK) { //@ts-ignore return this.gameletAPIInst.setUserData(userdata); } }; return GameletAPIImpl; }()); exports.AppGameletAPI = (0, utilities_1.singleton)(GameletAPIImpl).getInstance(); //# sourceMappingURL=gameletapi.js.map