// (function webpackUniversalModuleDefinition(root, factory) { // if(typeof exports === 'object' && typeof module === 'object') // module.exports = factory(); // else if(typeof define === 'function' && define.amd) // define([], factory); // else if(typeof exports === 'object') // exports["qqgame"] = factory(); // else // root["qqgame"] = factory(); // })(window, function() { // return /******/ (function(modules) { // webpackBootstrap // /******/ // The module cache // /******/ var installedModules = {}; // /******/ // /******/ // The require function // /******/ function __webpack_require__(moduleId) { // /******/ // /******/ // Check if module is in cache // /******/ if(installedModules[moduleId]) { // /******/ return installedModules[moduleId].exports; // /******/ } // /******/ // Create a new module (and put it into the cache) // /******/ var module = installedModules[moduleId] = { // /******/ i: moduleId, // /******/ l: false, // /******/ exports: {} // /******/ }; // /******/ // /******/ // Execute the module function // /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); // /******/ // /******/ // Flag the module as loaded // /******/ module.l = true; // /******/ // /******/ // Return the exports of the module // /******/ return module.exports; // /******/ } // /******/ // /******/ // /******/ // expose the modules object (__webpack_modules__) // /******/ __webpack_require__.m = modules; // /******/ // /******/ // expose the module cache // /******/ __webpack_require__.c = installedModules; // /******/ // /******/ // define getter function for harmony exports // /******/ __webpack_require__.d = function(exports, name, getter) { // /******/ if(!__webpack_require__.o(exports, name)) { // /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); // /******/ } // /******/ }; // /******/ // /******/ // define __esModule on exports // /******/ __webpack_require__.r = function(exports) { // /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { // /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); // /******/ } // /******/ Object.defineProperty(exports, '__esModule', { value: true }); // /******/ }; // /******/ // /******/ // create a fake namespace object // /******/ // mode & 1: value is a module id, require it // /******/ // mode & 2: merge all properties of value into the ns // /******/ // mode & 4: return value when already ns object // /******/ // mode & 8|1: behave like require // /******/ __webpack_require__.t = function(value, mode) { // /******/ if(mode & 1) value = __webpack_require__(value); // /******/ if(mode & 8) return value; // /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; // /******/ var ns = Object.create(null); // /******/ __webpack_require__.r(ns); // /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); // /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); // /******/ return ns; // /******/ }; // /******/ // /******/ // getDefaultExport function for compatibility with non-harmony modules // /******/ __webpack_require__.n = function(module) { // /******/ var getter = module && module.__esModule ? // /******/ function getDefault() { return module['default']; } : // /******/ function getModuleExports() { return module; }; // /******/ __webpack_require__.d(getter, 'a', getter); // /******/ return getter; // /******/ }; // /******/ // /******/ // Object.prototype.hasOwnProperty.call // /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; // /******/ // /******/ // __webpack_public_path__ // /******/ __webpack_require__.p = ""; // /******/ // /******/ // /******/ // Load entry module and return exports // /******/ return __webpack_require__(__webpack_require__.s = 8); // /******/ }) // /************************************************************************/ // /******/ ([ // /* 0 */ // /***/ (function(module, exports, __webpack_require__) { // // "use strict"; // // // Object.defineProperty(exports, "__esModule", { // value: true // }); // var isRobot = getParam('robot') == '1'; // 是否机器人 // function getParam(name) { // var url = location.href; // name = name.replace(/[\[\]]/g, "\\$&"); // var regex = new RegExp("[?&]" + name + "(=([^]*)|&|#|$)"); // var results = regex.exec(url); // if (!results) return null; // if (!results[2]) return ''; // return decodeURIComponent(results[2].replace(/\+/g, " ")); // } // // var isIOS = function () { // var u = navigator.userAgent.toLowerCase(); // var flag = u.indexOf('iphone') > -1 || u.indexOf('ipad') > -1; // return function () { // return flag; // }; // }(); // // var isAndroid = function () { // var u = navigator.userAgent.toLowerCase(); // var flag = u.indexOf('android') > -1; // return function () { // return flag; // }; // }(); // // var isDebug = location.hostname === 'localhost' || !!getParam('qqdebug'); // // var log = function log(msg) { // // console.log('[QQGame SDK]:', msg); // }; // // var isQQGame = function isQQGame() { // if (isDebug || isRobot) { // return true; // } // return navigator.userAgent.toLowerCase().indexOf('qqgame') != -1; // }; // // var userInfo = {}; // var setUserInfo = function setUserInfo(info) { // if (Array.isArray(info)) { // info.forEach(function (item) { // setUserInfo(item); // }); // } else if (info && info.qqgameid) { // // 兼容 gameUin 和 qqgameid // var qqgameid = info.qqgameid; // userInfo[qqgameid] = info; // } // }; // // var getUserInfo = function getUserInfo(qqgameid) { // if (userInfo[qqgameid]) { // return userInfo[qqgameid]; // } // return null; // }; // // var getDeviceInfo = function getDeviceInfo() { // var devicePixelRatio = window.devicePixelRatio || 1; // var devInfo = { // statusBarHeight: 20 // // devicePixelRatio: devicePixelRatio // }; // var ua = navigator.userAgent.toLowerCase(); // var res = ua.match(/StatusBarHeight\/([\d\.]+)/i); // if (Array.isArray(res) && res[1]) { // var height = parseInt(res[1]); // if (!isNaN(height)) { // devInfo.statusBarHeight = parseInt(height / devicePixelRatio); // } // } // return devInfo; // }; // // var getEnv = function () { // var hallEnv = 'prod'; // var ua = navigator.userAgent.toLowerCase(); // var res = ua.match(/\senv\/([\d])\s/i); // if (Array.isArray(res) && res[1]) { // var env = parseInt(res[1]); // if (env == "1") { // // 测试 // hallEnv = 'test'; // } else if (env == "2") { // // 预发布 // hallEnv = 'prev'; // } else if (env == "3") { // // 正式 // hallEnv = 'prod'; // } // } // return function () { // if (isDebug) { // return 'test'; // } // return hallEnv; // }; // }(); // // exports.getParam = getParam; // exports.isIOS = isIOS; // exports.isAndroid = isAndroid; // exports.isDebug = isDebug; // exports.log = log; // exports.isQQGame = isQQGame; // exports.getUserInfo = getUserInfo; // exports.setUserInfo = setUserInfo; // exports.getDeviceInfo = getDeviceInfo; // exports.getEnv = getEnv; // // /***/ }), // /* 1 */ // /***/ (function(module, exports, __webpack_require__) { // // "use strict"; // // // Object.defineProperty(exports, "__esModule", { // value: true // }); // exports.disableRobotRender = exports.isRobotRender = exports.robotLevel = exports.isRobot = undefined; // // var _util = __webpack_require__(0); // // var isRobot = (0, _util.getParam)('robot') == '1'; // 是否机器人 // var isRobotRender = (0, _util.getParam)('render') == '1'; // 用于机器人是否渲染 // var robotLevel; // // if (isRobot) { // exports.robotLevel = robotLevel = (0, _util.getParam)('level'); // if (robotLevel) { // exports.robotLevel = robotLevel = parseInt(robotLevel); // exports.robotLevel = robotLevel = isNaN(robotLevel) ? 1 : robotLevel; // 当参数有误时,默认机器人等级为 1 // } // } // // function disableRobotRender() { // if (window.cc) { // // cocos robot 屏蔽渲染 // try { // cc.director._visitScene = cc.renderer.clear = cc.renderer.rendering = function () {}; // } catch (e) {} // } // } // // exports.isRobot = isRobot; // exports.robotLevel = robotLevel; // exports.isRobotRender = isRobotRender; // exports.disableRobotRender = disableRobotRender; // // /***/ }), // /* 2 */ // /***/ (function(module, exports, __webpack_require__) { // // "use strict"; // // // Object.defineProperty(exports, "__esModule", { // value: true // }); // exports.default = frameWsInit; // // var _util = __webpack_require__(0); // // var _weblog = __webpack_require__(5); // // var _weblog2 = _interopRequireDefault(_weblog); // // var _ws = __webpack_require__(4); // // var _ws2 = _interopRequireDefault(_ws); // // function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } // // var setWebLog = function setWebLog() {}; // var frameWsIP; // var frameWsURL; // var frameWs; // var uin; // var tableKey; // var frameSvrId; // var frameWs; // var frameFps; // var frameWsPromise; // var frameIndex = -1; // var helloTimer; // var isWsClosed = false; // var cgiPath; // var framePort; // // // 仅用于测试 // var v1 = '-'; // var v2 = '-'; // var v3 = '-'; // // var sendFrameMsg = function sendFrameMsg(msg) { // if (isWsClosed) { // return; // } // var header = '{domain=' + frameWsIP + ';cgipath=' + cgiPath + ';cgiquery=uin=' + uin + ';}'; // try { // frameWs.send('' + header.length + header + JSON.stringify(msg)); // } catch (e) { // (0, _util.log)('send frame msg error: ' + JSON.stringify(e)); // } // }; // // var sendFrameReady = function sendFrameReady() { // (0, _util.log)('send frame ready'); // var body = { // "Cmd": "frame_ready", // "BackString": "frame_ready", // "MsgBody": { // "session": { // "tableKey": tableKey // }, // "fps": frameFps // } // }; // sendFrameMsg(body); // }; // // var sendFrameHello = function sendFrameHello() { // // log(`send frame hello`); // var body = { // "Cmd": "frame_hello", // "BackString": "frame_hello", // "MsgBody": { // "session": { // "tableKey": tableKey // }, // "fps": frameFps // } // }; // sendFrameMsg(body); // }; // // var sendFrameDataIndex = 0; // var sendTimeMap = {}; // var keyFlag = Math.ceil(Math.random() * 1000000); // var sendFrameData = function sendFrameData(data) { // if (_util.isDebug) { // data.testkey = 'testkey_' + keyFlag + '_' + sendFrameDataIndex++; // data.testtime = Date.now(); // data.testFrameIndex = frameIndex; // sendTimeMap[data.testkey] = data.testtime; // // log('send frame data'); // } // var body = { // "Cmd": "frame_transmit", // "BackString": "frame_transmit", // "MsgBody": { // "session": { // "tableKey": tableKey // }, // "frameData": data // } // }; // sendFrameMsg(body); // }; // // var sendFrameStop = function sendFrameStop() { // clearInterval(helloTimer); // (0, _util.log)('send frame stop'); // var body = { // "Cmd": "frame_stop", // "BackString": "frame_stop", // "MsgBody": { // "session": { // "tableKey": tableKey // } // } // }; // sendFrameMsg(body); // frameWs && frameWs.close && frameWs.close(); // isWsClosed = true; // }; // // var lastFrameMsgTime; // var lastHelloMsgTime; // // function onFrameMessage(frames) { // var currentTime = Date.now(); // if (lastFrameMsgTime) { // var cost = currentTime - lastFrameMsgTime; // 两帧时间差 // frameIndex = frames.frameIndex; // //if (cost > 70) { // // log(`frameTestGap2, ${cost}, ${frameIndex}`); // //} // // log(`frameTestGap, ${cost}, ${frameIndex}`); // if (frames.frameData) { // var testkey = frames.frameData[0].testkey; // var testtime = frames.frameData[0].testtime; // v1 = frameIndex - frames.frameData[0].testFrameIndex; // // log(`frameIndexGap, ${v1}`); // 帧差 // if (sendTimeMap[testkey]) { // v3 = currentTime - testtime; // (0, _util.log)('\u81EA\u53D1\u81EA\u6536\u5EF6\u8FDF ' + v3); // delete sendTimeMap[testkey]; // } // var text = '\u5E27\u5DEE: ' + v1 + ', \u81EA\u53D1\u81EA\u6536\u5EF6\u8FDF: ' + v3 + ', hello\u5EF6\u8FDF: ' + v2; // setWebLog(text); // } // } // lastFrameMsgTime = currentTime; // } // // var frameWsConnect = function frameWsConnect(onMessage) { // return new Promise(function (resolve, reject) { // frameWs = new _ws2.default(frameWsURL); // frameWs.onopen = function () { // (0, _util.log)('frame ws open'); // sendFrameReady(); // }; // frameWs.onmessage = function (data) { // var msg = data.data; // msg = JSON.parse(msg); // var cmd = msg.Cmd; // // if (cmd == 'frame_start') { // (0, _util.log)('frame start'); // resolve(); // // 发送hello包 // clearInterval(helloTimer); // helloTimer = setInterval(function () { // sendFrameHello(); // lastHelloMsgTime = Date.now(); // }, 1000); // } else if (cmd == 'frame_transmit') { // if (msg.MsgBody && msg.MsgBody.frames && msg.MsgBody.frames[0]) { // var frames = msg.MsgBody.frames[0]; // _util.isDebug && onFrameMessage(frames); // onMessage(frames); // } // } else if (cmd == 'frame_hello') { // if (_util.isDebug) { // v2 = Date.now() - lastHelloMsgTime; // (0, _util.log)('frameTestHello ' + v2); // var text = '\u5E27\u5DEE: ' + v1 + ', \u81EA\u53D1\u81EA\u6536\u5EF6\u8FDF: ' + v3 + ', hello\u5EF6\u8FDF: ' + v2; // setWebLog(text); // } // } // }; // // frameWs.onclose = function () { // // isWsClosed = true; // (0, _util.log)('frame ws close'); // }; // // frameWs.onerror = function (error) { // (0, _util.log)('frame ws error ' + JSON.stringify(error)); // }; // }); // }; // // function frameWsInit(options) { // if (_util.isDebug) { // setWebLog = (0, _weblog2.default)(); // } // uin = options.uin; // tableKey = options.tableKey; // frameSvrId = options.frameSvrId; // frameFps = options.frameFps; // frameWsIP = options.frameURL; // framePort = options.framePort; // frameWsURL = frameWsIP + ':' + framePort; // cgiPath = options.cgiPath; // // console.log(`frameWsURL ${frameWsURL}`) // var onMessage = options.onMessage || function () {}; // var wsPromise = frameWsConnect(onMessage); // return { // wsPromise: wsPromise, // send: sendFrameData, // stop: sendFrameStop // }; // } // // /***/ }), // /* 3 */ // /***/ (function(module, exports, __webpack_require__) { // // "use strict"; // // // Object.defineProperty(exports, "__esModule", { // value: true // }); // // 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; }; // // exports.default = function (qqgame) { // // qqgame.disableRobotRender = disableRobotRender; // if (_robot.isRobot) { // (0, _robot.disableRobotRender)(); // 正式环境关闭渲染 // } // // var invokeClient = function invokeClient(name, params) { // var jsonString = JSON.stringify({ // 'eID': name, // 'ePara': params // }); // if (_robot.isRobot) { // try { // window.pvpRequest(jsonString); // } catch (e) {} // } else { // try { // if ((0, _util.isAndroid)()) { // if (window.qqgame && window.qqgame.pvpRequest) { // window.qqgame.pvpRequest(jsonString); // } // } else if ((0, _util.isIOS)()) { // if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.pvpRequest && window.webkit.messageHandlers.pvpRequest.postMessage) { // window.webkit.messageHandlers.pvpRequest.postMessage(jsonString); // } // } // } catch (e) {} // } // }; // // qqgame.invoke = function (name, params) { // // 加防护,游戏结算后,不再接受游戏的invoke // if (isGameEnd) { // return; // } // // params = params || {}; // (0, _util.log)('invoke ' + name + ' ' + JSON.stringify(params)); // // if (name == "frameData") { // // 用户的操作消息 // /* if (params && params.data && params.data.id == debugUserId && params.data.msgKey) { // var t = Date.now(); // var msgKey = params.data.msgKey; // debugMsgMap[msgKey] = t; // } */ // frameWs.send(params); // // qqgame.invoke('frameDataByUDP', params); // return; // } // // if (name == 'gameInit' && params.openFraming) { // isFrameGame = true; // frameFps = params.fpsExpect || 5; // params.openFraming = undefined; // params.fpsExpect = undefined; // } // // /* if (debugMode) { // if (name == 'frameData') { // var debugMsgKey = `${debugUserKey}_${Math.ceil(Math.random() * 100000)}`; // debugKeyMap[debugMsgKey] = Date.now(); // params.debugMsgKey = debugMsgKey; // } // } */ // // // 查看用户信息 // if (name == "showUser" && (params.gameUin || params.qqgameid)) { // var qqgameid = params.gameUin || params.qqgameid; // var userInfo = (0, _util.getUserInfo)(qqgameid) || {}; // 可能返回 null // params = Object.assign(params, userInfo); // } // // // 加防护,游戏结算后,不再接受游戏的invoke // if (name === 'gameResult') { // if (params.result && params.result.win == qqgame.RESULT_LEAVE) { // // 结算页不处理逃跑,将逃跑转为失败 // params.result.win = qqgame.RESULT_LOSE; // } // if (!params.gameType) { // params.gameType = "COCOS"; // } // isGameEnd = true; // // if (isFrameGame) { // frameWs.stop(); // } // } // // invokeClient(name, params); // }; // // // 客户端心跳 // if (!_robot.isRobot) { // setInterval(function () { // invokeClient('watchDog'); // }, 3000); // } // // var cbList = []; // qqgame.onMessage = function (cb) { // cbList.push(cb); // }; // // // 客户端调用页面提供的接口 // qqgame.pvpResponse = function (data) { // if ((typeof data === 'undefined' ? 'undefined' : _typeof(data)) !== 'object') { // data = JSON.parse(data); // } // // var msgType = data.eID; // var msgData = data.ePara; // // if (msgType === 'gameReset') { // isGameEnd = false; // // isChannelCreated = false; // } // // // 加防护,游戏结算后,不再接受客户端的消息 // if (isGameEnd) { // return; // } // // if (msgType !== 'frameData') { // (0, _util.log)('onMessage ' + JSON.stringify(data)); // } // // if (msgType == 'frameData') { // if (Array.isArray(msgData.frames)) { // msgData = msgData.frames[0]; // } // } // // // 保存用户信息 // if (msgType == 'channelCreated') { // var playerInfos = msgData.playerInfos; // (0, _util.setUserInfo)(playerInfos); // } // // if (msgType == "channelCreating") { // if (isFrameGame) { // tableKey = msgData.tableKey; // cgiPath = msgData.url.transmitSvr.cgipath; // frameURL = msgData.url.transmitSvr.domain; // framePort = msgData.url.transmitSvr.port; // } // return; // } // // // 如果是帧同步,拦截channelCreated,等直连成功后,再通知游戏channelCreated // if (msgType == "channelCreated") { // if (isFrameGame) { // uin = msgData.playerInfos[0].qqgameid; // // debugUserId = 1000 + msgData.playerInfos[0].seat; // frameWs = (0, _frame2.default)({ // uin: uin, // frameFps: frameFps, // tableKey: tableKey, // cgiPath: cgiPath, // frameURL: frameURL, // framePort: framePort, // onMessage: function onMessage(data) { // pvpResponse('frameData', data); // /* qqgame.pvpResponse({ // eID: 'frameData', // ePara: data // }); */ // } // }); // frameWs.wsPromise.then(function () { // // isChannelCreated = true; // // qqgame.pvpResponse(data); // pvpResponse(msgType, msgData); // }); // return; // } // } // // /* if (msgType == 'frameData') { // if (Array.isArray(msgData.frames)) { // msgData = msgData.frames[0]; // if (debugMode) { // var data = msgData; // var index = data.frameIndex; // if (Array.isArray(data.frameData)) { // data.frameData.forEach((frameItem) => { // var msgKey = frameItem.debugMsgKey; // if (debugKeyMap[msgKey]) { // var sendTime = debugKeyMap[msgKey]; // var t = Date.now(); // log(`自发自收延迟: ${t - sendTime}`) // delete debugKeyMap[msgKey]; // } // }); // } // } // } else { // return; // } // }*/ // // pvpResponse(msgType, msgData); // }; // // qqgame.setDebugAppid = function () {}; // // var pvpResponse = function pvpResponse(msgType, msgData) { // cbList.forEach(function (cb) { // cb(msgType, msgData); // }); // }; // }; // // var _util = __webpack_require__(0); // // var _robot = __webpack_require__(1); // // var _frame = __webpack_require__(2); // // var _frame2 = _interopRequireDefault(_frame); // // function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } // // var debugMode = false; // // var debugUserId; // // var debugMsgMap = {}; // // 都是帧同步相关 // var isFrameGame = false; // var frameFps = 5; // var frameWs; // var uin; // var frameURL; // var framePort; // var cgiPath; // var tableKey; // var frameSvrId; // // var isGameEnd = false; // // var debugKeyMap = {}; // 調試使用 // // var debugUserKey = Math.ceil(Math.random() * 100000); // 調試使用 // // /***/ }), // /* 4 */ // /***/ (function(module, exports, __webpack_require__) { // // "use strict"; // var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__; // // // MIT License: // // // // Copyright (c) 2010-2012, Joe Walnes // // // // Permission is hereby granted, free of charge, to any person obtaining a copy // // of this software and associated documentation files (the "Software"), to deal // // in the Software without restriction, including without limitation the rights // // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // // copies of the Software, and to permit persons to whom the Software is // // furnished to do so, subject to the following conditions: // // // // The above copyright notice and this permission notice shall be included in // // all copies or substantial portions of the Software. // // // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // // THE SOFTWARE. // // /** // * This behaves like a WebSocket in every way, except if it fails to connect, // * or it gets disconnected, it will repeatedly poll until it successfully connects // * again. // * // * It is API compatible, so when you have: // * ws = new WebSocket('ws://....'); // * you can replace with: // * ws = new ReconnectingWebSocket('ws://....'); // * // * The event stream will typically look like: // * onconnecting // * onopen // * onmessage // * onmessage // * onclose // lost connection // * onconnecting // * onopen // sometime later... // * onmessage // * onmessage // * etc... // * // * It is API compatible with the standard WebSocket API, apart from the following members: // * // * - `bufferedAmount` // * - `extensions` // * - `binaryType` // * // * Latest version: https://github.com/joewalnes/reconnecting-websocket/ // * - Joe Walnes // * // * Syntax // * ====== // * var socket = new ReconnectingWebSocket(url, protocols, options); // * // * Parameters // * ========== // * url - The url you are connecting to. // * protocols - Optional string or array of protocols. // * options - See below // * // * Options // * ======= // * Options can either be passed upon instantiation or set after instantiation: // * // * var socket = new ReconnectingWebSocket(url, null, { debug: true, reconnectInterval: 4000 }); // * // * or // * // * var socket = new ReconnectingWebSocket(url); // * socket.debug = true; // * socket.reconnectInterval = 4000; // * // * debug // * - Whether this instance should log debug messages. Accepts true or false. Default: false. // * // * automaticOpen // * - 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(). // * // * reconnectInterval // * - The number of milliseconds to delay before attempting to reconnect. Accepts integer. Default: 1000. // * // * maxReconnectInterval // * - The maximum number of milliseconds to delay a reconnection attempt. Accepts integer. Default: 30000. // * // * reconnectDecay // * - The rate of increase of the reconnect delay. Allows reconnect attempts to back off when problems persist. Accepts integer or float. Default: 1.5. // * // * timeoutInterval // * - The maximum time in milliseconds to wait for a connection to succeed before closing and retrying. Accepts integer. Default: 2000. // * // */ // (function (global, factory) { // if (true) { // !(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory), // __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? // (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__), // __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); // } else {} // })(undefined, function () { // // if (!('WebSocket' in window)) { // return; // } // // function ReconnectingWebSocket(url, protocols, options) { // // // Default settings // var settings = { // // /** Whether this instance should log debug messages. */ // debug: false, // // /** Whether or not the websocket should attempt to connect immediately upon instantiation. */ // automaticOpen: true, // // /** The number of milliseconds to delay before attempting to reconnect. */ // reconnectInterval: 1000, // /** The maximum number of milliseconds to delay a reconnection attempt. */ // maxReconnectInterval: 30000, // /** The rate of increase of the reconnect delay. Allows reconnect attempts to back off when problems persist. */ // reconnectDecay: 1.5, // // /** The maximum time in milliseconds to wait for a connection to succeed before closing and retrying. */ // timeoutInterval: 2000, // // /** The maximum number of reconnection attempts to make. Unlimited if null. */ // maxReconnectAttempts: 100, // null, // // /** The binary type, possible values 'blob' or 'arraybuffer', default 'blob'. */ // binaryType: 'blob' // }; // if (!options) { // options = {}; // } // // // Overwrite and define settings with options if they exist. // for (var key in settings) { // if (typeof options[key] !== 'undefined') { // this[key] = options[key]; // } else { // this[key] = settings[key]; // } // } // // // These should be treated as read-only properties // // /** The URL as resolved by the constructor. This is always an absolute URL. Read only. */ // this.url = url; // // /** The number of attempted reconnects since starting, or the last successful connection. Read only. */ // this.reconnectAttempts = 0; // // /** // * The current state of the connection. // * Can be one of: WebSocket.CONNECTING, WebSocket.OPEN, WebSocket.CLOSING, WebSocket.CLOSED // * Read only. // */ // this.readyState = WebSocket.CONNECTING; // // /** // * A string indicating the name of the sub-protocol the server selected; this will be one of // * the strings specified in the protocols parameter when creating the WebSocket object. // * Read only. // */ // this.protocol = null; // // // Private state variables // // var self = this; // var ws; // var forcedClose = false; // var timedOut = false; // var eventTarget = document.createElement('div'); // // // Wire up "on*" properties as event handlers // // eventTarget.addEventListener('open', function (event) { // self.onopen(event); // }); // eventTarget.addEventListener('close', function (event) { // self.onclose(event); // }); // eventTarget.addEventListener('connecting', function (event) { // self.onconnecting(event); // }); // eventTarget.addEventListener('message', function (event) { // self.onmessage(event); // }); // eventTarget.addEventListener('error', function (event) { // self.onerror(event); // }); // // // Expose the API required by EventTarget // // this.addEventListener = eventTarget.addEventListener.bind(eventTarget); // this.removeEventListener = eventTarget.removeEventListener.bind(eventTarget); // this.dispatchEvent = eventTarget.dispatchEvent.bind(eventTarget); // // /** // * This function generates an event that is compatible with standard // * compliant browsers and IE9 - IE11 // * // * This will prevent the error: // * Object doesn't support this action // * // * http://stackoverflow.com/questions/19345392/why-arent-my-parameters-getting-passed-through-to-a-dispatched-event/19345563#19345563 // * @param s String The name that the event should use // * @param args Object an optional object that the event will use // */ // function generateEvent(s, args) { // var evt = document.createEvent("CustomEvent"); // evt.initCustomEvent(s, false, false, args); // return evt; // }; // // this.open = function (reconnectAttempt) { // ws = new WebSocket(self.url, protocols || []); // ws.binaryType = this.binaryType; // // if (reconnectAttempt) { // if (this.maxReconnectAttempts && this.reconnectAttempts > this.maxReconnectAttempts) { // return; // } // } else { // eventTarget.dispatchEvent(generateEvent('connecting')); // this.reconnectAttempts = 0; // } // // if (self.debug || ReconnectingWebSocket.debugAll) { // console.debug('ReconnectingWebSocket', 'attempt-connect', self.url); // } // // var localWs = ws; // var timeout = setTimeout(function () { // if (self.debug || ReconnectingWebSocket.debugAll) { // console.debug('ReconnectingWebSocket', 'connection-timeout', self.url); // } // timedOut = true; // localWs.close(); // timedOut = false; // }, self.timeoutInterval); // // ws.onopen = function (event) { // clearTimeout(timeout); // if (self.debug || ReconnectingWebSocket.debugAll) { // console.debug('ReconnectingWebSocket', 'onopen', self.url); // } // self.protocol = ws.protocol; // self.readyState = WebSocket.OPEN; // self.reconnectAttempts = 0; // var e = generateEvent('open'); // e.isReconnect = reconnectAttempt; // reconnectAttempt = false; // eventTarget.dispatchEvent(e); // }; // // ws.onclose = function (event) { // clearTimeout(timeout); // ws = null; // if (forcedClose) { // self.readyState = WebSocket.CLOSED; // eventTarget.dispatchEvent(generateEvent('close')); // } else { // self.readyState = WebSocket.CONNECTING; // var e = generateEvent('connecting'); // e.code = event.code; // e.reason = event.reason; // e.wasClean = event.wasClean; // eventTarget.dispatchEvent(e); // if (!reconnectAttempt && !timedOut) { // if (self.debug || ReconnectingWebSocket.debugAll) { // console.debug('ReconnectingWebSocket', 'onclose', self.url); // } // eventTarget.dispatchEvent(generateEvent('close')); // } // // var timeout = self.reconnectInterval * Math.pow(self.reconnectDecay, self.reconnectAttempts); // setTimeout(function () { // self.reconnectAttempts++; // self.open(true); // }, timeout > self.maxReconnectInterval ? self.maxReconnectInterval : timeout); // } // }; // ws.onmessage = function (event) { // if (self.debug || ReconnectingWebSocket.debugAll) { // console.debug('ReconnectingWebSocket', 'onmessage', self.url, event.data); // } // var e = generateEvent('message'); // e.data = event.data; // eventTarget.dispatchEvent(e); // }; // ws.onerror = function (event) { // if (self.debug || ReconnectingWebSocket.debugAll) { // console.debug('ReconnectingWebSocket', 'onerror', self.url, event); // } // eventTarget.dispatchEvent(generateEvent('error')); // }; // }; // // // Whether or not to create a websocket upon instantiation // if (this.automaticOpen == true) { // this.open(false); // } // // /** // * Transmits data to the server over the WebSocket connection. // * // * @param data a text string, ArrayBuffer or Blob to send to the server. // */ // this.send = function (data) { // if (ws) { // if (self.debug || ReconnectingWebSocket.debugAll) { // console.debug('ReconnectingWebSocket', 'send', self.url, data); // } // return ws.send(data); // } else { // throw 'INVALID_STATE_ERR : Pausing to reconnect websocket'; // } // }; // // /** // * Closes the WebSocket connection or connection attempt, if any. // * If the connection is already CLOSED, this method does nothing. // */ // this.close = function (code, reason) { // // Default CLOSE_NORMAL code // if (typeof code == 'undefined') { // code = 1000; // } // forcedClose = true; // if (ws) { // ws.close(code, reason); // } // }; // // /** // * Additional public API method to refresh the connection if still open (close, re-open). // * For example, if the app suspects bad data / missed heart beats, it can try to refresh. // */ // this.refresh = function () { // if (ws) { // ws.close(); // } // }; // } // // /** // * An event listener to be called when the WebSocket connection's readyState changes to OPEN; // * this indicates that the connection is ready to send and receive data. // */ // ReconnectingWebSocket.prototype.onopen = function (event) {}; // /** An event listener to be called when the WebSocket connection's readyState changes to CLOSED. */ // ReconnectingWebSocket.prototype.onclose = function (event) {}; // /** An event listener to be called when a connection begins being attempted. */ // ReconnectingWebSocket.prototype.onconnecting = function (event) {}; // /** An event listener to be called when a message is received from the server. */ // ReconnectingWebSocket.prototype.onmessage = function (event) {}; // /** An event listener to be called when an error occurs. */ // ReconnectingWebSocket.prototype.onerror = function (event) {}; // // /** // * Whether all instances of ReconnectingWebSocket should log debug messages. // * Setting this to true is the equivalent of setting all instances of ReconnectingWebSocket.debug to true. // */ // ReconnectingWebSocket.debugAll = false; // // ReconnectingWebSocket.CONNECTING = WebSocket.CONNECTING; // ReconnectingWebSocket.OPEN = WebSocket.OPEN; // ReconnectingWebSocket.CLOSING = WebSocket.CLOSING; // ReconnectingWebSocket.CLOSED = WebSocket.CLOSED; // // return ReconnectingWebSocket; // }); // // /***/ }), // /* 5 */ // /***/ (function(module, exports, __webpack_require__) { // // "use strict"; // // // Object.defineProperty(exports, "__esModule", { // value: true // }); // exports.default = debugInit; // function debugInit() { // var container = document.createElement('div'); // container.style.display = 'none'; // var isVisible = false; // 刚开始不可见,调用setFrameDebugText后,才可见 // // var isFrameDebugClosed = false; // // var isEnabled = false; // var style = { // 'position': 'absolute', // 'top': 0, // 'left': 0, // 'height': '20px', // 'line-height': '20px', // 'z-index': 10000, // 'width': '100%', // 'padding': '5px 10px', // 'color': '#F76a24', // 'background-color': '#fefcec', // 'font-family': '\'Helvetica Neue\', \'Hiragino Sans GB\', Helvetica' // }; // var styleString = ''; // for (var k in style) { // var v = style[k]; // styleString += k + ': ' + v + ';'; // } // // var closeBtnStyle = { // 'position': 'absolute', // 'right': 0, // 'top': 0, // 'padding': '5px 10px', // 'z-index': 10001 // }; // var closeStyleString = ''; // for (var k in closeBtnStyle) { // var v = closeBtnStyle[k]; // closeStyleString += k + ': ' + v + ';'; // } // // container.innerHTML = '
\xD7'; // // // sdk加载在head中,当sdk执行时,可能获取不到body,需要onload之后,才将执行append // // window.addEventListener('load', function () { // document.body.appendChild(container); // var div = document.querySelector('#framedebug'); // var isEnabled = true; // document.querySelector("#framedebugclose").onclick = function () { // isEnabled = false; // container.style.display = 'none'; // }; // // }); // // function setDebugText(text) { // if (!isEnabled) { // return; // } // if (!isVisible) { // // 最开始不可见,第一次调用后,才可见 // container.style.display = 'block '; // isVisible = true; // } // div.innerText = text; // } // return setDebugText; // } // // /***/ }), // /* 6 */ // /***/ (function(module, exports, __webpack_require__) { // // "use strict"; // // // Object.defineProperty(exports, "__esModule", { // value: true // }); // exports.setDebugAppid = exports.getQQ = exports.getAppid = undefined; // // var _util = __webpack_require__(0); // // var debugAppid; // 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]; // // function isAppidVaild(appid) { // appid = parseInt(appid); // if (debugAppidList.indexOf(appid) > -1) { // return true; // } // return false; // } // // // 生成随机QQ,不再支持指定QQ // function getQQ() { // var qq = Math.ceil(Math.random() * 1000000000 + 10000); // (0, _util.log)('qq ' + qq); // return qq; // } // // function setDebugAppid(appid) { // debugAppid = appid; // } // // function getAppid() { // if (debugAppid) { // return debugAppid; // } // var appid = (0, _util.getParam)('appid'); // if (isAppidVaild(appid)) { // return appid; // } // return debugAppidList[0]; // } // // exports.getAppid = getAppid; // exports.getQQ = getQQ; // exports.setDebugAppid = setDebugAppid; // // /***/ }), // /* 7 */ // /***/ (function(module, exports, __webpack_require__) { // // "use strict"; // // // Object.defineProperty(exports, "__esModule", { // value: true // }); // // 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; }; // // exports.default = function (qqgame) { // var frameWs; // var uin; // var isFrameGame; // var frameFps; // var isGameEnd = false; // // var helloMsgTimer = null; // var ws; // // qqgame.setDebugAppid = _util2.setDebugAppid; // qqgame.invoke = function (name, params) { // if (isGameEnd) { // return; // } // params = params || {}; // (0, _util.log)('invoke ' + name + ' ' + JSON.stringify(params)); // // if (name == "frameData") { // frameWs.send(params); // return; // } // // wsPromise.then(function () { // var json = { // 'eID': name, // 'ePara': params // }; // // if (name == 'gameInit') { // params.appid = (0, _util2.getAppid)(); // (0, _util.log)('appid ' + params.appid); // params.qq = uin = (0, _util2.getQQ)(); // // 帧同步直连 // if (params.openFraming) { // isFrameGame = true; // frameFps = params.fpsExpect; // params.openFraming = undefined; // params.fpsExpect = undefined; // } // } // // // 如果游戏结束,长连接不再发心跳 // // gameExit 只有debug环境下才有这个eID // if (name == 'gameResult' || name == 'gameExit') { // isGameEnd = true; // // clearInterval(helloMsgTimer); // isFrameGame && frameWs.stop(); // } // ws.send(JSON.stringify(json)); // }); // }; // // var cbList = []; // qqgame.onMessage = function (cb) { // cbList.push(cb); // }; // // // 客户端调用页面提供的接口 // qqgame.pvpResponse = function (data) { // // if (name === 'gameReset') { // // isGameEnd = false; // // } // // // 加防护,游戏结算后,不再接受客户端的消息 // if (isGameEnd) { // return; // } // // if ((typeof data === 'undefined' ? 'undefined' : _typeof(data)) !== 'object') { // data = JSON.parse(data); // } // var msgType = data.eID; // var msgData = data.ePara; // if (msgType !== 'frameData') { // (0, _util.log)('onMessage ' + JSON.stringify(data)); // } // // cbList.forEach(function (cb) { // cb(msgType, msgData); // }); // }; // // var wsPromise = function () { // return new Promise(function (resolve, reject) { // var wsURL = 'ws://test.go.minigame.qq.com/h5pvpservice/'; // ws = new WebSocket(wsURL); // ws.onopen = function () { // resolve(); // (0, _util.log)('ws open'); // }; // // ws.onmessage = function (data) { // var msg = data.data; // msg = JSON.parse(msg); // var cmd = msg.eID; // // if (isFrameGame) { // if (cmd == "session") { // var tableKey = msg.ePara.tableKey; // var frameSvrId = msg.ePara.frameSvrId; // frameWs = (0, _frame2.default)({ // uin: uin, // tableKey: tableKey, // frameSvrId: frameSvrId, // frameFps: frameFps, // frameURL: 'ws://test.trans.mobile.minigame.qq.com', // framePort: 9050, // cgiPath: '', // onMessage: function onMessage(data) { // qqgame.pvpResponse({ // eID: 'frameData', // ePara: data // }); // } // }); // return; // } // // // 如果是帧同步,拦截channelCreated,等直连成功后,再通知游戏channelCreated // if (cmd == "channelCreated") { // frameWs.wsPromise.then(function () { // qqgame.pvpResponse(msg); // }); // return; // } // } // // if (cmd == "leave") { // isGameEnd = true; // // clearInterval(helloMsgTimer); // isFrameGame && frameWs.stop(); // } // qqgame.pvpResponse(msg); // }; // // ws.onerror = function (error) { // (0, _util.log)('ws error ' + JSON.stringify(error)); // }; // }); // }(); // // window.addEventListener('beforeunload', function () { // if (!isGameEnd) { // // 如果已经发送过gameResult,这里则不再发送 // qqgame.invoke('gameExit'); // } // }); // }; // // var _util = __webpack_require__(0); // // var _util2 = __webpack_require__(6); // // var _frame = __webpack_require__(2); // // var _frame2 = _interopRequireDefault(_frame); // // function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } // // /***/ }), // /* 8 */ // /***/ (function(module, exports, __webpack_require__) { // // "use strict"; // // // var _util = __webpack_require__(0); // // var _sdk = __webpack_require__(7); // // var _sdk2 = _interopRequireDefault(_sdk); // // var _sdk3 = __webpack_require__(3); // // var _sdk4 = _interopRequireDefault(_sdk3); // // var _robot = __webpack_require__(1); // // function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } // // var qqgame = window.qqgame = window.qqgame || {}; // // // 避免多次加载 SDK // if (!qqgame.invoke) { // qqgame.version = '0.3.5-beta.1'; // // Web SDK 是否已重载机器人相关函数 // qqgame.isWebSDKOverloadRobotFunction = true; // (0, _util.log)('version ' + qqgame.version); // (0, _util.log)('WiKi https://qqgame.qq.com/h5wiki/pvp-sdk'); // // qqgame.isQQGame = _util.isQQGame; // qqgame.getDeviceInfo = _util.getDeviceInfo; // qqgame.isAndroid = _util.isAndroid; // qqgame.isIOS = _util.isIOS; // qqgame.getEnv = _util.getEnv; // // qqgame.isRobot = _robot.isRobot; // qqgame.robotLevel = _robot.robotLevel; // // qqgame.RESULT_LOSE = -1; // 失败 // qqgame.RESULT_DRAW = 0; //平局 // qqgame.RESULT_WIN = 1; // 胜利 // qqgame.RESULT_LEAVE = 2; // 逃跑 // qqgame.RESULT_TYPE_RESULT = 1; // 胜负结算 // qqgame.RESULT_TYPE_RANK = 2; // 排名结算 // // if (_util.isDebug) { // (0, _sdk2.default)(qqgame); // } else { // (0, _sdk4.default)(qqgame); // } // } // // module.exports = qqgame; // // /***/ }) // /******/ ]); // });