UNPKG

gamelet-pixui-frame

Version:

pixui开发者框架

656 lines 34.9 kB
"use strict"; 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.JSSDKAppWindowGameletAPI = void 0; // import * as ext from '../system/exports/external'; var presetdata_mgr_1 = require("./presetdata_mgr"); var cmd_mgr_1 = require("./cmd_mgr"); var ecmd_1 = require("../../../enums/ecmd"); var stash_1 = require("./stash"); var rpc_mgr_1 = require("./rpc_mgr"); var local_dispatcher_1 = require("../../../utilities/local_dispatcher"); var utilities_1 = require("../../../utilities/utilities"); var eevents_1 = require("../../../enums/eevents"); var reporter_1 = require("./reporter"); var eplatform_1 = require("../../../enums/eplatform"); var global_data_1 = require("../../../global_data"); var utilities_2 = require("../../../utilities/utilities"); var faas_tdm_reporter_1 = require("../../../utilities/faas_tdm_reporter"); var logger_1 = require("./logger"); var JSSDKAppWindowGameletAPIImpl = /** @class */ (function () { function JSSDKAppWindowGameletAPIImpl() { var _this = this; global_data_1.GlobalData.runtimeEnv = "jssdk-appwindow"; presetdata_mgr_1.PresetDataMgr.getInstance().init(); cmd_mgr_1.CMDMgr.getInstance().init(); rpc_mgr_1.RPCMgr.getInstance().init(); local_dispatcher_1.LocalDispatcher.getInstance().init(); // CMDMgr.getInstance().regCMDHandler(ECMD.S2W_SEND_MESSAGE_TO_WINDOW, (cmd:ICMD)=>{ // LocalDispatcher.getInstance().dispatch(EEvents.L_EVT_ON_GAME_MESSAGE, cmd.args); // }); if (presetdata_mgr_1.PresetDataMgr.getInstance().getEnv().isNano) { cmd_mgr_1.CMDMgr.getInstance().regCMDHandler(ecmd_1.ECMD.S2W_REQUEST_CLOSE, function (cmd) { _this.close(); }); } if (presetdata_mgr_1.PresetDataMgr.getInstance().getGamelet().totalLogSwitch >= 0) { var totalSwitch = Boolean(presetdata_mgr_1.PresetDataMgr.getInstance().getGamelet().totalLogSwitch); var appSwitch = Boolean(presetdata_mgr_1.PresetDataMgr.getInstance().getGamelet().appLogSwitch); (0, logger_1.loggerInit)(presetdata_mgr_1.PresetDataMgr.getInstance().getGamelet().appId, presetdata_mgr_1.PresetDataMgr.getInstance().getGamelet().appVersion, totalSwitch, appSwitch); } } JSSDKAppWindowGameletAPIImpl.prototype.canUsePlatformAPI = function () { //判断pixui环境 var isInPixUI = window.navigator.userAgent.search('PixUI') >= 0; //判断js-sdk环境 var sdk_info = (0, utilities_2.getQueryParam)("env_runtimeEnv"); if (sdk_info === "jssdk" && isInPixUI) { return true; } return false; }; JSSDKAppWindowGameletAPIImpl.prototype.getRuntimeEnv = function () { return global_data_1.GlobalData.runtimeEnv; }; JSSDKAppWindowGameletAPIImpl.prototype.genAppScopeEventName = function (evt) { return "TO_APP_".concat(presetdata_mgr_1.PresetDataMgr.getInstance().getGamelet().appId, "_").concat(evt); }; JSSDKAppWindowGameletAPIImpl.prototype.getAppID = function () { if (this.userSetAppInfo && this.userSetAppInfo.appID) { return this.userSetAppInfo.appID; } return presetdata_mgr_1.PresetDataMgr.getInstance().getGamelet().appId; }; JSSDKAppWindowGameletAPIImpl.prototype.getAppId = function () { if (this.userSetAppInfo && this.userSetAppInfo.appID) { return this.userSetAppInfo.appID; } return presetdata_mgr_1.PresetDataMgr.getInstance().getGamelet().appId; }; JSSDKAppWindowGameletAPIImpl.prototype.getAppKey = function () { if (this.userSetAppInfo && this.userSetAppInfo.appKey) { return this.userSetAppInfo.appKey; } return presetdata_mgr_1.PresetDataMgr.getInstance().getGamelet().appKey; }; JSSDKAppWindowGameletAPIImpl.prototype.getAppName = function () { if (this.userSetAppInfo && this.userSetAppInfo.appName) { return this.userSetAppInfo.appName; } return presetdata_mgr_1.PresetDataMgr.getInstance().getGamelet().appName; }; JSSDKAppWindowGameletAPIImpl.prototype.getAppVersion = function () { if (this.userSetAppInfo && this.userSetAppInfo.appVersion) { return this.userSetAppInfo.appVersion; } return presetdata_mgr_1.PresetDataMgr.getInstance().getGamelet().appVersion; }; JSSDKAppWindowGameletAPIImpl.prototype.getAppEntranceConfig = function (key) { var entranceConfig = presetdata_mgr_1.PresetDataMgr.getInstance().getGamelet().entranceConfig; if (entranceConfig != undefined) { return entranceConfig[key]; } return undefined; }; JSSDKAppWindowGameletAPIImpl.prototype.getOpenArgs = function () { return presetdata_mgr_1.PresetDataMgr.getInstance().getOpenArgs(); }; JSSDKAppWindowGameletAPIImpl.prototype.getIsProductEnvironment = function () { if (this.userSetAppInfo && (typeof this.userSetAppInfo.isProductEnvironment === "boolean")) { return this.userSetAppInfo.isProductEnvironment; } return (presetdata_mgr_1.PresetDataMgr.getInstance().getEnv().isProduct == 1); }; JSSDKAppWindowGameletAPIImpl.prototype.getIsHitBackendWhitelist = function () { return (presetdata_mgr_1.PresetDataMgr.getInstance().getGamelet().isHitBackendWhitelist == 1); }; JSSDKAppWindowGameletAPIImpl.prototype.getIsSupportCallbroker = function () { return this.canUsePlatformAPI(); }; JSSDKAppWindowGameletAPIImpl.prototype.getPlatformDesc = function () { var platform = presetdata_mgr_1.PresetDataMgr.getInstance().getEnv().platform; if (platform == eplatform_1.EPLATFORM.PLATFORM_WINDOWS) { return "windows"; } if (platform == eplatform_1.EPLATFORM.PLATFORM_ANDROID) { return "android"; } if (platform == eplatform_1.EPLATFORM.PLATFORM_IOS) { return "ios"; } if (platform == eplatform_1.EPLATFORM.PLATFORM_MAC) { return "mac"; } return "unknown"; }; JSSDKAppWindowGameletAPIImpl.prototype.getEntryInfo = function () { return presetdata_mgr_1.PresetDataMgr.getInstance().getEnv().entryInfo; }; JSSDKAppWindowGameletAPIImpl.prototype.getFaasAddr = function () { return presetdata_mgr_1.PresetDataMgr.getInstance().getGamelet().faasAddr; }; JSSDKAppWindowGameletAPIImpl.prototype.getUserData = function () { return __awaiter(this, void 0, void 0, function () { var ud, compUd; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, rpc_mgr_1.RPCMgr.getInstance().callSDK("UserdataMgr.getInstance().getUserdata")]; case 1: ud = _a.sent(); compUd = (0, utilities_1.UserdataComp)(ud); console.log("app compUd : " + JSON.stringify(compUd)); return [2 /*return*/, new Promise(function (resolve, reject) { resolve(compUd); })]; } }); }); }; JSSDKAppWindowGameletAPIImpl.prototype.refreshUserDataTokens = function () { return new Promise(function (resolve, reject) { resolve(rpc_mgr_1.RPCMgr.getInstance().callSDK("UserdataMgr.getInstance().refresh")); }); }; JSSDKAppWindowGameletAPIImpl.prototype.reportJSExceptionStringToTDM = function (content) { throw new Error("reportJSExceptionStringToTDM not implemented"); }; JSSDKAppWindowGameletAPIImpl.prototype.reportStringToTDM = function (content, tag) { throw new Error("reportStringToTDM not implemented"); }; JSSDKAppWindowGameletAPIImpl.prototype.reportNumberToTDM = function (tag) { throw new Error("reportNumberToTDM not implemented"); }; JSSDKAppWindowGameletAPIImpl.prototype.faasReportStringToTDM = function (content, tag) { return __awaiter(this, void 0, void 0, function () { var ud; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.getUserData()]; case 1: ud = _a.sent(); return [2 /*return*/, (0, faas_tdm_reporter_1.FaasReportToTdm)(content, tag, 2, this.getAppID(), "index", this.getAppVersion(), ud, this.getIsProductEnvironment())]; } }); }); }; JSSDKAppWindowGameletAPIImpl.prototype.faasReportNumberToTDM = function (tag) { return __awaiter(this, void 0, void 0, function () { var ud; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.getUserData()]; case 1: ud = _a.sent(); return [2 /*return*/, (0, faas_tdm_reporter_1.FaasReportToTdm)("", tag, 0, this.getAppID(), "index", this.getAppVersion(), ud, this.getIsProductEnvironment())]; } }); }); }; JSSDKAppWindowGameletAPIImpl.prototype.setDataStash = function (dataKey, dataValue) { return stash_1.Stash.setDataStash(dataKey, dataValue, this.getAppID(), this.getAppKey()); }; JSSDKAppWindowGameletAPIImpl.prototype.getDataStash = function (dataKey) { return stash_1.Stash.getDataStash(dataKey, this.getAppID(), this.getAppKey()); }; JSSDKAppWindowGameletAPIImpl.prototype.clearDataStash = function () { return stash_1.Stash.clearDataStash(this.getAppID(), this.getAppKey()); }; /** * 写cookie文件 */ JSSDKAppWindowGameletAPIImpl.prototype.writeCookie = function (customerName, content, appId) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { return [2 /*return*/, new Promise(function (resolve, reject) { resolve(rpc_mgr_1.RPCMgr.getInstance().callSDK("CookiesMgr.getInstance().writeCookie", customerName, content, appId === null || appId === void 0 ? void 0 : appId.toString())); })]; }); }); }; JSSDKAppWindowGameletAPIImpl.prototype.writeRoleCookie = function (customerName, content, appId) { return __awaiter(this, void 0, void 0, function () { var ud, openid, roleid, k; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.getUserData()]; case 1: ud = _a.sent(); openid = ud.sOpenId || ud.openID || ""; roleid = ud.sRoleId || ud.roleID || ""; k = customerName + openid + roleid; return [2 /*return*/, new Promise(function (resolve, reject) { resolve(rpc_mgr_1.RPCMgr.getInstance().callSDK("CookiesMgr.getInstance().writeCookie", k, content, appId === null || appId === void 0 ? void 0 : appId.toString())); })]; } }); }); }; /** * 读取cookie */ JSSDKAppWindowGameletAPIImpl.prototype.readCookie = function (customerName, appId) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { return [2 /*return*/, new Promise(function (resolve, reject) { resolve(rpc_mgr_1.RPCMgr.getInstance().callSDK("CookiesMgr.getInstance().readCookie", customerName, appId === null || appId === void 0 ? void 0 : appId.toString())); })]; }); }); }; JSSDKAppWindowGameletAPIImpl.prototype.readRoleCookie = function (customerName, appId) { return __awaiter(this, void 0, void 0, function () { var ud, openid, roleid, k; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.getUserData()]; case 1: ud = _a.sent(); openid = ud.sOpenId || ud.openID || ""; roleid = ud.sRoleId || ud.roleID || ""; k = customerName + openid + roleid; return [2 /*return*/, new Promise(function (resolve, reject) { resolve(rpc_mgr_1.RPCMgr.getInstance().callSDK("CookiesMgr.getInstance().readCookie", k, appId === null || appId === void 0 ? void 0 : appId.toString())); })]; } }); }); }; /** * 删除cookie */ JSSDKAppWindowGameletAPIImpl.prototype.deleteCookie = function (customerName, appId) { return __awaiter(this, void 0, void 0, function () { var ud, openid, roleid, k; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.getUserData()]; case 1: ud = _a.sent(); openid = ud.sOpenId || ud.openID || ""; roleid = ud.sRoleId || ud.roleID || ""; k = customerName + openid + roleid; return [2 /*return*/, new Promise(function (resolve, reject) { resolve(rpc_mgr_1.RPCMgr.getInstance().callSDK("CookiesMgr.getInstance().deleteCookie", k, appId === null || appId === void 0 ? void 0 : appId.toString())); resolve(rpc_mgr_1.RPCMgr.getInstance().callSDK("CookiesMgr.getInstance().deleteCookie", customerName, appId === null || appId === void 0 ? void 0 : appId.toString())); })]; } }); }); }; JSSDKAppWindowGameletAPIImpl.prototype.addOnGameCommandListener = function (func) { this.addEventListener(eevents_1.EEvents.EVT_ON_GAME_MESSAGE, func); this.addEventListener(this.genAppScopeEventName(eevents_1.EEvents.EVT_ON_GAME_MESSAGE), func); }; JSSDKAppWindowGameletAPIImpl.prototype.removeOnGameCommandListener = function (func) { this.removeEventListener(eevents_1.EEvents.EVT_ON_GAME_MESSAGE, func); this.removeEventListener(this.genAppScopeEventName(eevents_1.EEvents.EVT_ON_GAME_MESSAGE), func); }; JSSDKAppWindowGameletAPIImpl.prototype.addOnSrvPushDataListener = function (func) { this.addEventListener(eevents_1.EEvents.EVT_ON_SRV_PUSH_DATA, func); }; JSSDKAppWindowGameletAPIImpl.prototype.removeOnSrvPushDataListener = function (func) { this.removeEventListener(eevents_1.EEvents.EVT_ON_SRV_PUSH_DATA, func); }; JSSDKAppWindowGameletAPIImpl.prototype.addEventListener = function (evt, func) { rpc_mgr_1.RPCMgr.getInstance().callSDK("Dispatcher.getInstance().add", evt, func); }; JSSDKAppWindowGameletAPIImpl.prototype.removeEventListener = function (evt, func) { rpc_mgr_1.RPCMgr.getInstance().callSDK("Dispatcher.getInstance().remove", evt, func); }; JSSDKAppWindowGameletAPIImpl.prototype.dispatchEvent = function (evt) { var _a; var args = []; for (var _i = 1; _i < arguments.length; _i++) { args[_i - 1] = arguments[_i]; } (_a = rpc_mgr_1.RPCMgr.getInstance()).callSDK.apply(_a, __spreadArray(["Dispatcher.getInstance().dispatch", evt], args, false)); }; JSSDKAppWindowGameletAPIImpl.prototype.addLocalEventListener = function (evt, func) { local_dispatcher_1.LocalDispatcher.getInstance().add(evt, func); }; JSSDKAppWindowGameletAPIImpl.prototype.removeLocalEventListener = function (evt, func) { local_dispatcher_1.LocalDispatcher.getInstance().remove(evt, func); }; JSSDKAppWindowGameletAPIImpl.prototype.dispatchLocalEvent = function (evt) { var _a; var args = []; for (var _i = 1; _i < arguments.length; _i++) { args[_i - 1] = arguments[_i]; } (_a = local_dispatcher_1.LocalDispatcher.getInstance()).dispatch.apply(_a, __spreadArray([evt], args, false)); }; JSSDKAppWindowGameletAPIImpl.prototype.callGame = function (msg) { var cmdobj = { "cmd": ecmd_1.ECMD.W2S_SEND_MSG_TO_GAME, "args": msg }; cmd_mgr_1.CMDMgr.getInstance().postMessageToSDK(JSON.stringify(cmdobj)); }; JSSDKAppWindowGameletAPIImpl.prototype.open = function (appID, extend) { // let replace = Boolean(extend["replace"]); // TODO url 从管理端配置读取,不让用户在代码里自设url。会通过url下发资源造成版本无法管理 // let cmdobj = { // "cmd": ECMD.W2S_OPEN_NEW, // "args": { // "url": url, // "name": name, // "features": features, // "replace": replace // } // }; // CMDMgr.getInstance().postMessageToSDK(JSON.stringify(cmdobj)); // 拼装发送消息给SDK,SDK层确定本活动是否使用URL以及获取地址 var cmdobj = { cmd: ecmd_1.ECMD.W2S_OPEN_NEW, args: { appID: appID, extend: extend || {} } }; cmd_mgr_1.CMDMgr.getInstance().postMessageToSDK(JSON.stringify(cmdobj)); }; JSSDKAppWindowGameletAPIImpl.prototype.close = function (appID, features) { if (presetdata_mgr_1.PresetDataMgr.getInstance().getEnv().isNano) { // we send this message only when we are running app on nano simulator // because SDK on nano simulator can not receive window close event // in-game platform will listen window's close event and get job properly done, no need to send such message var cmdobj = { "cmd": ecmd_1.ECMD.W2S_INFORM_CLOSE }; cmd_mgr_1.CMDMgr.getInstance().postMessageToSDK(JSON.stringify(cmdobj)); } if (appID == undefined || appID == this.getAppID()) { window.close(); return; } // appPage 1.2.3以上才支持 close if ((0, utilities_1.checkVersionToNumber)((0, utilities_1.getGameletInnerVersion)()) >= (0, utilities_1.checkVersionToNumber)('1.2.3')) { rpc_mgr_1.RPCMgr.getInstance().callSDK("AppWindowMgr.getInstance().closeApp", String(appID), features && features['appPage'] ? features['appPage'] : undefined); } else { // do nothing console.warn("[GameletAPI Error] GameletSDK 版本>=1.2.3时才可以在页面虚拟机中关闭指定窗口。targetAppID:" + appID); return; } }; JSSDKAppWindowGameletAPIImpl.prototype.reportStats = function (usredata, iModule, iChannelID, iType, iActId, iJumpType, sJumpURL, sRecommendID, sChangjingID, iGoodsID, iCountID, iFee, iActStyle, iFlowID, sExtendList) { reporter_1.Reporter.reportStats(usredata, iModule, iChannelID, iType, iActId, iJumpType, sJumpURL, sRecommendID, sChangjingID, iGoodsID, iCountID, iFee, "openplat", iActStyle, iFlowID, sExtendList); }; JSSDKAppWindowGameletAPIImpl.prototype.callApplicationBroker = function (commandId, subCommandId, req, callback) { return __awaiter(this, void 0, void 0, function () { var ud, reqPack; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.getUserData()]; case 1: ud = _a.sent(); reqPack = (0, utilities_1.GenCallApplicationBrokerRequest)(subCommandId, this.getAppID(), this.getAppKey(), this.getAppVersion(), req, ud); rpc_mgr_1.RPCMgr.getInstance().callSDK("BrokerSocket.getInstance().send", commandId, JSON.stringify(reqPack), callback); return [2 /*return*/]; } }); }); }; JSSDKAppWindowGameletAPIImpl.prototype.gameCustomFunction = function (functionName) { var args = []; for (var _i = 1; _i < arguments.length; _i++) { args[_i - 1] = arguments[_i]; } }; JSSDKAppWindowGameletAPIImpl.prototype.reportStatsV2 = function (iType, iChangjingId, iGoodsId, iCountId, iFee, iFlowId, extendList, appId) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { // 上报TDM/INTL/ATM // Reporter.reportStatsV2(await this.getUserData(), 0, 0, iType, this.getAppID(), 0, "", "0", iChangjingId, iGoodsId, iCountId, iFee, "openplat", 0, iFlowId, extendList) // 上报http fass appId = appId || this.getAppID(); rpc_mgr_1.RPCMgr.getInstance().callSDK("ReportMgr.getInstance().reportStats", iType, appId, iChangjingId, iGoodsId, iCountId, iFee, iFlowId, extendList); return [2 /*return*/]; }); }); }; JSSDKAppWindowGameletAPIImpl.prototype.reportMonitorV2 = function (tag, content, itype) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { // 上报TDM/INTL/ATM // Reporter.reportMonitorV2(tag, content, itype, this.getAppID(), 'index', this.getAppVersion(), await this.getUserData(), this.getIsProductEnvironment()) // 上报http fass rpc_mgr_1.RPCMgr.getInstance().callSDK("ReportMgr.getInstance().reportMonitor", content, tag, itype, this.getAppID(), this.getAppVersion()); return [2 /*return*/]; }); }); }; JSSDKAppWindowGameletAPIImpl.prototype.getArchivePath = function () { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { return [2 /*return*/, rpc_mgr_1.RPCMgr.getInstance().callSDK('Paths.getResourceArchiveExtractPath').catch(function (err) { console.error('getArchivePath error: ', err); })]; }); }); }; JSSDKAppWindowGameletAPIImpl.prototype.loadFileToArrayBuffer = function (url) { return __awaiter(this, void 0, void 0, function () { var base64Str; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, rpc_mgr_1.RPCMgr.getInstance().callSDK('Files.loadFileToArrayBuffer', url).catch(function (err) { console.error('loadFileToArrayBuffer error: ', err); })]; case 1: base64Str = _a.sent(); return [2 /*return*/, (0, utilities_1.base64ToArrayBuffer)(base64Str)]; } }); }); }; JSSDKAppWindowGameletAPIImpl.prototype.saveArrayBufferToFile = function (path, arrayBuffer) { return __awaiter(this, void 0, void 0, function () { var base64Str; return __generator(this, function (_a) { base64Str = (0, utilities_1.arrayBufferToBase64)(arrayBuffer); return [2 /*return*/, rpc_mgr_1.RPCMgr.getInstance().callSDK('Files.saveArrayBufferToFile', path, base64Str).catch(function (err) { console.error('saveArrayBufferToFile error: ', err); })]; }); }); }; JSSDKAppWindowGameletAPIImpl.prototype.loadFileToString = function (url) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { return [2 /*return*/, rpc_mgr_1.RPCMgr.getInstance().callSDK('Files.loadFileToString', url).catch(function (err) { console.error('loadFileToString error: ', err); })]; }); }); }; JSSDKAppWindowGameletAPIImpl.prototype.saveStringToFile = function (path, str) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { return [2 /*return*/, rpc_mgr_1.RPCMgr.getInstance().callSDK('Files.saveStringToFile', path, str).catch(function (err) { console.error('saveStringToFile error: ', err); })]; }); }); }; JSSDKAppWindowGameletAPIImpl.prototype.setGameletAppEnv = function (appInfo, _isProductEnvironment) { return __awaiter(this, void 0, void 0, function () { var appID, appName, appVersion, appKey, isProductEnvironment; return __generator(this, function (_a) { appID = parseInt(appInfo['appID'] || appInfo['appId']) || -1; appName = appInfo['appName'] != undefined ? appInfo['appName'] : ''; appVersion = appInfo['appVersion'] != undefined ? appInfo['appVersion'] : ''; appKey = appInfo['appKey'] != undefined ? appInfo['appKey'] : ''; isProductEnvironment = _isProductEnvironment; if (appID < 0 && !appName) { return [2 /*return*/]; } this.userSetAppInfo = {}; this.userSetAppInfo['appID'] = appID; this.userSetAppInfo['appName'] = appName; this.userSetAppInfo['appVersion'] = appVersion; this.userSetAppInfo['appKey'] = appKey; this.userSetAppInfo['isProductEnvironment'] = isProductEnvironment; rpc_mgr_1.RPCMgr.getInstance().setInstanceID(appID); return [2 /*return*/]; }); }); }; JSSDKAppWindowGameletAPIImpl.prototype.getAppInfo = function (appId, appKey) { return __awaiter(this, void 0, void 0, function () { var ret, appInfo; return __generator(this, function (_a) { switch (_a.label) { case 0: ret = {}; return [4 /*yield*/, rpc_mgr_1.RPCMgr.getInstance().callSDK('AppInfoMgr.getInstance().getAppInfoByAppID', appId.toString()).catch(function (err) { console.error('getAppInfoByAppID error: ', err); })]; case 1: appInfo = _a.sent(); if (appInfo && appInfo.id != undefined && appInfo.key != undefined && appInfo.name && appInfo.version) { if (appKey == appInfo.key) { ret = { appID: parseInt(appInfo.id), appName: appInfo.name, appKey: appInfo.key, appVersion: appInfo.version, // customConfig: appInfo.customConfig }; } else { console.error('getAppInfo error: User input invaildate appKey' + ', appID:' + appId + ' appKey:' + appKey); } } else { console.error('getAppInfo error: User input appID has no info' + ' , appID:' + appId); } return [2 /*return*/, ret]; } }); }); }; JSSDKAppWindowGameletAPIImpl.prototype.queryAppStatus = function (appId) { return __awaiter(this, void 0, void 0, function () { var ret, appInfo; return __generator(this, function (_a) { switch (_a.label) { case 0: ret = {}; return [4 /*yield*/, rpc_mgr_1.RPCMgr.getInstance().callSDK('AppInfoMgr.getInstance().getAppInfoByAppID', appId.toString()).catch(function (err) { console.error('getAppInfoByAppID error: ', err); })]; case 1: appInfo = _a.sent(); if (appInfo && appInfo.id != undefined && appInfo.key != undefined && appInfo.name && appInfo.version) { ret = { appID: parseInt(appInfo.id), appName: appInfo.name, appVersion: appInfo.version, appEntranceExecuted: appInfo.entranceExecuted, appPreprocessStarted: appInfo.preprocessVMStarted, }; } else { console.error('queryAppStatus error: User input appID has no info' + ' , appID:' + appId); } return [2 /*return*/, ret]; } }); }); }; JSSDKAppWindowGameletAPIImpl.prototype.getResourcePath = function () { return ""; }; JSSDKAppWindowGameletAPIImpl.prototype.cacheAsset = function (url, callback) { rpc_mgr_1.RPCMgr.getInstance().callSDK("AssetCacheMgr.getInstance().cacheAsset", url, callback); }; JSSDKAppWindowGameletAPIImpl.prototype.isAssetCached = function (url) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { return [2 /*return*/, rpc_mgr_1.RPCMgr.getInstance().callSDK("AssetCacheMgr.getInstance().isAssetCached", url)]; }); }); }; JSSDKAppWindowGameletAPIImpl.prototype.getAssetCachePath = function (url) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { return [2 /*return*/, new Promise(function (resolve) { rpc_mgr_1.RPCMgr.getInstance().callSDK("AssetCacheMgr.getInstance().cacheAsset", url, function (savePath, isSucess) { resolve(savePath); }); })]; }); }); }; JSSDKAppWindowGameletAPIImpl.prototype.storeAsset = function (url, callback) { rpc_mgr_1.RPCMgr.getInstance().callSDK("AssetStorageMgr.getInstance().storeAsset", url, callback); }; JSSDKAppWindowGameletAPIImpl.prototype.isAssetStored = function (url) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { return [2 /*return*/, rpc_mgr_1.RPCMgr.getInstance().callSDK("AssetStorageMgr.getInstance().isAssetStored", url)]; }); }); }; JSSDKAppWindowGameletAPIImpl.prototype.getAssetStorePath = function (url) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { return [2 /*return*/, new Promise(function (resolve, reject) { resolve(rpc_mgr_1.RPCMgr.getInstance().callSDK("AssetStorageMgr.getInstance().getAssetPath", url)); })]; }); }); }; JSSDKAppWindowGameletAPIImpl.prototype.getJSSDKVersion = function () { return ''; }; return JSSDKAppWindowGameletAPIImpl; }()); exports.JSSDKAppWindowGameletAPI = (0, utilities_1.singleton)(JSSDKAppWindowGameletAPIImpl); //# sourceMappingURL=appwindow_gameletapi.js.map