/******************************************************************************* * * 埋点服务 * * * * 2020.08.31 ******************************************************************************/ const MOD = require( "nx.mod" ); const TDefine = require( "trace.define" ); const TTT = TDefine.TraceType; const TraceManager = cc.Class( { extends: MOD, name: "TraceManager", // 初始化 initialize: function( _args ) { // USPER this._super( _args ); // 队列 this.router = ""; this.queues = []; this.sid = ""; this.rid = 0; // 访问接口(设置) nx.mTrace = this; return true; }, // 销毁 uninitialize: function() { // 访问接口(关闭) nx.mTrace = null; // USPER return this._super(); }, // 设置路由 setRouter: function( _url ) { this.router = _url; }, // 设置角色信息 setRole: function( _sid, _rid ) { this.sid = _sid; this.rid = _rid; }, // 埋点 trace: function( _type, _p1, _p2, _cb, _reset = false ) { nx.debug( `$Trace:fire:${ _type }` ); if( _reset ) { this.queues = []; } // 无效类型 if( !nx.dt.numPositive( _type, false ) ) { nx.error( `$Trace:无效埋点!` + _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; // } // } // } let 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() { if( this.queues.length == 0 ) { return; } let task = this.queues.shift(); if( task ) { nx.web.post( this.router, task.args ); } // 下一个 this.nextCommit(); }, } ); // 模块导出 module.exports = TraceManager;