qqgamesdk.js 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482
  1. // (function webpackUniversalModuleDefinition(root, factory) {
  2. // if(typeof exports === 'object' && typeof module === 'object')
  3. // module.exports = factory();
  4. // else if(typeof define === 'function' && define.amd)
  5. // define([], factory);
  6. // else if(typeof exports === 'object')
  7. // exports["qqgame"] = factory();
  8. // else
  9. // root["qqgame"] = factory();
  10. // })(window, function() {
  11. // return /******/ (function(modules) { // webpackBootstrap
  12. // /******/ // The module cache
  13. // /******/ var installedModules = {};
  14. // /******/
  15. // /******/ // The require function
  16. // /******/ function __webpack_require__(moduleId) {
  17. // /******/
  18. // /******/ // Check if module is in cache
  19. // /******/ if(installedModules[moduleId]) {
  20. // /******/ return installedModules[moduleId].exports;
  21. // /******/ }
  22. // /******/ // Create a new module (and put it into the cache)
  23. // /******/ var module = installedModules[moduleId] = {
  24. // /******/ i: moduleId,
  25. // /******/ l: false,
  26. // /******/ exports: {}
  27. // /******/ };
  28. // /******/
  29. // /******/ // Execute the module function
  30. // /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  31. // /******/
  32. // /******/ // Flag the module as loaded
  33. // /******/ module.l = true;
  34. // /******/
  35. // /******/ // Return the exports of the module
  36. // /******/ return module.exports;
  37. // /******/ }
  38. // /******/
  39. // /******/
  40. // /******/ // expose the modules object (__webpack_modules__)
  41. // /******/ __webpack_require__.m = modules;
  42. // /******/
  43. // /******/ // expose the module cache
  44. // /******/ __webpack_require__.c = installedModules;
  45. // /******/
  46. // /******/ // define getter function for harmony exports
  47. // /******/ __webpack_require__.d = function(exports, name, getter) {
  48. // /******/ if(!__webpack_require__.o(exports, name)) {
  49. // /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  50. // /******/ }
  51. // /******/ };
  52. // /******/
  53. // /******/ // define __esModule on exports
  54. // /******/ __webpack_require__.r = function(exports) {
  55. // /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  56. // /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  57. // /******/ }
  58. // /******/ Object.defineProperty(exports, '__esModule', { value: true });
  59. // /******/ };
  60. // /******/
  61. // /******/ // create a fake namespace object
  62. // /******/ // mode & 1: value is a module id, require it
  63. // /******/ // mode & 2: merge all properties of value into the ns
  64. // /******/ // mode & 4: return value when already ns object
  65. // /******/ // mode & 8|1: behave like require
  66. // /******/ __webpack_require__.t = function(value, mode) {
  67. // /******/ if(mode & 1) value = __webpack_require__(value);
  68. // /******/ if(mode & 8) return value;
  69. // /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  70. // /******/ var ns = Object.create(null);
  71. // /******/ __webpack_require__.r(ns);
  72. // /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  73. // /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  74. // /******/ return ns;
  75. // /******/ };
  76. // /******/
  77. // /******/ // getDefaultExport function for compatibility with non-harmony modules
  78. // /******/ __webpack_require__.n = function(module) {
  79. // /******/ var getter = module && module.__esModule ?
  80. // /******/ function getDefault() { return module['default']; } :
  81. // /******/ function getModuleExports() { return module; };
  82. // /******/ __webpack_require__.d(getter, 'a', getter);
  83. // /******/ return getter;
  84. // /******/ };
  85. // /******/
  86. // /******/ // Object.prototype.hasOwnProperty.call
  87. // /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  88. // /******/
  89. // /******/ // __webpack_public_path__
  90. // /******/ __webpack_require__.p = "";
  91. // /******/
  92. // /******/
  93. // /******/ // Load entry module and return exports
  94. // /******/ return __webpack_require__(__webpack_require__.s = 8);
  95. // /******/ })
  96. // /************************************************************************/
  97. // /******/ ([
  98. // /* 0 */
  99. // /***/ (function(module, exports, __webpack_require__) {
  100. //
  101. // "use strict";
  102. //
  103. //
  104. // Object.defineProperty(exports, "__esModule", {
  105. // value: true
  106. // });
  107. // var isRobot = getParam('robot') == '1'; // 是否机器人
  108. // function getParam(name) {
  109. // var url = location.href;
  110. // name = name.replace(/[\[\]]/g, "\\$&");
  111. // var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)");
  112. // var results = regex.exec(url);
  113. // if (!results) return null;
  114. // if (!results[2]) return '';
  115. // return decodeURIComponent(results[2].replace(/\+/g, " "));
  116. // }
  117. //
  118. // var isIOS = function () {
  119. // var u = navigator.userAgent.toLowerCase();
  120. // var flag = u.indexOf('iphone') > -1 || u.indexOf('ipad') > -1;
  121. // return function () {
  122. // return flag;
  123. // };
  124. // }();
  125. //
  126. // var isAndroid = function () {
  127. // var u = navigator.userAgent.toLowerCase();
  128. // var flag = u.indexOf('android') > -1;
  129. // return function () {
  130. // return flag;
  131. // };
  132. // }();
  133. //
  134. // var isDebug = location.hostname === 'localhost' || !!getParam('qqdebug');
  135. //
  136. // var log = function log(msg) {
  137. // // console.log('[QQGame SDK]:', msg);
  138. // };
  139. //
  140. // var isQQGame = function isQQGame() {
  141. // if (isDebug || isRobot) {
  142. // return true;
  143. // }
  144. // return navigator.userAgent.toLowerCase().indexOf('qqgame') != -1;
  145. // };
  146. //
  147. // var userInfo = {};
  148. // var setUserInfo = function setUserInfo(info) {
  149. // if (Array.isArray(info)) {
  150. // info.forEach(function (item) {
  151. // setUserInfo(item);
  152. // });
  153. // } else if (info && info.qqgameid) {
  154. // // 兼容 gameUin 和 qqgameid
  155. // var qqgameid = info.qqgameid;
  156. // userInfo[qqgameid] = info;
  157. // }
  158. // };
  159. //
  160. // var getUserInfo = function getUserInfo(qqgameid) {
  161. // if (userInfo[qqgameid]) {
  162. // return userInfo[qqgameid];
  163. // }
  164. // return null;
  165. // };
  166. //
  167. // var getDeviceInfo = function getDeviceInfo() {
  168. // var devicePixelRatio = window.devicePixelRatio || 1;
  169. // var devInfo = {
  170. // statusBarHeight: 20
  171. // // devicePixelRatio: devicePixelRatio
  172. // };
  173. // var ua = navigator.userAgent.toLowerCase();
  174. // var res = ua.match(/StatusBarHeight\/([\d\.]+)/i);
  175. // if (Array.isArray(res) && res[1]) {
  176. // var height = parseInt(res[1]);
  177. // if (!isNaN(height)) {
  178. // devInfo.statusBarHeight = parseInt(height / devicePixelRatio);
  179. // }
  180. // }
  181. // return devInfo;
  182. // };
  183. //
  184. // var getEnv = function () {
  185. // var hallEnv = 'prod';
  186. // var ua = navigator.userAgent.toLowerCase();
  187. // var res = ua.match(/\senv\/([\d])\s/i);
  188. // if (Array.isArray(res) && res[1]) {
  189. // var env = parseInt(res[1]);
  190. // if (env == "1") {
  191. // // 测试
  192. // hallEnv = 'test';
  193. // } else if (env == "2") {
  194. // // 预发布
  195. // hallEnv = 'prev';
  196. // } else if (env == "3") {
  197. // // 正式
  198. // hallEnv = 'prod';
  199. // }
  200. // }
  201. // return function () {
  202. // if (isDebug) {
  203. // return 'test';
  204. // }
  205. // return hallEnv;
  206. // };
  207. // }();
  208. //
  209. // exports.getParam = getParam;
  210. // exports.isIOS = isIOS;
  211. // exports.isAndroid = isAndroid;
  212. // exports.isDebug = isDebug;
  213. // exports.log = log;
  214. // exports.isQQGame = isQQGame;
  215. // exports.getUserInfo = getUserInfo;
  216. // exports.setUserInfo = setUserInfo;
  217. // exports.getDeviceInfo = getDeviceInfo;
  218. // exports.getEnv = getEnv;
  219. //
  220. // /***/ }),
  221. // /* 1 */
  222. // /***/ (function(module, exports, __webpack_require__) {
  223. //
  224. // "use strict";
  225. //
  226. //
  227. // Object.defineProperty(exports, "__esModule", {
  228. // value: true
  229. // });
  230. // exports.disableRobotRender = exports.isRobotRender = exports.robotLevel = exports.isRobot = undefined;
  231. //
  232. // var _util = __webpack_require__(0);
  233. //
  234. // var isRobot = (0, _util.getParam)('robot') == '1'; // 是否机器人
  235. // var isRobotRender = (0, _util.getParam)('render') == '1'; // 用于机器人是否渲染
  236. // var robotLevel;
  237. //
  238. // if (isRobot) {
  239. // exports.robotLevel = robotLevel = (0, _util.getParam)('level');
  240. // if (robotLevel) {
  241. // exports.robotLevel = robotLevel = parseInt(robotLevel);
  242. // exports.robotLevel = robotLevel = isNaN(robotLevel) ? 1 : robotLevel; // 当参数有误时,默认机器人等级为 1
  243. // }
  244. // }
  245. //
  246. // function disableRobotRender() {
  247. // if (window.cc) {
  248. // // cocos robot 屏蔽渲染
  249. // try {
  250. // cc.director._visitScene = cc.renderer.clear = cc.renderer.rendering = function () {};
  251. // } catch (e) {}
  252. // }
  253. // }
  254. //
  255. // exports.isRobot = isRobot;
  256. // exports.robotLevel = robotLevel;
  257. // exports.isRobotRender = isRobotRender;
  258. // exports.disableRobotRender = disableRobotRender;
  259. //
  260. // /***/ }),
  261. // /* 2 */
  262. // /***/ (function(module, exports, __webpack_require__) {
  263. //
  264. // "use strict";
  265. //
  266. //
  267. // Object.defineProperty(exports, "__esModule", {
  268. // value: true
  269. // });
  270. // exports.default = frameWsInit;
  271. //
  272. // var _util = __webpack_require__(0);
  273. //
  274. // var _weblog = __webpack_require__(5);
  275. //
  276. // var _weblog2 = _interopRequireDefault(_weblog);
  277. //
  278. // var _ws = __webpack_require__(4);
  279. //
  280. // var _ws2 = _interopRequireDefault(_ws);
  281. //
  282. // function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  283. //
  284. // var setWebLog = function setWebLog() {};
  285. // var frameWsIP;
  286. // var frameWsURL;
  287. // var frameWs;
  288. // var uin;
  289. // var tableKey;
  290. // var frameSvrId;
  291. // var frameWs;
  292. // var frameFps;
  293. // var frameWsPromise;
  294. // var frameIndex = -1;
  295. // var helloTimer;
  296. // var isWsClosed = false;
  297. // var cgiPath;
  298. // var framePort;
  299. //
  300. // // 仅用于测试
  301. // var v1 = '-';
  302. // var v2 = '-';
  303. // var v3 = '-';
  304. //
  305. // var sendFrameMsg = function sendFrameMsg(msg) {
  306. // if (isWsClosed) {
  307. // return;
  308. // }
  309. // var header = '{domain=' + frameWsIP + ';cgipath=' + cgiPath + ';cgiquery=uin=' + uin + ';}';
  310. // try {
  311. // frameWs.send('' + header.length + header + JSON.stringify(msg));
  312. // } catch (e) {
  313. // (0, _util.log)('send frame msg error: ' + JSON.stringify(e));
  314. // }
  315. // };
  316. //
  317. // var sendFrameReady = function sendFrameReady() {
  318. // (0, _util.log)('send frame ready');
  319. // var body = {
  320. // "Cmd": "frame_ready",
  321. // "BackString": "frame_ready",
  322. // "MsgBody": {
  323. // "session": {
  324. // "tableKey": tableKey
  325. // },
  326. // "fps": frameFps
  327. // }
  328. // };
  329. // sendFrameMsg(body);
  330. // };
  331. //
  332. // var sendFrameHello = function sendFrameHello() {
  333. // // log(`send frame hello`);
  334. // var body = {
  335. // "Cmd": "frame_hello",
  336. // "BackString": "frame_hello",
  337. // "MsgBody": {
  338. // "session": {
  339. // "tableKey": tableKey
  340. // },
  341. // "fps": frameFps
  342. // }
  343. // };
  344. // sendFrameMsg(body);
  345. // };
  346. //
  347. // var sendFrameDataIndex = 0;
  348. // var sendTimeMap = {};
  349. // var keyFlag = Math.ceil(Math.random() * 1000000);
  350. // var sendFrameData = function sendFrameData(data) {
  351. // if (_util.isDebug) {
  352. // data.testkey = 'testkey_' + keyFlag + '_' + sendFrameDataIndex++;
  353. // data.testtime = Date.now();
  354. // data.testFrameIndex = frameIndex;
  355. // sendTimeMap[data.testkey] = data.testtime;
  356. // // log('send frame data');
  357. // }
  358. // var body = {
  359. // "Cmd": "frame_transmit",
  360. // "BackString": "frame_transmit",
  361. // "MsgBody": {
  362. // "session": {
  363. // "tableKey": tableKey
  364. // },
  365. // "frameData": data
  366. // }
  367. // };
  368. // sendFrameMsg(body);
  369. // };
  370. //
  371. // var sendFrameStop = function sendFrameStop() {
  372. // clearInterval(helloTimer);
  373. // (0, _util.log)('send frame stop');
  374. // var body = {
  375. // "Cmd": "frame_stop",
  376. // "BackString": "frame_stop",
  377. // "MsgBody": {
  378. // "session": {
  379. // "tableKey": tableKey
  380. // }
  381. // }
  382. // };
  383. // sendFrameMsg(body);
  384. // frameWs && frameWs.close && frameWs.close();
  385. // isWsClosed = true;
  386. // };
  387. //
  388. // var lastFrameMsgTime;
  389. // var lastHelloMsgTime;
  390. //
  391. // function onFrameMessage(frames) {
  392. // var currentTime = Date.now();
  393. // if (lastFrameMsgTime) {
  394. // var cost = currentTime - lastFrameMsgTime; // 两帧时间差
  395. // frameIndex = frames.frameIndex;
  396. // //if (cost > 70) {
  397. // // log(`frameTestGap2, ${cost}, ${frameIndex}`);
  398. // //}
  399. // // log(`frameTestGap, ${cost}, ${frameIndex}`);
  400. // if (frames.frameData) {
  401. // var testkey = frames.frameData[0].testkey;
  402. // var testtime = frames.frameData[0].testtime;
  403. // v1 = frameIndex - frames.frameData[0].testFrameIndex;
  404. // // log(`frameIndexGap, ${v1}`); // 帧差
  405. // if (sendTimeMap[testkey]) {
  406. // v3 = currentTime - testtime;
  407. // (0, _util.log)('\u81EA\u53D1\u81EA\u6536\u5EF6\u8FDF ' + v3);
  408. // delete sendTimeMap[testkey];
  409. // }
  410. // var text = '\u5E27\u5DEE: ' + v1 + ', \u81EA\u53D1\u81EA\u6536\u5EF6\u8FDF: ' + v3 + ', hello\u5EF6\u8FDF: ' + v2;
  411. // setWebLog(text);
  412. // }
  413. // }
  414. // lastFrameMsgTime = currentTime;
  415. // }
  416. //
  417. // var frameWsConnect = function frameWsConnect(onMessage) {
  418. // return new Promise(function (resolve, reject) {
  419. // frameWs = new _ws2.default(frameWsURL);
  420. // frameWs.onopen = function () {
  421. // (0, _util.log)('frame ws open');
  422. // sendFrameReady();
  423. // };
  424. // frameWs.onmessage = function (data) {
  425. // var msg = data.data;
  426. // msg = JSON.parse(msg);
  427. // var cmd = msg.Cmd;
  428. //
  429. // if (cmd == 'frame_start') {
  430. // (0, _util.log)('frame start');
  431. // resolve();
  432. // // 发送hello包
  433. // clearInterval(helloTimer);
  434. // helloTimer = setInterval(function () {
  435. // sendFrameHello();
  436. // lastHelloMsgTime = Date.now();
  437. // }, 1000);
  438. // } else if (cmd == 'frame_transmit') {
  439. // if (msg.MsgBody && msg.MsgBody.frames && msg.MsgBody.frames[0]) {
  440. // var frames = msg.MsgBody.frames[0];
  441. // _util.isDebug && onFrameMessage(frames);
  442. // onMessage(frames);
  443. // }
  444. // } else if (cmd == 'frame_hello') {
  445. // if (_util.isDebug) {
  446. // v2 = Date.now() - lastHelloMsgTime;
  447. // (0, _util.log)('frameTestHello ' + v2);
  448. // var text = '\u5E27\u5DEE: ' + v1 + ', \u81EA\u53D1\u81EA\u6536\u5EF6\u8FDF: ' + v3 + ', hello\u5EF6\u8FDF: ' + v2;
  449. // setWebLog(text);
  450. // }
  451. // }
  452. // };
  453. //
  454. // frameWs.onclose = function () {
  455. // // isWsClosed = true;
  456. // (0, _util.log)('frame ws close');
  457. // };
  458. //
  459. // frameWs.onerror = function (error) {
  460. // (0, _util.log)('frame ws error ' + JSON.stringify(error));
  461. // };
  462. // });
  463. // };
  464. //
  465. // function frameWsInit(options) {
  466. // if (_util.isDebug) {
  467. // setWebLog = (0, _weblog2.default)();
  468. // }
  469. // uin = options.uin;
  470. // tableKey = options.tableKey;
  471. // frameSvrId = options.frameSvrId;
  472. // frameFps = options.frameFps;
  473. // frameWsIP = options.frameURL;
  474. // framePort = options.framePort;
  475. // frameWsURL = frameWsIP + ':' + framePort;
  476. // cgiPath = options.cgiPath;
  477. // // console.log(`frameWsURL ${frameWsURL}`)
  478. // var onMessage = options.onMessage || function () {};
  479. // var wsPromise = frameWsConnect(onMessage);
  480. // return {
  481. // wsPromise: wsPromise,
  482. // send: sendFrameData,
  483. // stop: sendFrameStop
  484. // };
  485. // }
  486. //
  487. // /***/ }),
  488. // /* 3 */
  489. // /***/ (function(module, exports, __webpack_require__) {
  490. //
  491. // "use strict";
  492. //
  493. //
  494. // Object.defineProperty(exports, "__esModule", {
  495. // value: true
  496. // });
  497. //
  498. // var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  499. //
  500. // exports.default = function (qqgame) {
  501. // // qqgame.disableRobotRender = disableRobotRender;
  502. // if (_robot.isRobot) {
  503. // (0, _robot.disableRobotRender)(); // 正式环境关闭渲染
  504. // }
  505. //
  506. // var invokeClient = function invokeClient(name, params) {
  507. // var jsonString = JSON.stringify({
  508. // 'eID': name,
  509. // 'ePara': params
  510. // });
  511. // if (_robot.isRobot) {
  512. // try {
  513. // window.pvpRequest(jsonString);
  514. // } catch (e) {}
  515. // } else {
  516. // try {
  517. // if ((0, _util.isAndroid)()) {
  518. // if (window.qqgame && window.qqgame.pvpRequest) {
  519. // window.qqgame.pvpRequest(jsonString);
  520. // }
  521. // } else if ((0, _util.isIOS)()) {
  522. // if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.pvpRequest && window.webkit.messageHandlers.pvpRequest.postMessage) {
  523. // window.webkit.messageHandlers.pvpRequest.postMessage(jsonString);
  524. // }
  525. // }
  526. // } catch (e) {}
  527. // }
  528. // };
  529. //
  530. // qqgame.invoke = function (name, params) {
  531. // // 加防护,游戏结算后,不再接受游戏的invoke
  532. // if (isGameEnd) {
  533. // return;
  534. // }
  535. //
  536. // params = params || {};
  537. // (0, _util.log)('invoke ' + name + ' ' + JSON.stringify(params));
  538. //
  539. // if (name == "frameData") {
  540. // // 用户的操作消息
  541. // /* if (params && params.data && params.data.id == debugUserId && params.data.msgKey) {
  542. // var t = Date.now();
  543. // var msgKey = params.data.msgKey;
  544. // debugMsgMap[msgKey] = t;
  545. // } */
  546. // frameWs.send(params);
  547. // // qqgame.invoke('frameDataByUDP', params);
  548. // return;
  549. // }
  550. //
  551. // if (name == 'gameInit' && params.openFraming) {
  552. // isFrameGame = true;
  553. // frameFps = params.fpsExpect || 5;
  554. // params.openFraming = undefined;
  555. // params.fpsExpect = undefined;
  556. // }
  557. //
  558. // /* if (debugMode) {
  559. // if (name == 'frameData') {
  560. // var debugMsgKey = `${debugUserKey}_${Math.ceil(Math.random() * 100000)}`;
  561. // debugKeyMap[debugMsgKey] = Date.now();
  562. // params.debugMsgKey = debugMsgKey;
  563. // }
  564. // } */
  565. //
  566. // // 查看用户信息
  567. // if (name == "showUser" && (params.gameUin || params.qqgameid)) {
  568. // var qqgameid = params.gameUin || params.qqgameid;
  569. // var userInfo = (0, _util.getUserInfo)(qqgameid) || {}; // 可能返回 null
  570. // params = Object.assign(params, userInfo);
  571. // }
  572. //
  573. // // 加防护,游戏结算后,不再接受游戏的invoke
  574. // if (name === 'gameResult') {
  575. // if (params.result && params.result.win == qqgame.RESULT_LEAVE) {
  576. // // 结算页不处理逃跑,将逃跑转为失败
  577. // params.result.win = qqgame.RESULT_LOSE;
  578. // }
  579. // if (!params.gameType) {
  580. // params.gameType = "COCOS";
  581. // }
  582. // isGameEnd = true;
  583. //
  584. // if (isFrameGame) {
  585. // frameWs.stop();
  586. // }
  587. // }
  588. //
  589. // invokeClient(name, params);
  590. // };
  591. //
  592. // // 客户端心跳
  593. // if (!_robot.isRobot) {
  594. // setInterval(function () {
  595. // invokeClient('watchDog');
  596. // }, 3000);
  597. // }
  598. //
  599. // var cbList = [];
  600. // qqgame.onMessage = function (cb) {
  601. // cbList.push(cb);
  602. // };
  603. //
  604. // // 客户端调用页面提供的接口
  605. // qqgame.pvpResponse = function (data) {
  606. // if ((typeof data === 'undefined' ? 'undefined' : _typeof(data)) !== 'object') {
  607. // data = JSON.parse(data);
  608. // }
  609. //
  610. // var msgType = data.eID;
  611. // var msgData = data.ePara;
  612. //
  613. // if (msgType === 'gameReset') {
  614. // isGameEnd = false;
  615. // // isChannelCreated = false;
  616. // }
  617. //
  618. // // 加防护,游戏结算后,不再接受客户端的消息
  619. // if (isGameEnd) {
  620. // return;
  621. // }
  622. //
  623. // if (msgType !== 'frameData') {
  624. // (0, _util.log)('onMessage ' + JSON.stringify(data));
  625. // }
  626. //
  627. // if (msgType == 'frameData') {
  628. // if (Array.isArray(msgData.frames)) {
  629. // msgData = msgData.frames[0];
  630. // }
  631. // }
  632. //
  633. // // 保存用户信息
  634. // if (msgType == 'channelCreated') {
  635. // var playerInfos = msgData.playerInfos;
  636. // (0, _util.setUserInfo)(playerInfos);
  637. // }
  638. //
  639. // if (msgType == "channelCreating") {
  640. // if (isFrameGame) {
  641. // tableKey = msgData.tableKey;
  642. // cgiPath = msgData.url.transmitSvr.cgipath;
  643. // frameURL = msgData.url.transmitSvr.domain;
  644. // framePort = msgData.url.transmitSvr.port;
  645. // }
  646. // return;
  647. // }
  648. //
  649. // // 如果是帧同步,拦截channelCreated,等直连成功后,再通知游戏channelCreated
  650. // if (msgType == "channelCreated") {
  651. // if (isFrameGame) {
  652. // uin = msgData.playerInfos[0].qqgameid;
  653. // // debugUserId = 1000 + msgData.playerInfos[0].seat;
  654. // frameWs = (0, _frame2.default)({
  655. // uin: uin,
  656. // frameFps: frameFps,
  657. // tableKey: tableKey,
  658. // cgiPath: cgiPath,
  659. // frameURL: frameURL,
  660. // framePort: framePort,
  661. // onMessage: function onMessage(data) {
  662. // pvpResponse('frameData', data);
  663. // /* qqgame.pvpResponse({
  664. // eID: 'frameData',
  665. // ePara: data
  666. // }); */
  667. // }
  668. // });
  669. // frameWs.wsPromise.then(function () {
  670. // // isChannelCreated = true;
  671. // // qqgame.pvpResponse(data);
  672. // pvpResponse(msgType, msgData);
  673. // });
  674. // return;
  675. // }
  676. // }
  677. //
  678. // /* if (msgType == 'frameData') {
  679. // if (Array.isArray(msgData.frames)) {
  680. // msgData = msgData.frames[0];
  681. // if (debugMode) {
  682. // var data = msgData;
  683. // var index = data.frameIndex;
  684. // if (Array.isArray(data.frameData)) {
  685. // data.frameData.forEach((frameItem) => {
  686. // var msgKey = frameItem.debugMsgKey;
  687. // if (debugKeyMap[msgKey]) {
  688. // var sendTime = debugKeyMap[msgKey];
  689. // var t = Date.now();
  690. // log(`自发自收延迟: ${t - sendTime}`)
  691. // delete debugKeyMap[msgKey];
  692. // }
  693. // });
  694. // }
  695. // }
  696. // } else {
  697. // return;
  698. // }
  699. // }*/
  700. //
  701. // pvpResponse(msgType, msgData);
  702. // };
  703. //
  704. // qqgame.setDebugAppid = function () {};
  705. //
  706. // var pvpResponse = function pvpResponse(msgType, msgData) {
  707. // cbList.forEach(function (cb) {
  708. // cb(msgType, msgData);
  709. // });
  710. // };
  711. // };
  712. //
  713. // var _util = __webpack_require__(0);
  714. //
  715. // var _robot = __webpack_require__(1);
  716. //
  717. // var _frame = __webpack_require__(2);
  718. //
  719. // var _frame2 = _interopRequireDefault(_frame);
  720. //
  721. // function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  722. //
  723. // var debugMode = false;
  724. // // var debugUserId;
  725. // // var debugMsgMap = {};
  726. // // 都是帧同步相关
  727. // var isFrameGame = false;
  728. // var frameFps = 5;
  729. // var frameWs;
  730. // var uin;
  731. // var frameURL;
  732. // var framePort;
  733. // var cgiPath;
  734. // var tableKey;
  735. // var frameSvrId;
  736. //
  737. // var isGameEnd = false;
  738. // // var debugKeyMap = {}; // 調試使用
  739. // // var debugUserKey = Math.ceil(Math.random() * 100000); // 調試使用
  740. //
  741. // /***/ }),
  742. // /* 4 */
  743. // /***/ (function(module, exports, __webpack_require__) {
  744. //
  745. // "use strict";
  746. // var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;
  747. //
  748. // // MIT License:
  749. // //
  750. // // Copyright (c) 2010-2012, Joe Walnes
  751. // //
  752. // // Permission is hereby granted, free of charge, to any person obtaining a copy
  753. // // of this software and associated documentation files (the "Software"), to deal
  754. // // in the Software without restriction, including without limitation the rights
  755. // // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  756. // // copies of the Software, and to permit persons to whom the Software is
  757. // // furnished to do so, subject to the following conditions:
  758. // //
  759. // // The above copyright notice and this permission notice shall be included in
  760. // // all copies or substantial portions of the Software.
  761. // //
  762. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  763. // // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  764. // // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  765. // // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  766. // // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  767. // // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  768. // // THE SOFTWARE.
  769. //
  770. // /**
  771. // * This behaves like a WebSocket in every way, except if it fails to connect,
  772. // * or it gets disconnected, it will repeatedly poll until it successfully connects
  773. // * again.
  774. // *
  775. // * It is API compatible, so when you have:
  776. // * ws = new WebSocket('ws://....');
  777. // * you can replace with:
  778. // * ws = new ReconnectingWebSocket('ws://....');
  779. // *
  780. // * The event stream will typically look like:
  781. // * onconnecting
  782. // * onopen
  783. // * onmessage
  784. // * onmessage
  785. // * onclose // lost connection
  786. // * onconnecting
  787. // * onopen // sometime later...
  788. // * onmessage
  789. // * onmessage
  790. // * etc...
  791. // *
  792. // * It is API compatible with the standard WebSocket API, apart from the following members:
  793. // *
  794. // * - `bufferedAmount`
  795. // * - `extensions`
  796. // * - `binaryType`
  797. // *
  798. // * Latest version: https://github.com/joewalnes/reconnecting-websocket/
  799. // * - Joe Walnes
  800. // *
  801. // * Syntax
  802. // * ======
  803. // * var socket = new ReconnectingWebSocket(url, protocols, options);
  804. // *
  805. // * Parameters
  806. // * ==========
  807. // * url - The url you are connecting to.
  808. // * protocols - Optional string or array of protocols.
  809. // * options - See below
  810. // *
  811. // * Options
  812. // * =======
  813. // * Options can either be passed upon instantiation or set after instantiation:
  814. // *
  815. // * var socket = new ReconnectingWebSocket(url, null, { debug: true, reconnectInterval: 4000 });
  816. // *
  817. // * or
  818. // *
  819. // * var socket = new ReconnectingWebSocket(url);
  820. // * socket.debug = true;
  821. // * socket.reconnectInterval = 4000;
  822. // *
  823. // * debug
  824. // * - Whether this instance should log debug messages. Accepts true or false. Default: false.
  825. // *
  826. // * automaticOpen
  827. // * - Whether or not the websocket should attempt to connect immediately upon instantiation. The socket can be manually opened or closed at any time using ws.open() and ws.close().
  828. // *
  829. // * reconnectInterval
  830. // * - The number of milliseconds to delay before attempting to reconnect. Accepts integer. Default: 1000.
  831. // *
  832. // * maxReconnectInterval
  833. // * - The maximum number of milliseconds to delay a reconnection attempt. Accepts integer. Default: 30000.
  834. // *
  835. // * reconnectDecay
  836. // * - The rate of increase of the reconnect delay. Allows reconnect attempts to back off when problems persist. Accepts integer or float. Default: 1.5.
  837. // *
  838. // * timeoutInterval
  839. // * - The maximum time in milliseconds to wait for a connection to succeed before closing and retrying. Accepts integer. Default: 2000.
  840. // *
  841. // */
  842. // (function (global, factory) {
  843. // if (true) {
  844. // !(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory),
  845. // __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ?
  846. // (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__),
  847. // __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  848. // } else {}
  849. // })(undefined, function () {
  850. //
  851. // if (!('WebSocket' in window)) {
  852. // return;
  853. // }
  854. //
  855. // function ReconnectingWebSocket(url, protocols, options) {
  856. //
  857. // // Default settings
  858. // var settings = {
  859. //
  860. // /** Whether this instance should log debug messages. */
  861. // debug: false,
  862. //
  863. // /** Whether or not the websocket should attempt to connect immediately upon instantiation. */
  864. // automaticOpen: true,
  865. //
  866. // /** The number of milliseconds to delay before attempting to reconnect. */
  867. // reconnectInterval: 1000,
  868. // /** The maximum number of milliseconds to delay a reconnection attempt. */
  869. // maxReconnectInterval: 30000,
  870. // /** The rate of increase of the reconnect delay. Allows reconnect attempts to back off when problems persist. */
  871. // reconnectDecay: 1.5,
  872. //
  873. // /** The maximum time in milliseconds to wait for a connection to succeed before closing and retrying. */
  874. // timeoutInterval: 2000,
  875. //
  876. // /** The maximum number of reconnection attempts to make. Unlimited if null. */
  877. // maxReconnectAttempts: 100, // null,
  878. //
  879. // /** The binary type, possible values 'blob' or 'arraybuffer', default 'blob'. */
  880. // binaryType: 'blob'
  881. // };
  882. // if (!options) {
  883. // options = {};
  884. // }
  885. //
  886. // // Overwrite and define settings with options if they exist.
  887. // for (var key in settings) {
  888. // if (typeof options[key] !== 'undefined') {
  889. // this[key] = options[key];
  890. // } else {
  891. // this[key] = settings[key];
  892. // }
  893. // }
  894. //
  895. // // These should be treated as read-only properties
  896. //
  897. // /** The URL as resolved by the constructor. This is always an absolute URL. Read only. */
  898. // this.url = url;
  899. //
  900. // /** The number of attempted reconnects since starting, or the last successful connection. Read only. */
  901. // this.reconnectAttempts = 0;
  902. //
  903. // /**
  904. // * The current state of the connection.
  905. // * Can be one of: WebSocket.CONNECTING, WebSocket.OPEN, WebSocket.CLOSING, WebSocket.CLOSED
  906. // * Read only.
  907. // */
  908. // this.readyState = WebSocket.CONNECTING;
  909. //
  910. // /**
  911. // * A string indicating the name of the sub-protocol the server selected; this will be one of
  912. // * the strings specified in the protocols parameter when creating the WebSocket object.
  913. // * Read only.
  914. // */
  915. // this.protocol = null;
  916. //
  917. // // Private state variables
  918. //
  919. // var self = this;
  920. // var ws;
  921. // var forcedClose = false;
  922. // var timedOut = false;
  923. // var eventTarget = document.createElement('div');
  924. //
  925. // // Wire up "on*" properties as event handlers
  926. //
  927. // eventTarget.addEventListener('open', function (event) {
  928. // self.onopen(event);
  929. // });
  930. // eventTarget.addEventListener('close', function (event) {
  931. // self.onclose(event);
  932. // });
  933. // eventTarget.addEventListener('connecting', function (event) {
  934. // self.onconnecting(event);
  935. // });
  936. // eventTarget.addEventListener('message', function (event) {
  937. // self.onmessage(event);
  938. // });
  939. // eventTarget.addEventListener('error', function (event) {
  940. // self.onerror(event);
  941. // });
  942. //
  943. // // Expose the API required by EventTarget
  944. //
  945. // this.addEventListener = eventTarget.addEventListener.bind(eventTarget);
  946. // this.removeEventListener = eventTarget.removeEventListener.bind(eventTarget);
  947. // this.dispatchEvent = eventTarget.dispatchEvent.bind(eventTarget);
  948. //
  949. // /**
  950. // * This function generates an event that is compatible with standard
  951. // * compliant browsers and IE9 - IE11
  952. // *
  953. // * This will prevent the error:
  954. // * Object doesn't support this action
  955. // *
  956. // * http://stackoverflow.com/questions/19345392/why-arent-my-parameters-getting-passed-through-to-a-dispatched-event/19345563#19345563
  957. // * @param s String The name that the event should use
  958. // * @param args Object an optional object that the event will use
  959. // */
  960. // function generateEvent(s, args) {
  961. // var evt = document.createEvent("CustomEvent");
  962. // evt.initCustomEvent(s, false, false, args);
  963. // return evt;
  964. // };
  965. //
  966. // this.open = function (reconnectAttempt) {
  967. // ws = new WebSocket(self.url, protocols || []);
  968. // ws.binaryType = this.binaryType;
  969. //
  970. // if (reconnectAttempt) {
  971. // if (this.maxReconnectAttempts && this.reconnectAttempts > this.maxReconnectAttempts) {
  972. // return;
  973. // }
  974. // } else {
  975. // eventTarget.dispatchEvent(generateEvent('connecting'));
  976. // this.reconnectAttempts = 0;
  977. // }
  978. //
  979. // if (self.debug || ReconnectingWebSocket.debugAll) {
  980. // console.debug('ReconnectingWebSocket', 'attempt-connect', self.url);
  981. // }
  982. //
  983. // var localWs = ws;
  984. // var timeout = setTimeout(function () {
  985. // if (self.debug || ReconnectingWebSocket.debugAll) {
  986. // console.debug('ReconnectingWebSocket', 'connection-timeout', self.url);
  987. // }
  988. // timedOut = true;
  989. // localWs.close();
  990. // timedOut = false;
  991. // }, self.timeoutInterval);
  992. //
  993. // ws.onopen = function (event) {
  994. // clearTimeout(timeout);
  995. // if (self.debug || ReconnectingWebSocket.debugAll) {
  996. // console.debug('ReconnectingWebSocket', 'onopen', self.url);
  997. // }
  998. // self.protocol = ws.protocol;
  999. // self.readyState = WebSocket.OPEN;
  1000. // self.reconnectAttempts = 0;
  1001. // var e = generateEvent('open');
  1002. // e.isReconnect = reconnectAttempt;
  1003. // reconnectAttempt = false;
  1004. // eventTarget.dispatchEvent(e);
  1005. // };
  1006. //
  1007. // ws.onclose = function (event) {
  1008. // clearTimeout(timeout);
  1009. // ws = null;
  1010. // if (forcedClose) {
  1011. // self.readyState = WebSocket.CLOSED;
  1012. // eventTarget.dispatchEvent(generateEvent('close'));
  1013. // } else {
  1014. // self.readyState = WebSocket.CONNECTING;
  1015. // var e = generateEvent('connecting');
  1016. // e.code = event.code;
  1017. // e.reason = event.reason;
  1018. // e.wasClean = event.wasClean;
  1019. // eventTarget.dispatchEvent(e);
  1020. // if (!reconnectAttempt && !timedOut) {
  1021. // if (self.debug || ReconnectingWebSocket.debugAll) {
  1022. // console.debug('ReconnectingWebSocket', 'onclose', self.url);
  1023. // }
  1024. // eventTarget.dispatchEvent(generateEvent('close'));
  1025. // }
  1026. //
  1027. // var timeout = self.reconnectInterval * Math.pow(self.reconnectDecay, self.reconnectAttempts);
  1028. // setTimeout(function () {
  1029. // self.reconnectAttempts++;
  1030. // self.open(true);
  1031. // }, timeout > self.maxReconnectInterval ? self.maxReconnectInterval : timeout);
  1032. // }
  1033. // };
  1034. // ws.onmessage = function (event) {
  1035. // if (self.debug || ReconnectingWebSocket.debugAll) {
  1036. // console.debug('ReconnectingWebSocket', 'onmessage', self.url, event.data);
  1037. // }
  1038. // var e = generateEvent('message');
  1039. // e.data = event.data;
  1040. // eventTarget.dispatchEvent(e);
  1041. // };
  1042. // ws.onerror = function (event) {
  1043. // if (self.debug || ReconnectingWebSocket.debugAll) {
  1044. // console.debug('ReconnectingWebSocket', 'onerror', self.url, event);
  1045. // }
  1046. // eventTarget.dispatchEvent(generateEvent('error'));
  1047. // };
  1048. // };
  1049. //
  1050. // // Whether or not to create a websocket upon instantiation
  1051. // if (this.automaticOpen == true) {
  1052. // this.open(false);
  1053. // }
  1054. //
  1055. // /**
  1056. // * Transmits data to the server over the WebSocket connection.
  1057. // *
  1058. // * @param data a text string, ArrayBuffer or Blob to send to the server.
  1059. // */
  1060. // this.send = function (data) {
  1061. // if (ws) {
  1062. // if (self.debug || ReconnectingWebSocket.debugAll) {
  1063. // console.debug('ReconnectingWebSocket', 'send', self.url, data);
  1064. // }
  1065. // return ws.send(data);
  1066. // } else {
  1067. // throw 'INVALID_STATE_ERR : Pausing to reconnect websocket';
  1068. // }
  1069. // };
  1070. //
  1071. // /**
  1072. // * Closes the WebSocket connection or connection attempt, if any.
  1073. // * If the connection is already CLOSED, this method does nothing.
  1074. // */
  1075. // this.close = function (code, reason) {
  1076. // // Default CLOSE_NORMAL code
  1077. // if (typeof code == 'undefined') {
  1078. // code = 1000;
  1079. // }
  1080. // forcedClose = true;
  1081. // if (ws) {
  1082. // ws.close(code, reason);
  1083. // }
  1084. // };
  1085. //
  1086. // /**
  1087. // * Additional public API method to refresh the connection if still open (close, re-open).
  1088. // * For example, if the app suspects bad data / missed heart beats, it can try to refresh.
  1089. // */
  1090. // this.refresh = function () {
  1091. // if (ws) {
  1092. // ws.close();
  1093. // }
  1094. // };
  1095. // }
  1096. //
  1097. // /**
  1098. // * An event listener to be called when the WebSocket connection's readyState changes to OPEN;
  1099. // * this indicates that the connection is ready to send and receive data.
  1100. // */
  1101. // ReconnectingWebSocket.prototype.onopen = function (event) {};
  1102. // /** An event listener to be called when the WebSocket connection's readyState changes to CLOSED. */
  1103. // ReconnectingWebSocket.prototype.onclose = function (event) {};
  1104. // /** An event listener to be called when a connection begins being attempted. */
  1105. // ReconnectingWebSocket.prototype.onconnecting = function (event) {};
  1106. // /** An event listener to be called when a message is received from the server. */
  1107. // ReconnectingWebSocket.prototype.onmessage = function (event) {};
  1108. // /** An event listener to be called when an error occurs. */
  1109. // ReconnectingWebSocket.prototype.onerror = function (event) {};
  1110. //
  1111. // /**
  1112. // * Whether all instances of ReconnectingWebSocket should log debug messages.
  1113. // * Setting this to true is the equivalent of setting all instances of ReconnectingWebSocket.debug to true.
  1114. // */
  1115. // ReconnectingWebSocket.debugAll = false;
  1116. //
  1117. // ReconnectingWebSocket.CONNECTING = WebSocket.CONNECTING;
  1118. // ReconnectingWebSocket.OPEN = WebSocket.OPEN;
  1119. // ReconnectingWebSocket.CLOSING = WebSocket.CLOSING;
  1120. // ReconnectingWebSocket.CLOSED = WebSocket.CLOSED;
  1121. //
  1122. // return ReconnectingWebSocket;
  1123. // });
  1124. //
  1125. // /***/ }),
  1126. // /* 5 */
  1127. // /***/ (function(module, exports, __webpack_require__) {
  1128. //
  1129. // "use strict";
  1130. //
  1131. //
  1132. // Object.defineProperty(exports, "__esModule", {
  1133. // value: true
  1134. // });
  1135. // exports.default = debugInit;
  1136. // function debugInit() {
  1137. // var container = document.createElement('div');
  1138. // container.style.display = 'none';
  1139. // var isVisible = false; // 刚开始不可见,调用setFrameDebugText后,才可见
  1140. // // var isFrameDebugClosed = false;
  1141. // // var isEnabled = false;
  1142. // var style = {
  1143. // 'position': 'absolute',
  1144. // 'top': 0,
  1145. // 'left': 0,
  1146. // 'height': '20px',
  1147. // 'line-height': '20px',
  1148. // 'z-index': 10000,
  1149. // 'width': '100%',
  1150. // 'padding': '5px 10px',
  1151. // 'color': '#F76a24',
  1152. // 'background-color': '#fefcec',
  1153. // 'font-family': '\'Helvetica Neue\', \'Hiragino Sans GB\', Helvetica'
  1154. // };
  1155. // var styleString = '';
  1156. // for (var k in style) {
  1157. // var v = style[k];
  1158. // styleString += k + ': ' + v + ';';
  1159. // }
  1160. //
  1161. // var closeBtnStyle = {
  1162. // 'position': 'absolute',
  1163. // 'right': 0,
  1164. // 'top': 0,
  1165. // 'padding': '5px 10px',
  1166. // 'z-index': 10001
  1167. // };
  1168. // var closeStyleString = '';
  1169. // for (var k in closeBtnStyle) {
  1170. // var v = closeBtnStyle[k];
  1171. // closeStyleString += k + ': ' + v + ';';
  1172. // }
  1173. //
  1174. // container.innerHTML = '<div style="' + styleString + '" id="framedebug"></div><span id="framedebugclose" style="' + closeStyleString + '">\xD7</span>';
  1175. //
  1176. // // sdk加载在head中,当sdk执行时,可能获取不到body,需要onload之后,才将执行append
  1177. // // window.addEventListener('load', function () {
  1178. // document.body.appendChild(container);
  1179. // var div = document.querySelector('#framedebug');
  1180. // var isEnabled = true;
  1181. // document.querySelector("#framedebugclose").onclick = function () {
  1182. // isEnabled = false;
  1183. // container.style.display = 'none';
  1184. // };
  1185. // // });
  1186. //
  1187. // function setDebugText(text) {
  1188. // if (!isEnabled) {
  1189. // return;
  1190. // }
  1191. // if (!isVisible) {
  1192. // // 最开始不可见,第一次调用后,才可见
  1193. // container.style.display = 'block ';
  1194. // isVisible = true;
  1195. // }
  1196. // div.innerText = text;
  1197. // }
  1198. // return setDebugText;
  1199. // }
  1200. //
  1201. // /***/ }),
  1202. // /* 6 */
  1203. // /***/ (function(module, exports, __webpack_require__) {
  1204. //
  1205. // "use strict";
  1206. //
  1207. //
  1208. // Object.defineProperty(exports, "__esModule", {
  1209. // value: true
  1210. // });
  1211. // exports.setDebugAppid = exports.getQQ = exports.getAppid = undefined;
  1212. //
  1213. // var _util = __webpack_require__(0);
  1214. //
  1215. // var debugAppid;
  1216. // var debugAppidList = [8000343, 8000369, 8000370, 8000371, 8000372, 8000379, 8000381, 8000382, 8000383, 8000384, 8000385, 8000386, 8000387, 8000486, 8000489, 8000497, 8000498, 8000499, 8000500, 8000510, 8000513, 8000514, 8000515];
  1217. //
  1218. // function isAppidVaild(appid) {
  1219. // appid = parseInt(appid);
  1220. // if (debugAppidList.indexOf(appid) > -1) {
  1221. // return true;
  1222. // }
  1223. // return false;
  1224. // }
  1225. //
  1226. // // 生成随机QQ,不再支持指定QQ
  1227. // function getQQ() {
  1228. // var qq = Math.ceil(Math.random() * 1000000000 + 10000);
  1229. // (0, _util.log)('qq ' + qq);
  1230. // return qq;
  1231. // }
  1232. //
  1233. // function setDebugAppid(appid) {
  1234. // debugAppid = appid;
  1235. // }
  1236. //
  1237. // function getAppid() {
  1238. // if (debugAppid) {
  1239. // return debugAppid;
  1240. // }
  1241. // var appid = (0, _util.getParam)('appid');
  1242. // if (isAppidVaild(appid)) {
  1243. // return appid;
  1244. // }
  1245. // return debugAppidList[0];
  1246. // }
  1247. //
  1248. // exports.getAppid = getAppid;
  1249. // exports.getQQ = getQQ;
  1250. // exports.setDebugAppid = setDebugAppid;
  1251. //
  1252. // /***/ }),
  1253. // /* 7 */
  1254. // /***/ (function(module, exports, __webpack_require__) {
  1255. //
  1256. // "use strict";
  1257. //
  1258. //
  1259. // Object.defineProperty(exports, "__esModule", {
  1260. // value: true
  1261. // });
  1262. //
  1263. // var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  1264. //
  1265. // exports.default = function (qqgame) {
  1266. // var frameWs;
  1267. // var uin;
  1268. // var isFrameGame;
  1269. // var frameFps;
  1270. // var isGameEnd = false;
  1271. // // var helloMsgTimer = null;
  1272. // var ws;
  1273. //
  1274. // qqgame.setDebugAppid = _util2.setDebugAppid;
  1275. // qqgame.invoke = function (name, params) {
  1276. // if (isGameEnd) {
  1277. // return;
  1278. // }
  1279. // params = params || {};
  1280. // (0, _util.log)('invoke ' + name + ' ' + JSON.stringify(params));
  1281. //
  1282. // if (name == "frameData") {
  1283. // frameWs.send(params);
  1284. // return;
  1285. // }
  1286. //
  1287. // wsPromise.then(function () {
  1288. // var json = {
  1289. // 'eID': name,
  1290. // 'ePara': params
  1291. // };
  1292. //
  1293. // if (name == 'gameInit') {
  1294. // params.appid = (0, _util2.getAppid)();
  1295. // (0, _util.log)('appid ' + params.appid);
  1296. // params.qq = uin = (0, _util2.getQQ)();
  1297. // // 帧同步直连
  1298. // if (params.openFraming) {
  1299. // isFrameGame = true;
  1300. // frameFps = params.fpsExpect;
  1301. // params.openFraming = undefined;
  1302. // params.fpsExpect = undefined;
  1303. // }
  1304. // }
  1305. //
  1306. // // 如果游戏结束,长连接不再发心跳
  1307. // // gameExit 只有debug环境下才有这个eID
  1308. // if (name == 'gameResult' || name == 'gameExit') {
  1309. // isGameEnd = true;
  1310. // // clearInterval(helloMsgTimer);
  1311. // isFrameGame && frameWs.stop();
  1312. // }
  1313. // ws.send(JSON.stringify(json));
  1314. // });
  1315. // };
  1316. //
  1317. // var cbList = [];
  1318. // qqgame.onMessage = function (cb) {
  1319. // cbList.push(cb);
  1320. // };
  1321. //
  1322. // // 客户端调用页面提供的接口
  1323. // qqgame.pvpResponse = function (data) {
  1324. // // if (name === 'gameReset') {
  1325. // // isGameEnd = false;
  1326. // // }
  1327. //
  1328. // // 加防护,游戏结算后,不再接受客户端的消息
  1329. // if (isGameEnd) {
  1330. // return;
  1331. // }
  1332. //
  1333. // if ((typeof data === 'undefined' ? 'undefined' : _typeof(data)) !== 'object') {
  1334. // data = JSON.parse(data);
  1335. // }
  1336. // var msgType = data.eID;
  1337. // var msgData = data.ePara;
  1338. // if (msgType !== 'frameData') {
  1339. // (0, _util.log)('onMessage ' + JSON.stringify(data));
  1340. // }
  1341. //
  1342. // cbList.forEach(function (cb) {
  1343. // cb(msgType, msgData);
  1344. // });
  1345. // };
  1346. //
  1347. // var wsPromise = function () {
  1348. // return new Promise(function (resolve, reject) {
  1349. // var wsURL = 'ws://test.go.minigame.qq.com/h5pvpservice/';
  1350. // ws = new WebSocket(wsURL);
  1351. // ws.onopen = function () {
  1352. // resolve();
  1353. // (0, _util.log)('ws open');
  1354. // };
  1355. //
  1356. // ws.onmessage = function (data) {
  1357. // var msg = data.data;
  1358. // msg = JSON.parse(msg);
  1359. // var cmd = msg.eID;
  1360. //
  1361. // if (isFrameGame) {
  1362. // if (cmd == "session") {
  1363. // var tableKey = msg.ePara.tableKey;
  1364. // var frameSvrId = msg.ePara.frameSvrId;
  1365. // frameWs = (0, _frame2.default)({
  1366. // uin: uin,
  1367. // tableKey: tableKey,
  1368. // frameSvrId: frameSvrId,
  1369. // frameFps: frameFps,
  1370. // frameURL: 'ws://test.trans.mobile.minigame.qq.com',
  1371. // framePort: 9050,
  1372. // cgiPath: '',
  1373. // onMessage: function onMessage(data) {
  1374. // qqgame.pvpResponse({
  1375. // eID: 'frameData',
  1376. // ePara: data
  1377. // });
  1378. // }
  1379. // });
  1380. // return;
  1381. // }
  1382. //
  1383. // // 如果是帧同步,拦截channelCreated,等直连成功后,再通知游戏channelCreated
  1384. // if (cmd == "channelCreated") {
  1385. // frameWs.wsPromise.then(function () {
  1386. // qqgame.pvpResponse(msg);
  1387. // });
  1388. // return;
  1389. // }
  1390. // }
  1391. //
  1392. // if (cmd == "leave") {
  1393. // isGameEnd = true;
  1394. // // clearInterval(helloMsgTimer);
  1395. // isFrameGame && frameWs.stop();
  1396. // }
  1397. // qqgame.pvpResponse(msg);
  1398. // };
  1399. //
  1400. // ws.onerror = function (error) {
  1401. // (0, _util.log)('ws error ' + JSON.stringify(error));
  1402. // };
  1403. // });
  1404. // }();
  1405. //
  1406. // window.addEventListener('beforeunload', function () {
  1407. // if (!isGameEnd) {
  1408. // // 如果已经发送过gameResult,这里则不再发送
  1409. // qqgame.invoke('gameExit');
  1410. // }
  1411. // });
  1412. // };
  1413. //
  1414. // var _util = __webpack_require__(0);
  1415. //
  1416. // var _util2 = __webpack_require__(6);
  1417. //
  1418. // var _frame = __webpack_require__(2);
  1419. //
  1420. // var _frame2 = _interopRequireDefault(_frame);
  1421. //
  1422. // function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  1423. //
  1424. // /***/ }),
  1425. // /* 8 */
  1426. // /***/ (function(module, exports, __webpack_require__) {
  1427. //
  1428. // "use strict";
  1429. //
  1430. //
  1431. // var _util = __webpack_require__(0);
  1432. //
  1433. // var _sdk = __webpack_require__(7);
  1434. //
  1435. // var _sdk2 = _interopRequireDefault(_sdk);
  1436. //
  1437. // var _sdk3 = __webpack_require__(3);
  1438. //
  1439. // var _sdk4 = _interopRequireDefault(_sdk3);
  1440. //
  1441. // var _robot = __webpack_require__(1);
  1442. //
  1443. // function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  1444. //
  1445. // var qqgame = window.qqgame = window.qqgame || {};
  1446. //
  1447. // // 避免多次加载 SDK
  1448. // if (!qqgame.invoke) {
  1449. // qqgame.version = '0.3.5-beta.1';
  1450. // // Web SDK 是否已重载机器人相关函数
  1451. // qqgame.isWebSDKOverloadRobotFunction = true;
  1452. // (0, _util.log)('version ' + qqgame.version);
  1453. // (0, _util.log)('WiKi https://qqgame.qq.com/h5wiki/pvp-sdk');
  1454. //
  1455. // qqgame.isQQGame = _util.isQQGame;
  1456. // qqgame.getDeviceInfo = _util.getDeviceInfo;
  1457. // qqgame.isAndroid = _util.isAndroid;
  1458. // qqgame.isIOS = _util.isIOS;
  1459. // qqgame.getEnv = _util.getEnv;
  1460. //
  1461. // qqgame.isRobot = _robot.isRobot;
  1462. // qqgame.robotLevel = _robot.robotLevel;
  1463. //
  1464. // qqgame.RESULT_LOSE = -1; // 失败
  1465. // qqgame.RESULT_DRAW = 0; //平局
  1466. // qqgame.RESULT_WIN = 1; // 胜利
  1467. // qqgame.RESULT_LEAVE = 2; // 逃跑
  1468. // qqgame.RESULT_TYPE_RESULT = 1; // 胜负结算
  1469. // qqgame.RESULT_TYPE_RANK = 2; // 排名结算
  1470. //
  1471. // if (_util.isDebug) {
  1472. // (0, _sdk2.default)(qqgame);
  1473. // } else {
  1474. // (0, _sdk4.default)(qqgame);
  1475. // }
  1476. // }
  1477. //
  1478. // module.exports = qqgame;
  1479. //
  1480. // /***/ })
  1481. // /******/ ]);
  1482. // });