Commit 0eb7f34f authored by aiduck's avatar aiduck

合并代码

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