112 lines
2.3 KiB
JavaScript
112 lines
2.3 KiB
JavaScript
"use strict";
|
|
cc._RF.push(module, '1452b2tf35K7qzaSd3AgQYf', 'trace.mod');
|
|
// Scripts/nx/mods/trace/trace.mod.js
|
|
|
|
"use strict";
|
|
|
|
/*******************************************************************************
|
|
*
|
|
* 埋点服务
|
|
*
|
|
*
|
|
*
|
|
* 2020.08.31
|
|
******************************************************************************/
|
|
|
|
var MOD = require("nx.mod");
|
|
var TDefine = require("trace.define");
|
|
var TTT = TDefine.TraceType;
|
|
var TraceManager = cc.Class({
|
|
"extends": MOD,
|
|
name: "TraceManager",
|
|
// 初始化
|
|
initialize: function initialize(_args) {
|
|
// USPER
|
|
this._super(_args);
|
|
|
|
// 队列
|
|
this.router = "";
|
|
this.queues = [];
|
|
this.sid = "";
|
|
this.rid = 0;
|
|
|
|
// 访问接口(设置)
|
|
nx.mTrace = this;
|
|
return true;
|
|
},
|
|
// 销毁
|
|
uninitialize: function uninitialize() {
|
|
// 访问接口(关闭)
|
|
nx.mTrace = null;
|
|
|
|
// USPER
|
|
return this._super();
|
|
},
|
|
// 设置路由
|
|
setRouter: function setRouter(_url) {
|
|
this.router = _url;
|
|
},
|
|
// 设置角色信息
|
|
setRole: function setRole(_sid, _rid) {
|
|
this.sid = _sid;
|
|
this.rid = _rid;
|
|
},
|
|
// 埋点
|
|
trace: function trace(_type, _p1, _p2, _cb, _reset) {
|
|
if (_reset === void 0) {
|
|
_reset = false;
|
|
}
|
|
nx.debug("$Trace:fire:" + _type);
|
|
if (_reset) {
|
|
this.queues = [];
|
|
}
|
|
|
|
// 无效类型
|
|
if (!nx.dt.numPositive(_type, false)) {
|
|
nx.error("$Trace:\u65E0\u6548\u57CB\u70B9!" + _type);
|
|
nx.dt.fnInvoke(_cb, false);
|
|
return;
|
|
}
|
|
|
|
// 过滤
|
|
// if( _type < TTT.Newbee ) {
|
|
// if( nx.bridge && nx.bridge.role ) {
|
|
// let vo = nx.bridge.role.getRoleVo();
|
|
// if( vo && vo.lev > TDefine.NewbeeLevel ) {
|
|
// return;
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
var args = {
|
|
sid: this.sid,
|
|
rid: this.rid,
|
|
dot_type: _type.toString(),
|
|
p1: "" + _p1 || "",
|
|
p2: "" + _p2 || ""
|
|
};
|
|
this.queues.push({
|
|
args: args,
|
|
cb: _cb
|
|
});
|
|
this.nextCommit();
|
|
},
|
|
// 上传下一个
|
|
nextCommit: function nextCommit() {
|
|
if (this.queues.length == 0) {
|
|
return;
|
|
}
|
|
var task = this.queues.shift();
|
|
if (task) {
|
|
nx.web.post(this.router, task.args);
|
|
}
|
|
|
|
// 下一个
|
|
this.nextCommit();
|
|
}
|
|
});
|
|
|
|
// 模块导出
|
|
module.exports = TraceManager;
|
|
|
|
cc._RF.pop(); |