t-comm
Version:
专业、稳定、纯粹的工具库
69 lines (66 loc) • 2.57 kB
JavaScript
import { initEnv } from '../../env/env.js';
import { callJsBrowserAdapter, addMsdkNativeCallbackListener, sendToMsdkNative } from '../../msdk/msdk.js';
import { LocationFlag } from '../location-interface.js';
import '@babel/runtime/helpers/typeof';
import '../../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 (initEnv().isMsdk && options.useMsdkLocation
// && (ConfigInfo.instance.getTipGid() === GAME_HLDDZ || ConfigInfo.instance.getTipGid() === GAME_GP)
) {
callJsBrowserAdapter().then(function () {
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: 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);
}
sendToMsdkNative(requestLocationData);
})["catch"](function () {
console.log('addMsdkNativeCallbackListener error');
reject({
flag: LocationFlag.LocationFailed
});
});
} else {
reject({
flag: LocationFlag.LocationFailed
});
}
});
};
return MsdkLocation;
}();
export { MsdkLocation as default };