Commit e1c89f6a authored by aiduck's avatar aiduck

20190722

parent 319ad83b
...@@ -1486,6 +1486,12 @@ ...@@ -1486,6 +1486,12 @@
"supports-color": "^5.3.0" "supports-color": "^5.3.0"
} }
}, },
"charenc": {
"version": "0.0.2",
"resolved": "https://registry.npm.taobao.org/charenc/download/charenc-0.0.2.tgz",
"integrity": "sha1-wKHS86cJLgN3S/qD8UwPxXkKhmc=",
"dev": true
},
"chokidar": { "chokidar": {
"version": "2.1.6", "version": "2.1.6",
"resolved": "https://registry.npm.taobao.org/chokidar/download/chokidar-2.1.6.tgz?cache=0&sync_timestamp=1562457945399&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fchokidar%2Fdownload%2Fchokidar-2.1.6.tgz", "resolved": "https://registry.npm.taobao.org/chokidar/download/chokidar-2.1.6.tgz?cache=0&sync_timestamp=1562457945399&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fchokidar%2Fdownload%2Fchokidar-2.1.6.tgz",
...@@ -1727,6 +1733,35 @@ ...@@ -1727,6 +1733,35 @@
"sha.js": "^2.4.8" "sha.js": "^2.4.8"
} }
}, },
"cross-env": {
"version": "5.2.0",
"resolved": "http://registry.npm.taobao.org/cross-env/download/cross-env-5.2.0.tgz",
"integrity": "sha1-bs1MAV1Xc+YUA57lKQdmabnRJvI=",
"dev": true,
"requires": {
"cross-spawn": "^6.0.5",
"is-windows": "^1.0.0"
}
},
"cross-spawn": {
"version": "6.0.5",
"resolved": "http://registry.npm.taobao.org/cross-spawn/download/cross-spawn-6.0.5.tgz",
"integrity": "sha1-Sl7Hxk364iw6FBJNus3uhG2Ay8Q=",
"dev": true,
"requires": {
"nice-try": "^1.0.4",
"path-key": "^2.0.1",
"semver": "^5.5.0",
"shebang-command": "^1.2.0",
"which": "^1.2.9"
}
},
"crypt": {
"version": "0.0.2",
"resolved": "https://registry.npm.taobao.org/crypt/download/crypt-0.0.2.tgz",
"integrity": "sha1-iNf/fsDfuG9xPch7u0LQRNPmxBs=",
"dev": true
},
"crypto-browserify": { "crypto-browserify": {
"version": "3.12.0", "version": "3.12.0",
"resolved": "http://registry.npm.taobao.org/crypto-browserify/download/crypto-browserify-3.12.0.tgz", "resolved": "http://registry.npm.taobao.org/crypto-browserify/download/crypto-browserify-3.12.0.tgz",
...@@ -2241,8 +2276,7 @@ ...@@ -2241,8 +2276,7 @@
"ansi-regex": { "ansi-regex": {
"version": "2.1.1", "version": "2.1.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"aproba": { "aproba": {
"version": "1.2.0", "version": "1.2.0",
...@@ -2263,14 +2297,12 @@ ...@@ -2263,14 +2297,12 @@
"balanced-match": { "balanced-match": {
"version": "1.0.0", "version": "1.0.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"brace-expansion": { "brace-expansion": {
"version": "1.1.11", "version": "1.1.11",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"balanced-match": "^1.0.0", "balanced-match": "^1.0.0",
"concat-map": "0.0.1" "concat-map": "0.0.1"
...@@ -2285,20 +2317,17 @@ ...@@ -2285,20 +2317,17 @@
"code-point-at": { "code-point-at": {
"version": "1.1.0", "version": "1.1.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"concat-map": { "concat-map": {
"version": "0.0.1", "version": "0.0.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"console-control-strings": { "console-control-strings": {
"version": "1.1.0", "version": "1.1.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"core-util-is": { "core-util-is": {
"version": "1.0.2", "version": "1.0.2",
...@@ -2415,8 +2444,7 @@ ...@@ -2415,8 +2444,7 @@
"inherits": { "inherits": {
"version": "2.0.3", "version": "2.0.3",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"ini": { "ini": {
"version": "1.3.5", "version": "1.3.5",
...@@ -2428,7 +2456,6 @@ ...@@ -2428,7 +2456,6 @@
"version": "1.0.0", "version": "1.0.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"number-is-nan": "^1.0.0" "number-is-nan": "^1.0.0"
} }
...@@ -2443,7 +2470,6 @@ ...@@ -2443,7 +2470,6 @@
"version": "3.0.4", "version": "3.0.4",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"brace-expansion": "^1.1.7" "brace-expansion": "^1.1.7"
} }
...@@ -2451,14 +2477,12 @@ ...@@ -2451,14 +2477,12 @@
"minimist": { "minimist": {
"version": "0.0.8", "version": "0.0.8",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"minipass": { "minipass": {
"version": "2.3.5", "version": "2.3.5",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"safe-buffer": "^5.1.2", "safe-buffer": "^5.1.2",
"yallist": "^3.0.0" "yallist": "^3.0.0"
...@@ -2477,7 +2501,6 @@ ...@@ -2477,7 +2501,6 @@
"version": "0.5.1", "version": "0.5.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"minimist": "0.0.8" "minimist": "0.0.8"
} }
...@@ -2558,8 +2581,7 @@ ...@@ -2558,8 +2581,7 @@
"number-is-nan": { "number-is-nan": {
"version": "1.0.1", "version": "1.0.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"object-assign": { "object-assign": {
"version": "4.1.1", "version": "4.1.1",
...@@ -2571,7 +2593,6 @@ ...@@ -2571,7 +2593,6 @@
"version": "1.4.0", "version": "1.4.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"wrappy": "1" "wrappy": "1"
} }
...@@ -2657,8 +2678,7 @@ ...@@ -2657,8 +2678,7 @@
"safe-buffer": { "safe-buffer": {
"version": "5.1.2", "version": "5.1.2",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"safer-buffer": { "safer-buffer": {
"version": "2.1.2", "version": "2.1.2",
...@@ -2694,7 +2714,6 @@ ...@@ -2694,7 +2714,6 @@
"version": "1.0.2", "version": "1.0.2",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"code-point-at": "^1.0.0", "code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0", "is-fullwidth-code-point": "^1.0.0",
...@@ -2714,7 +2733,6 @@ ...@@ -2714,7 +2733,6 @@
"version": "3.0.1", "version": "3.0.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"ansi-regex": "^2.0.0" "ansi-regex": "^2.0.0"
} }
...@@ -2758,14 +2776,12 @@ ...@@ -2758,14 +2776,12 @@
"wrappy": { "wrappy": {
"version": "1.0.2", "version": "1.0.2",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"yallist": { "yallist": {
"version": "3.0.3", "version": "3.0.3",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
} }
} }
}, },
...@@ -3094,6 +3110,12 @@ ...@@ -3094,6 +3110,12 @@
"integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=", "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=",
"dev": true "dev": true
}, },
"isexe": {
"version": "2.0.0",
"resolved": "http://registry.npm.taobao.org/isexe/download/isexe-2.0.0.tgz",
"integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=",
"dev": true
},
"isobject": { "isobject": {
"version": "3.0.1", "version": "3.0.1",
"resolved": "https://registry.npm.taobao.org/isobject/download/isobject-3.0.1.tgz", "resolved": "https://registry.npm.taobao.org/isobject/download/isobject-3.0.1.tgz",
...@@ -3184,10 +3206,9 @@ ...@@ -3184,10 +3206,9 @@
} }
}, },
"lodash": { "lodash": {
"version": "4.17.14", "version": "4.17.15",
"resolved": "https://registry.npm.taobao.org/lodash/download/lodash-4.17.14.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Flodash%2Fdownload%2Flodash-4.17.14.tgz", "resolved": "https://registry.npm.taobao.org/lodash/download/lodash-4.17.15.tgz",
"integrity": "sha1-nOSHrmbJYlT+ILWZ8htoFgKAeLo=", "integrity": "sha1-tEf2ZwoEVbv+7dETku/zMOoJdUg="
"dev": true
}, },
"loose-envify": { "loose-envify": {
"version": "1.4.0", "version": "1.4.0",
...@@ -3238,6 +3259,17 @@ ...@@ -3238,6 +3259,17 @@
"object-visit": "^1.0.0" "object-visit": "^1.0.0"
} }
}, },
"md5": {
"version": "2.2.1",
"resolved": "https://registry.npm.taobao.org/md5/download/md5-2.2.1.tgz",
"integrity": "sha1-U6s41f48iJG6RlMp6iP6wFQBJvk=",
"dev": true,
"requires": {
"charenc": "~0.0.1",
"crypt": "~0.0.1",
"is-buffer": "~1.1.1"
}
},
"md5.js": { "md5.js": {
"version": "1.3.5", "version": "1.3.5",
"resolved": "http://registry.npm.taobao.org/md5.js/download/md5.js-1.3.5.tgz", "resolved": "http://registry.npm.taobao.org/md5.js/download/md5.js-1.3.5.tgz",
...@@ -3430,6 +3462,12 @@ ...@@ -3430,6 +3462,12 @@
"integrity": "sha1-rCetpmFn+ohJpq3dg39rGJrSCBw=", "integrity": "sha1-rCetpmFn+ohJpq3dg39rGJrSCBw=",
"dev": true "dev": true
}, },
"nice-try": {
"version": "1.0.5",
"resolved": "http://registry.npm.taobao.org/nice-try/download/nice-try-1.0.5.tgz",
"integrity": "sha1-ozeKdpbOfSI+iPybdkvX7xCJ42Y=",
"dev": true
},
"node-libs-browser": { "node-libs-browser": {
"version": "2.2.1", "version": "2.2.1",
"resolved": "https://registry.npm.taobao.org/node-libs-browser/download/node-libs-browser-2.2.1.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fnode-libs-browser%2Fdownload%2Fnode-libs-browser-2.2.1.tgz", "resolved": "https://registry.npm.taobao.org/node-libs-browser/download/node-libs-browser-2.2.1.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fnode-libs-browser%2Fdownload%2Fnode-libs-browser-2.2.1.tgz",
...@@ -3657,6 +3695,12 @@ ...@@ -3657,6 +3695,12 @@
"integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=",
"dev": true "dev": true
}, },
"path-key": {
"version": "2.0.1",
"resolved": "https://registry.npm.taobao.org/path-key/download/path-key-2.0.1.tgz",
"integrity": "sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A=",
"dev": true
},
"path-parse": { "path-parse": {
"version": "1.0.6", "version": "1.0.6",
"resolved": "http://registry.npm.taobao.org/path-parse/download/path-parse-1.0.6.tgz", "resolved": "http://registry.npm.taobao.org/path-parse/download/path-parse-1.0.6.tgz",
...@@ -4074,6 +4118,21 @@ ...@@ -4074,6 +4118,21 @@
"safe-buffer": "^5.0.1" "safe-buffer": "^5.0.1"
} }
}, },
"shebang-command": {
"version": "1.2.0",
"resolved": "http://registry.npm.taobao.org/shebang-command/download/shebang-command-1.2.0.tgz",
"integrity": "sha1-RKrGW2lbAzmJaMOfNj/uXer98eo=",
"dev": true,
"requires": {
"shebang-regex": "^1.0.0"
}
},
"shebang-regex": {
"version": "1.0.0",
"resolved": "https://registry.npm.taobao.org/shebang-regex/download/shebang-regex-1.0.0.tgz",
"integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=",
"dev": true
},
"smoothscroll-polyfill": { "smoothscroll-polyfill": {
"version": "0.4.4", "version": "0.4.4",
"resolved": "https://registry.npm.taobao.org/smoothscroll-polyfill/download/smoothscroll-polyfill-0.4.4.tgz", "resolved": "https://registry.npm.taobao.org/smoothscroll-polyfill/download/smoothscroll-polyfill-0.4.4.tgz",
...@@ -4726,6 +4785,15 @@ ...@@ -4726,6 +4785,15 @@
} }
} }
}, },
"which": {
"version": "1.3.1",
"resolved": "http://registry.npm.taobao.org/which/download/which-1.3.1.tgz",
"integrity": "sha1-pFBD1U9YBTFtqNYvn1CRjT2nCwo=",
"dev": true,
"requires": {
"isexe": "^2.0.0"
}
},
"worker-farm": { "worker-farm": {
"version": "1.7.0", "version": "1.7.0",
"resolved": "https://registry.npm.taobao.org/worker-farm/download/worker-farm-1.7.0.tgz", "resolved": "https://registry.npm.taobao.org/worker-farm/download/worker-farm-1.7.0.tgz",
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
"author": "Dec-F", "author": "Dec-F",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"lodash": "^4.17.15",
"rrweb": "^0.7.18" "rrweb": "^0.7.18"
}, },
"devDependencies": { "devDependencies": {
...@@ -31,6 +32,7 @@ ...@@ -31,6 +32,7 @@
"@babel/preset-env": "^7.4.5", "@babel/preset-env": "^7.4.5",
"babel-loader": "^8.0.6", "babel-loader": "^8.0.6",
"cross-env": "^5.2.0", "cross-env": "^5.2.0",
"md5": "^2.2.1",
"webpack": "^4.35.2", "webpack": "^4.35.2",
"worker-loader": "^2.0.0" "worker-loader": "^2.0.0"
} }
......
const common = {
/**
* fetch请求封装
* @param {*} action 请求线上地址
* @param {*} params 请求入参
* @param {*} method 请求方式,默认get
* @param {*} options 其他参数
* options为对象格式,值:
* isLoading(是否激活请求加载动画)
* isJson(是否设置post请求头contentType为application/json)
* content 自定义请求参数
*/
fetch(action, params = {}, method = 'get', options = {}) {
const token = utils.getCookie('token');
const XCsrfToken = utils.getCookie('csrf_token');
let url = action;
let option = {
method,
credentials: 'same-origin',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
'token': token,
'X-Csrf-Token': XCsrfToken
}
};
if (options && options.content) {
option = Object.assign({}, option, options.content);
}
if (method === 'post') {
if (options && options.isJson) {
option.body = JSON.stringify(params);
} else {
option = Object.assign({}, option, {
headers: {
Accept: 'application/json,text/plain,*/*',
'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8',
'token': token,
'X-Csrf-Token': XCsrfToken
}
});
option.body = utils.serialize(params);
}
}
if (method === 'get') {
url = Object.keys(params).length ? url + '?' + utils.serialize(params) : url;
}
}
}
export default common;
\ No newline at end of file
...@@ -3,20 +3,31 @@ import TracksWorker from "./tracks.worker"; ...@@ -3,20 +3,31 @@ import TracksWorker from "./tracks.worker";
export default class Monitor { export default class Monitor {
rrwebHandler = null; rrwebHandler = null;
tracksWorker = new TracksWorker(); tracksWorker = new TracksWorker();
// 记录
record() { record() {
this.rrwebHandler && this.rrwebHandler(); this.rrwebHandler && this.rrwebHandler();
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", event });
}, }
}); });
} }
// 停止
stop() { stop() {
if (!this.rrwebHandler) { if (!this.rrwebHandler) {
throw new Error("没有正在录制的实例"); throw new Error("没有正在录制的实例");
} }
console.log('停止录制')
this.rrwebHandler(); this.rrwebHandler();
} }
// 重置
reset(event) {
this.rrwebHandler && this.rrwebHandler();
console.log('重置数据')
this.tracksWorker.postMessage({ type: "reset", event });
}
// 发送信息
postMessage(action) { postMessage(action) {
this.tracksWorker.postMessage(action); this.tracksWorker.postMessage(action);
} }
......
import md5 from 'md5';
import utils from './utils';
import _ from 'lodash';
// 原始数据数组
let events = []; let events = [];
// 包装后的数据对象
let wrapEvents = [];
// 分条视频id
let recordKey = '';
// 全量快照是否已经返回
let isCdnReturn = false;
onmessage = ({ data: { type, event } }) => { onmessage = ({ data: { type, event } }) => {
switch (type) { switch (type) {
case "record": case "record":
// todo : 根据事件类型优先级触发上传策略 // todo : 数据本地存储
wrapEvents.push(utils.dataWrapper({
recordKey,
isCdn: false
}, event));
events.push(event);
// todo : 全量快照上传cdn // todo : 全量快照上传cdn
if(event.type === 2) {
const cdnIndex = _.findIndex(events, { 'type': 2 });
setTimeout(() => {
wrapEvents.splice(cdnIndex, 1, utils.dataWrapper({
recordKey,
isCdn: true
}, event));
isCdnReturn = true;
}, 1000);
}
// todo : 数据压缩 // todo : 数据压缩
events.push(event); // todo : 根据事件类型优先级触发上传策略(click)
console.log(events); if(event.data.source === 2 && isCdnReturn) {
if (events.length > 100) { console.log('点击上上传events', wrapEvents);
window.localStorage.setItem("rrevents", JSON.stringify(events));
events = []; events = [];
console.log("local"); wrapEvents = [];
}
// todo : 数据超出100条上线,自动上传
if (wrapEvents.length > 100 && isCdnReturn) {
console.log('超出线上100条上传events', wrapEvents)
events = [];
wrapEvents = [];
} }
break; break;
case "reset": case "reset":
// todo : 重新生成recordKey // todo : 重置参数,重新生成recordKey
events = [];
wrapEvents = [];
recordKey = '';
isCdnReture = false;
const { url, email } = event;
recordKey = md5(url + email + Date.parse(new Date()));
console.log(url, '分片id', recordKey);
break; break;
default: default:
console.log("unknow action"); console.log("unknow action");
......
const utils = {
// 包装event
dataWrapper(extraData, event) {
return {
...extraData,
event
}
},
// 获取token
getCookie(name) {
const regexp = new RegExp('(^| )' + name + '=([^;]*)(;|$)');
const matches = regexp.exec(document.cookie);
return matches ? matches[2] : null;
},
// 拼接URL请求参数
serialize(obj) {
const str = [];
for (let p in obj) {
if (obj.hasOwnProperty(p)) {
str.push(encodeURIComponent(p) + '=' + encodeURIComponent(this.isNothing(obj[p]) ? '' : obj[p]));
}
}
return str.join('&');
},
}
export default utils;
\ No newline at end of file
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