UNPKG

t-comm

Version:

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

136 lines (133 loc) 4.36 kB
import { initEnv } from '../env/env.mjs'; import { GAME_MAP } from '../launch-app/config.mjs'; import { getUrlPara } from '../url/url.mjs'; import { launchInWX, getWxGameCircleUrl } from './helper.mjs'; import '@babel/runtime/helpers/typeof'; import '../tslib.es6-096fffdd.js'; import '../loader/little-loader.mjs'; import '../msdk/msdk.mjs'; function ddzScheme(_a) { var gameId = _a.gameId, seriesId = _a.seriesId, uin = _a.uin, env = _a.env; var schemeHost = env.isIOS ? 'wx76fc280041c16519' : 'qqgame.hlddz.scheme'; var gameUrl = 'https://hlddz.huanle.qq.com/web/play.html?ADTAG=changshangsai&LoginType=Both&DefaultLoginType=WeChat&ParamType=OfflineMatch'; if (gameId || seriesId) { gameUrl += "&SeriesID=".concat(seriesId, "&GameID=").concat(gameId); } var schemeParam = "a=1&Operation=OfflineMatch&SeriesID=".concat(seriesId, "&GameID=").concat(gameId); if (uin) { gameUrl += "&uin=".concat(uin); schemeParam += "&uin=".concat(uin); } var schemeUrl = "".concat(schemeHost, "://startapp?").concat(schemeParam); return { schemeUrl: schemeUrl, schemeParam: schemeParam, gameUrl: gameUrl }; } /** * 拉起 DDZ * @param {object} params 拉起参数 * @param {string} params.seriesId series id * @param {string} params.gameId game id * @param {string} params.uin uin * @param {object} [params.context] 上下文,可传入组件实例 this * @param {object} [params.qrCodeLib] qrcode * @param {object} [params.dialogHandler] 弹窗 handler * @param {object} [params.otherDialogParams] 弹窗的其他参数 * @param {string} [params.wxJSLink] wx js link * @param {object} [params.env] 环境对象 * @returns Promise<boolean | number> * * @example * ```ts * launchDDZGameRoom({ * seriesId: '12', * gameId: '123', * uin: '222', * }) * ``` */ var launchDDZGameRoom = function launchDDZGameRoom(_a) { var _b = _a.seriesId, seriesId = _b === void 0 ? '' : _b, _c = _a.gameId, gameId = _c === void 0 ? '' : _c, _d = _a.uin, uin = _d === void 0 ? '' : _d, context = _a.context, qrCodeLib = _a.qrCodeLib, dialogHandler = _a.dialogHandler, otherDialogParams = _a.otherDialogParams, _e = _a.wxJSLink, wxJSLink = _e === void 0 ? 'https://res2.wx.qq.com/open/js/jweixin-1.6.0.js' : _e, _f = _a.env, env = _f === void 0 ? initEnv() : _f; var _g = ddzScheme({ gameId: gameId, seriesId: seriesId, uin: uin, env: env }), schemeUrl = _g.schemeUrl, schemeParam = _g.schemeParam, gameUrl = _g.gameUrl; console.info('[launchDDZGameRoom] schemeUrl: ', schemeUrl); console.info('[launchDDZGameRoom] env: ', env); return new Promise(function (resolve, _reject) { if (env.isWeixin) { launchInWX({ wxJSLink: wxJSLink, schemeUrl: schemeUrl, schemeParam: schemeParam, launchParams: { gameId: gameId, seriesId: seriesId, uin: uin }, context: context, qrCodeLib: qrCodeLib, dialogHandler: dialogHandler, otherDialogParams: otherDialogParams, resolve: resolve, reject: function reject() { _reject(); window.location.href = getWxGameCircleUrl(GAME_MAP.HLDDZ.GID); } }); return; } var fakeLink = "fakelink://&Operation=OfflineMatch&SeriesID=".concat(seriesId, "&GameID=").concat(gameId); if (uin) { fakeLink += "&uin=".concat(uin); } var ddzInGame = window.sessionStorage.getItem('ddz_ingame'); if (ddzInGame === '1' || !getUrlPara('msdkEncodeParam') && env.isMsdk) { console.info('[launchDDZGameRoom] fakeLink: ', fakeLink); if (env.isIOS) { // @ts-ignore window.location = fakeLink; } else { confirm(fakeLink); } return; } if (env.isInGame) { var js_1 = "{\"MsdkMethod\":\"WGSendMessageToNative\",\"MsgData\":\"".concat(fakeLink, "\"}"); setTimeout(function () { // 延迟关闭游戏webview if (env.isMsdk && typeof window.msdkShare === 'function' && typeof window.msdkCloseWebview === 'function') { window.msdkShare(js_1); window.msdkCloseWebview(); } }, 1); return; } window.location.href = gameUrl; resolve(1); }); }; export { launchDDZGameRoom };