UNPKG

t-comm

Version:

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

84 lines (77 loc) 3.35 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var _classCallCheck = require('@babel/runtime/helpers/classCallCheck'); var _createClass = require('@babel/runtime/helpers/createClass'); 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'); function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } var _classCallCheck__default = /*#__PURE__*/_interopDefaultLegacy(_classCallCheck); var _createClass__default = /*#__PURE__*/_interopDefaultLegacy(_createClass); // import { GAME_HLDDZ, GAME_GP } from '../../tools/game'; // import ConfigInfo from '../../config'; var MsdkLocation = /*#__PURE__*/function () { function MsdkLocation() { _classCallCheck__default["default"](this, MsdkLocation); } return _createClass__default["default"](MsdkLocation, [{ key: "getLocation", value: function getLocation(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 = { lat: response.latitude || response.lat, lng: response.longitude || response.lng }; resolve({ location: location, 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 }); } }); } }]); }(); exports["default"] = MsdkLocation;