Commit 0eb7f34f authored by aiduck's avatar aiduck

合并代码

parent ee77a5c0
......@@ -16,7 +16,7 @@ export default class Monitor {
console.log('开始录制')
this.rrwebHandler = rrweb.record({
emit: event => {
this.tracksWorker.postMessage({ type: "record", event });
this.tracksWorker.postMessage({ type: "record", payload: event });
},
});
}
......@@ -32,7 +32,7 @@ export default class Monitor {
reset(event) {
this.rrwebHandler && this.rrwebHandler();
console.log('重置数据')
this.tracksWorker.postMessage({ type: "reset", event });
this.tracksWorker.postMessage({ type: "reset", payload: event });
}
// 发送信息
postMessage(action) {
......
......@@ -4,52 +4,54 @@ import _ from 'lodash';
// 原始数据数组
let events = [];
// 包装后的数据对象
let wrapEvents = [];
let wrapData = [];
// 分条视频id
let recordKey = '';
// 全量快照是否已经返回
let isCdnReturn = false;
onmessage = ({ data: { type, event } }) => {
onmessage = ({ data: { type, payload } }) => {
switch (type) {
case "record":
// todo : 数据本地存储
wrapEvents.push(utils.dataWrapper({
wrapData.push(utils.dataWrapper({
recordKey,
isCdn: false
}, event));
events.push(event);
}, payload));
events.push(payload);
// todo : 全量快照上传cdn
if(event.type === 2) {
if(payload.type === 2) {
const cdnIndex = _.findIndex(events, { 'type': 2 });
setTimeout(() => {
wrapEvents.splice(cdnIndex, 1, utils.dataWrapper({
wrapData.splice(cdnIndex, 1, utils.dataWrapper({
recordKey,
isCdn: true
}, event));
}, payload));
isCdnReturn = true;
}, 1000);
}
// todo : 数据压缩
// todo : 根据事件类型优先级触发上传策略(click)
if(event.data.source === 2 && isCdnReturn) {
console.log('点击上上传events', wrapEvents);
if(payload.data.source === 2 && isCdnReturn) {
console.log('点击上上传events', wrapData);
postMessage(wrapData);
events = [];
wrapEvents = [];
wrapData = [];
}
// todo : 数据超出100条上线,自动上传
if (wrapEvents.length > 100 && isCdnReturn) {
console.log('超出线上100条上传events', wrapEvents)
if (wrapData.length > 100 && isCdnReturn) {
console.log('超出线上100条上传events', wrapData)
postMessage(wrapData);
events = [];
wrapEvents = [];
wrapData = [];
}
break;
case "reset":
// todo : 重置参数,重新生成recordKey
events = [];
wrapEvents = [];
wrapData = [];
recordKey = '';
isCdnReture = false;
const { url, email } = events;
const { url, email } = payload;
recordKey = md5(url + email + Date.parse(new Date()));
console.log(url, '分片id', recordKey);
break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment