Commit 900aa80d authored by fanxuehui's avatar fanxuehui

fix(postmessage):

parent 319ad83b
{
"name": "hunter-rrweb",
"version": "0.0.1",
"description": "Tools for recording and replaying user behavior built using rrweb",
"description": "Tools for user behavior recording and playback based on rrweb",
"main": "dist/index.js",
"scripts": {
"dev": "cross-env NODE_ENV=dev node build.js",
......
......@@ -3,11 +3,18 @@ import TracksWorker from "./tracks.worker";
export default class Monitor {
rrwebHandler = null;
tracksWorker = new TracksWorker();
constructor() {
this.tracksWorker.onmessage = ({ data }) => {
console.log(data);
window.localStorage.setItem("rrevents", JSON.stringify(data));
console.log("local");
};
}
record() {
this.rrwebHandler && this.rrwebHandler();
this.rrwebHandler = rrweb.record({
emit: event => {
this.tracksWorker.postMessage({ type: "record", event });
this.tracksWorker.postMessage({ type: "record", payload: event });
},
});
}
......
let events = [];
onmessage = ({ data: { type, event } }) => {
onmessage = ({ data: { type, payload } }) => {
switch (type) {
case "record":
// todo : 根据事件类型优先级触发上传策略
// todo : 全量快照上传cdn
// todo : 数据压缩
events.push(event);
events.push(payload);
console.log(events);
if (events.length > 100) {
window.localStorage.setItem("rrevents", JSON.stringify(events));
postMessage(events);
events = [];
console.log("local");
}
break;
case "reset":
......
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