f207f9a8-6ba3-4b60-aedd-2d49c3882381.js 3.38 KB
"use strict";
cc._RF.push(module, 'f207fmoa6NLYK7dLUnDiCOB', 'CooperationDotMgr');
// script/cooperation/script/CooperationDotMgr.ts

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const CooperationDataCenter_1 = require("./CooperationDataCenter");
const CryptoJS_1 = require("../script/CryptoJS");
const SALT = "d0dd883ae80667d27b924d1e52b78b59";
/**打点服务 */
const DOT_SERVER = "/client/v1/event/log/put";
/**测试服打点地址 */
const DOT_URL_DEBUG = "https://eventstat-test.icesimba.com";
/**正式服打点地址 */
const DOT_URL_RELEASE = "https://eventstat.icesimba.com";
/**是否打点到测试服,否则打点到正式服 */
const DOT_DEBUG = false;
/**游戏id */
const GAME_ID = "cooperation";
let CooperationDotMgr = /** @class */ (() => {
    class CooperationDotMgr {
        static getInstance() {
            return CooperationDotMgr._instance;
        }
        /**获取打点请求服务 */
        getXHR() {
            let url = DOT_DEBUG ? DOT_URL_DEBUG : DOT_URL_RELEASE;
            url += DOT_SERVER;
            let xmlHttp = new XMLHttpRequest();
            xmlHttp.open('POST', url);
            xmlHttp.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');
            xmlHttp.onreadystatechange = function () {
                if (xmlHttp.readyState === 4) {
                    if (xmlHttp.status === 200) {
                        console.log("dot succeed");
                    }
                }
            };
            return xmlHttp;
        }
        async dot(eventKey, gameData, category) {
            let channel = CooperationDataCenter_1.default.getInstance().getCurGameChannel();
            if ("dummy" === channel || "" === channel)
                return;
            let data = this.getBaseElements();
            data["category"] = category ? category : "cooperation_event";
            data["id"] = eventKey ? eventKey : "event";
            data["game_data"] = gameData ? gameData : {};
            data["game_id"] = GAME_ID;
            let xhr = this.getXHR();
            let stringfyData = JSON.stringify(data);
            let upLoadData = {
                event_type: category,
                data: stringfyData,
                sign: CryptoJS_1.CryptoJS.MD5(stringfyData + SALT).toString()
            };
            let upLoadStringfy = JSON.stringify(upLoadData);
            await xhr.send(upLoadStringfy);
        }
        getBaseElements() {
            let base = {
                mainGameId: CooperationDataCenter_1.default.getInstance().getCurGameID(),
                mainAppId: CooperationDataCenter_1.default.getInstance().getCurGameAppID(),
                dotTime: (new Date()).toTimeString(),
                channel: CooperationDataCenter_1.default.getInstance().getCurGameChannel()
            };
            return base;
        }
        /**点击子游戏打点 */
        dotClickSubGame(appId, appName, index, location) {
            let eventKey = "clickSubGame";
            this.dot(eventKey, { appId: appId, appName: appName, index: index, location: location }, eventKey);
        }
        /**点击游戏中心打点 */
        dotClickGameCenter() {
            let eventKey = "clickGameCenter";
            this.dot(eventKey, {}, eventKey);
        }
    }
    CooperationDotMgr._instance = new CooperationDotMgr();
    return CooperationDotMgr;
})();
exports.default = CooperationDotMgr;

cc._RF.pop();