Application.js
17.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
var Common = require('Common');
var Network = require('Network');
//var ListView = require('ListView');
cc.Class({
extends: cc.Component,
properties: {
//键值由具体场景决定
_aSceneContext: { default: [] },
_aSceneParameter: { default: [] },
_bBackStatus: false,
_iDefaultCollectionId: -1,
_oScene: null,
_strSceneName: "",
},
// use this for initialization
onLoad: function () {
this._aSceneContext = [];
this._aSceneParameter = [];
//探针相关
this._oProbe = this.initProbe();
},
setScene: function (oScene) {
this._strSceneName = cc.director.getScene().name;
this._oScene = oScene;
},
getScene: function () {
return this._oScene;
},
getSceneContext: function () {
return this._aSceneContext;
},
popSceneContext: function () {
return this._aSceneContext.pop();
},
getTopSceneContext: function () {
return this._aSceneContext[this._aSceneContext.length - 1];
},
setSceneContext: function (aSceneContext) {
this._aSceneContext = aSceneContext;
},
getSceneParameter: function () {
return this._aSceneParameter;
},
popSceneParameter: function () {
return this._aSceneParameter.pop();
},
getTopSceneParameter: function () {
if (this._aSceneParameter.length) {
return this._aSceneParameter[this._aSceneParameter.length - 1];
} else {
return null;
}
},
setSceneParameter: function (aSceneParameter) {
this._aSceneParameter = aSceneParameter;
},
getBackStatus: function () {
return this._bBackStatus;
},
setBackStatus: function (bBackStatus) {
this._bBackStatus = bBackStatus;
},
getDefaultCollectionId: function () {
return this._iDefaultCollectionId;
},
setDefaultCollectionId: function (iCollectionId) {
this._iDefaultCollectionId = iCollectionId;
},
initProbe: function () {
try {
let _this = this;
//对于ajax进行拦截
let fnTempAjax = Network.ajax;
Network.ajax = function (strMethod, strURL, astrContentType, oDataOrPostBody, onSuccess, onError, oScope, oAdditionalData) {
if (_this._oScene && _this._oScene._bIsFocusInit) {
cc.log("strURL==>" + strURL);
if (-1 != strURL.indexOf("User/AddMedia2Collection")) {
console.log(strURL);
console.log(oDataOrPostBody);
_this._oProbe.requestProbe("MediaCollect", {
"mediaId": oDataOrPostBody.mediaId,
"mediaCode": oAdditionalData.code
});
}
if (-1 != strURL.indexOf("User/RemoveMediaFromCollection")) {
console.log(strURL);
console.log(oDataOrPostBody);
_this._oProbe.requestProbe("MediaUncollect", {
"mediaId": oDataOrPostBody.mediaId,
"mediaCode": oAdditionalData.code
});
}
}
fnTempAjax.call(Network, strMethod, strURL, astrContentType, oDataOrPostBody, onSuccess, onError, oScope, oAdditionalData);
}
return {
oSceneUIMap: {
"sceneMain": "index"
},
oCommonParam: {
product: "ForFun",
sessionId: "",
version: Common.VERSION,
userId: Common.USER_ID,
action: "",
},
loginEntrance: "",
lastActiveTime: "",
uuid: "",
inited: false,
jumpCode: "",
productId: "",
productPrice: "",
aInterActive: [],
aCollectActive: [],
oActionEvoker: null,
oActionList: null,
aDataShowScene: ["sceneAudioPlayer", "sceneCategoryList", "sceneCollectionList", "sceneFreeList", "sceneHistoryList", "sceneHotCategoryWithScreen",
"sceneKTVPlayer", "sceneRankList", "sceneSearch", "sceneShop", "sceneSongLibraryInPlayer", "sceneStarPersonalSection", "sceneSubIndex", "sceneSubjectList", "sceneTagList"],
init: function () {
try {
this.lastActiveTime = this.lastActiveTime || 0;
this.updateActive();
this.uuid = this.uuid || Common.uuid(32, 16);
this.sessionId = this.uuid || Common.uuid(32, 16);
this.inited = true;
} catch (err) {
jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "init in Application Error==>" + err);
}
},
updateActive: function () {//更新active,每次动作更新lastActiveTime
try {
let iCurrentTime = new Date().getTime();
if (iCurrentTime - this.lastActiveTime >= 20 * 60 * 1000) {//超过20分钟时 2分钟用来测试来着 todo:
this.lastActiveTime = iCurrentTime;//更新lastActiveTime时间
this.uuid = Common.uuid(32, 16);//更新uuid
this.oCommonParam.sessionId = this.uuid;
}
this.lastActiveTime = iCurrentTime;//更新动作时间
} catch (err) {
jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "updateActive in Application Error==>" + err);
}
},
requestProbe: function (strType, oExtra) {
try {
this.updateActive();
let oParam = Common.assign({}, this.oCommonParam);
oParam.action = strType;
let obj = {};
switch (strType) {
case "Login"://登录
obj = {
"productId": Common.AUTH_PRODUCT,//鉴权成功的产品Id
}
break;
case "UIEnter"://页面进入
if (!this.inited) {
this.init();
//对按键进行拦截
let self = this;
let fnKeyDown = _this._oScene.onKeyDown;
_this._oScene.onKeyDown = function (event) {
self.updateActive();
fnKeyDown.call(_this._oScene, event);
}
}
obj = {
"parameters": _this.getTopSceneParameter(),
"ui": this.oSceneUIMap[_this._strSceneName] || _this._strSceneName,
"jumpCode": this.jumpCode || "-"
}
break;
case "UILeave"://页面离开
this.jumpCode = Common.uuid(32, 16);
obj = {
"context": _this._oScene._oSceneContext,
"ui": this.oSceneUIMap[_this._strSceneName] || _this._strSceneName,
"jumpCode": this.jumpCode,//页面离开进来jumpcode对应
}
Common.assign(obj, _this._oScene._fiCurrentFocus && _this._oScene._fiCurrentFocus.getFocusProbeInfo() || {});
break;
case "interActive"://页面交互
obj = {
"ui": this.oSceneUIMap[_this._strSceneName] || _this._strSceneName,
"context": this.oActionContext || _this._oScene._oSceneContext,
"actionTime": this.lastActiveTime
}
break;
case "MediaPlay":
case "MediaPause":
case "MediaStop":
case "MediaPlayAvailable":
case "MediaSeek"://播控相关
obj = {
"mediaId": parseInt(_this._oScene._strRequestMediaId),
"mediaCode": _this._oScene._strRequestMediaCode,
"appId": _this._oScene._strAppId,
"actionTime": new Date().getTime()
}
break
case "MediaCollect"://收藏
case "MediaUncollect"://取消收藏
obj = {
"ui": this.oSceneUIMap[_this._strSceneName] || _this._strSceneName,
"mediaId": parseInt(_this._oScene._strRequestMediaId),
"mediaCode": _this._oScene._strRequestMediaCode,
"appId": _this._oScene._strAppId
}
break;
case "Subscribing"://订购发起
case "Subscribed"://订购发起
case "Unsubscribing"://退订发起
case "Unsubscribed"://退订结果
obj = {
"productId": Common.AUTH_PRODUCT,
"transactionId": "",
"actionTime": new Date().getTime()
}
break;
case "mediaSearch"://搜索行为
obj = {
"ui": this.oSceneUIMap[_this._strSceneName] || _this._strSceneName,
}
break;
case "mediaSearchAccept"://搜索采纳
let olink = _this._oScene._fiCurrentFocus && _this._oScene._fiCurrentFocus.getFocusProbeInfo() || {};
let oLinkPoint = olink.linkPoint;
obj = {
"ui": this.oSceneUIMap[_this._strSceneName] || _this._strSceneName,
"keyword": _this._oScene._oSceneContext.currentKeyword
}
obj[oLinkPoint.type + "Id"] = oLinkPoint.id;
obj[oLinkPoint.type + "Code"] = oLinkPoint.code;
break;
case "error"://页面报错了
obj = {
"ui": this.oSceneUIMap[_this._strSceneName] || _this._strSceneName,
"context": _this._oScene._oSceneContext,
}
break;
}
if (oExtra) {
Common.assign(obj, oExtra);
}
Common.assign(oParam, obj);
var aProbeArray = [];
if (strType == "UILeave" && this.aInterActive.length) {
// fnTempAjax('GET',BI_BASE_PATH,null,this.aInterActive,function(responseText){
// // Log.info("probe Business::");
// },function(responseText){
// // Log.info("probe Communication::");
// });
// fnTempAjax('GET',BI_BASE_PATH,null,this.aCollectActive,function(responseText){
// // Log.info("probe Business::");
// },function(responseText){
// // Log.info("probe Communication::");
// });
aProbeArray.push(oParam);
this.aInterActive = [];
this.aCollectActive = [];
} else if (strType == "interActive") {
if (_this._oScene && _this._oScene._bIsFocusInit) {
this.aInterActive.push([oParam]);
if (this.aInterActive.length < 3) {
return;
}
aProbeArray = this.aInterActive;
this.aInterActive = [];
}
} else if (strType == "MediaCollect" || strType == "MediaUncollect") {
this.aCollectActive.push([oParam]);
if (this.aCollectActive.length < 4) {
return;
}
aProbeArray = this.aCollectActive;
this.aCollectActive = [];
} else {
aProbeArray.push(oParam);
}
console.log("============================");
console.log(aProbeArray);
var oArgs = {
'ray': encodeURIComponent(JSON.stringify([aProbeArray]))//数组作为参数值传到ray参数里边
}
fnTempAjax('GET', Common.BI_BASE_PATH, null, oArgs, function (responseText) {
// Log.info("probe Business::");
}, function (responseText) {
// Log.info("probe Communication::");
});
} catch (err) {
jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "requestProbe in Application Error==>" + err);
}
}
}
} catch (err) {
jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "initProbe in Application Error==>" + err);
}
},
probeInterceptScrollStart: function (oList) {
try {
let _this = this;
let fnTemp = this._oScene.onListScrollStart;
this._oScene.onListScrollStart = function () {
if (_this._oScene && _this._oScene._bIsFocusInit) {
_this.oActionEvoker = _this._oScene._fiCurrentFocus;
_this.oActionList = oList;
cc.log("=====================================");
cc.log(oList);
cc.log(_this.oActionEvoker.node.name);
}
fnTemp.call(_this._oScene);
}
} catch (err) {
jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "probeInterceptScrollStart in Application Error==>" + err);
}
},
probeInterceptScrollEnd: function (oList) {
try {
let _this = this;
let fnTemp = this._oScene.onListScrollEnd;
this._oScene.onListScrollEnd = function () {
if (_this._oScene && _this._oScene._bIsFocusInit) {
let strModuleName = oList.node.name;
let strEvoke = "UIButton";
if (_this.oActionEvoker && -1 != Common.getNodePath(_this.oActionEvoker.node).indexOf(oList.node.name)) {
}
if (_this.oActionEvoker && _this.oActionEvoker.node && _this.oActionEvoker.node.name == "ScrollBarBlock") {
strEvoke = "ScrollBar";
}
this._oProbe.requestProbe("interActive", {
"action": "DataShow",
"module": strModuleName,
"context": {
"pageIndex": Math.ceil((oList._iRecordIndexOfFirstCellInPage + oList._iCellCountEachRow * oList._iShowCellRows) / oList._iCellCountEachRow / oList._iShowCellRows),
"evoke": strEvoke
}
});
}
fnTemp.call(_this._oScene);
}
} catch (err) {
jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V", "probeInterceptScrollEnd in Application Error==>" + err);
}
},
});