Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
rip
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fanxuehui
rip
Commits
1426a6d1
Commit
1426a6d1
authored
Aug 29, 2019
by
aiduck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
保存上下文tryReport
parent
96936a35
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
28 deletions
+43
-28
package-lock.json
package-lock.json
+1
-1
monitor.js
src/lib/monitor.js
+3
-1
reporter.js
src/lib/reporter.js
+32
-19
tracks.worker.js
src/lib/tracks.worker.js
+7
-7
No files found.
package-lock.json
View file @
1426a6d1
{
{
"name"
:
"@tuia/rip"
,
"name"
:
"@tuia/rip"
,
"version"
:
"0.2.
0
"
,
"version"
:
"0.2.
1
"
,
"lockfileVersion"
:
1
,
"lockfileVersion"
:
1
,
"requires"
:
true
,
"requires"
:
true
,
"dependencies"
:
{
"dependencies"
:
{
...
...
src/lib/monitor.js
View file @
1426a6d1
...
@@ -31,7 +31,7 @@ class Monitor {
...
@@ -31,7 +31,7 @@ class Monitor {
this
.
tracksWorker
.
onmessage
=
(
event
)
=>
{
this
.
tracksWorker
.
onmessage
=
(
event
)
=>
{
switch
(
event
.
data
)
{
switch
(
event
.
data
)
{
case
"resetRecord"
:
case
"resetRecord"
:
this
.
record
();
this
.
record
();
// 开启录制
break
;
break
;
default
:
default
:
console
.
log
(
"unknow action"
,
event
.
data
);
console
.
log
(
"unknow action"
,
event
.
data
);
...
@@ -74,6 +74,8 @@ class Monitor {
...
@@ -74,6 +74,8 @@ class Monitor {
clearTimeout
(
timer
);
clearTimeout
(
timer
);
timer
=
setTimeout
(()
=>
{
timer
=
setTimeout
(()
=>
{
console
.
log
(
'hashchange reset'
);
console
.
log
(
'hashchange reset'
);
// 路由跳转的前关闭录制
this
.
stop
();
this
.
reset
({
path
:
location
.
hash
});
this
.
reset
({
path
:
location
.
hash
});
},
1000
);
},
1000
);
});
});
...
...
src/lib/reporter.js
View file @
1426a6d1
...
@@ -43,7 +43,10 @@ class Reporter {
...
@@ -43,7 +43,10 @@ class Reporter {
const
formData
=
new
FormData
();
const
formData
=
new
FormData
();
// 保存上下文
// 保存上下文
const
trackId
=
this
.
counter
.
count
;
const
trackId
=
this
.
counter
.
count
;
uploadingPile
.
add
(
trackId
);
const
recordKey
=
this
.
recordKey
;
log
(
'trackId'
,
trackId
);
log
(
'recordKey'
,
recordKey
);
this
.
uploadingPile
.
add
(
trackId
);
formData
.
append
(
"file"
,
blob
,
`
${
this
.
recordKey
+
trackId
}
.json`
);
formData
.
append
(
"file"
,
blob
,
`
${
this
.
recordKey
+
trackId
}
.json`
);
const
extra
=
{
const
extra
=
{
...
this
.
baseInfo
,
...
this
.
baseInfo
,
...
@@ -62,20 +65,28 @@ class Reporter {
...
@@ -62,20 +65,28 @@ class Reporter {
return
res
.
json
();
return
res
.
json
();
})
})
.
then
(
res
=>
{
.
then
(
res
=>
{
const
snapIndex
=
this
.
bus
&&
this
.
bus
.
map
((
item
,
index
)
=>
{
/** 因为在路由跳转前可能存在上个路由里面遗留的部分数据,
if
(
item
.
trackId
===
trackId
)
{
* 并且销毁dom的时候数据量又大于40000,那么一定调用了上传toCDN的接口
return
index
;
* 而toCDN的接口会保存之前的trackId,而this.bus在路由跳转的时候会被清空
}
* 那么上下文的trackId在this.bus中就会找不到,找到也不是正确的*/
});
if
(
this
.
recordKey
!==
recordKey
)
{
log
(
"url定位"
,
snapIndex
);
log
(
'路由跳转遗留数据'
);
log
(
"url内容"
,
res
.
data
.
url
);
return
;
// 向bus中注入
}
else
{
this
.
bus
.
splice
(
snapIndex
,
1
,
dataWrapper
(
extra
,
res
.
data
.
url
));
const
snapIndex
=
this
.
bus
&&
this
.
bus
.
findIndex
((
item
,
index
)
=>
{
// 在trackId之前 包括trackId本身的数据全部上传
if
(
item
.
trackId
===
trackId
)
{
const
reportData
=
this
.
bus
.
splice
(
0
,
snapIndex
+
1
);
return
index
;
this
.
report
(
reportData
);
}
uploadingPile
.
delete
(
trackId
);
});
return
res
;
log
(
'snapIndex'
,
snapIndex
);
// 向bus中注入
this
.
bus
.
splice
(
snapIndex
,
1
,
dataWrapper
(
extra
,
res
.
data
.
url
));
// 在trackId之前 包括trackId本身的数据全部上传
this
.
uploadingPile
.
delete
(
trackId
);
const
reportData
=
this
.
bus
.
splice
(
0
,
snapIndex
+
1
);
this
.
report
(
reportData
);
return
res
;
}
});
});
}
catch
(
e
)
{
}
catch
(
e
)
{
log
(
"上传失败,原因:"
,
e
.
message
);
log
(
"上传失败,原因:"
,
e
.
message
);
...
@@ -91,18 +102,21 @@ class Reporter {
...
@@ -91,18 +102,21 @@ class Reporter {
this
.
bus
.
push
(
dataWrapper
(
extra
,
data
));
this
.
bus
.
push
(
dataWrapper
(
extra
,
data
));
}
}
// 尝试上传
// 尝试上传
tryReport
(
data
)
{
tryReport
(
isOverHundred
)
{
// 如果有cdn的内容在上传,那么我们不做任何的上传直接返回
// 如果有cdn的内容在上传,那么我们不做任何的上传直接返回
if
(
this
.
uploadingPile
.
length
>
0
)
{
if
(
this
.
uploadingPile
.
length
>
0
)
{
log
(
'有cdn的内容在上传'
);
log
(
'有cdn的内容在上传'
,
this
.
uploadingPile
);
return
;
return
;
}
else
{
}
else
{
this
.
report
(
data
);
let
reportData
=
isOverHundred
?
this
.
bus
.
splice
(
0
,
100
)
:
this
.
bus
.
splice
(
0
,
this
.
bus
.
length
);
this
.
report
(
reportData
);
}
}
}
}
// 真正上传
// 真正上传
report
(
data
)
{
report
(
data
)
{
log
(
"上传数据"
,
data
);
log
(
"上传数据"
,
data
);
log
(
'上传后的bus'
,
this
.
bus
);
try
{
try
{
fetch
(
`
${
this
.
environmentUrl
}
/behavior/record`
,
{
fetch
(
`
${
this
.
environmentUrl
}
/behavior/record`
,
{
// fetch(`http://localhost:3000/behavior/record`, {
// fetch(`http://localhost:3000/behavior/record`, {
...
@@ -132,7 +146,6 @@ class Reporter {
...
@@ -132,7 +146,6 @@ class Reporter {
reset
()
{
reset
()
{
this
.
bus
=
[];
this
.
bus
=
[];
this
.
counter
.
reset
();
this
.
counter
.
reset
();
this
.
generateKey
();
}
}
}
}
...
...
src/lib/tracks.worker.js
View file @
1426a6d1
...
@@ -16,24 +16,24 @@ onmessage = ({ data: { type, payload } }) => {
...
@@ -16,24 +16,24 @@ onmessage = ({ data: { type, payload } }) => {
log
(
"bus"
,
reporter
.
bus
);
log
(
"bus"
,
reporter
.
bus
);
// todo : 全量快照上传cdn || 或者字符内容超过3000
// todo : 全量快照上传cdn || 或者字符内容超过3000
let
strData
=
JSON
.
stringify
(
payload
.
data
);
let
strData
=
JSON
.
stringify
(
payload
.
data
);
if
(
payload
.
type
===
2
||
strData
.
length
>
3
0000
)
{
if
(
payload
.
type
===
2
||
strData
.
length
>
4
0000
)
{
reporter
.
toCDN
(
payload
);
reporter
.
toCDN
(
payload
);
}
}
// todo : 数据压缩
// todo : 数据压缩
// todo : 根据事件类型优先级触发上传策略(click)
// todo : 根据事件类型优先级触发上传策略(click)
if
(
payload
.
data
.
source
===
2
&&
(
payload
.
data
.
type
===
2
||
payload
.
data
.
type
===
3
)
&&
!
reporter
.
isUploading
)
{
if
(
payload
.
data
.
source
===
2
&&
(
payload
.
data
.
type
===
2
||
payload
.
data
.
type
===
3
))
{
reporter
.
tryReport
(
reporter
.
bus
);
reporter
.
tryReport
(
false
);
}
}
// todo : 数据超出100条上线,自动上传
// todo : 数据超出100条上线,自动上传
if
(
reporter
.
bus
.
length
>
100
&&
!
reporter
.
isUploading
)
{
if
(
reporter
.
bus
.
length
>
100
)
{
reporter
.
tryReport
(
reporter
.
bus
);
reporter
.
tryReport
(
true
);
}
}
break
;
break
;
case
"reset"
:
case
"reset"
:
// todo : 重置参数,重新生成recordKey
// todo : 重置参数,重新生成recordKey
reporter
.
updateData
(
payload
);
reporter
.
reset
();
reporter
.
reset
();
postMessage
(
'resetRecord'
);
reporter
.
updateData
(
payload
);
postMessage
(
'resetRecord'
);
// 数据重置之后通知录制开启
log
(
"path"
,
reporter
.
baseInfo
.
path
);
log
(
"path"
,
reporter
.
baseInfo
.
path
);
log
(
"分片id"
,
reporter
.
recordKey
);
log
(
"分片id"
,
reporter
.
recordKey
);
break
;
break
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment