UNPKG

t-comm

Version:

专业、稳定、纯粹的工具库

73 lines (68 loc) 2.72 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var env_env = require('../../env/env.js'); var msdk_msdk = require('../../msdk/msdk.js'); var location_locationInterface = require('../location-interface.js'); require('@babel/runtime/helpers/typeof'); require('../../loader/little-loader.js'); // import { GAME_HLDDZ, GAME_GP } from '../../tools/game'; // import ConfigInfo from '../../config'; var MsdkLocation = /** @class */function () { function MsdkLocation() {} MsdkLocation.prototype.getLocation = function (options) { return new Promise(function (resolve, reject) { if (env_env.initEnv().isMsdk && options.useMsdkLocation // && (ConfigInfo.instance.getTipGid() === GAME_HLDDZ || ConfigInfo.instance.getTipGid() === GAME_GP) ) { msdk_msdk.callJsBrowserAdapter().then(function () { msdk_msdk.addMsdkNativeCallbackListener(function (data) { console.log('addMsdkNativeCallbackListener', data); var response; try { response = JSON.parse(data); } catch (_a) {} if ((response === null || response === void 0 ? void 0 : response.cmd) === 'reqLocation') { if ((response === null || response === void 0 ? void 0 : response.ret) === 0) { var location_1 = { lat: response.latitude || response.lat, lng: response.longitude || response.lng }; resolve({ location: location_1, flag: location_locationInterface.LocationFlag.LocationSuccess }); } else { reject({ flag: response.ret, errorMsg: response.errorMsg }); } } }); var requestLocationData = ''; // if (ConfigInfo.instance.getTipGid() === GAME_HLDDZ) { if (options.msdkLocationReqStr) { requestLocationData = options.msdkLocationReqStr; // 'fakelink://&Operation=ReqLocation'; } else { var reqData = { cmd: 'reqLocation' }; requestLocationData = JSON.stringify(reqData); } msdk_msdk.sendToMsdkNative(requestLocationData); })["catch"](function () { console.log('addMsdkNativeCallbackListener error'); reject({ flag: location_locationInterface.LocationFlag.LocationFailed }); }); } else { reject({ flag: location_locationInterface.LocationFlag.LocationFailed }); } }); }; return MsdkLocation; }(); exports["default"] = MsdkLocation;