Commit e1c89f6a authored by aiduck's avatar aiduck

20190722

parent 319ad83b
......@@ -1486,6 +1486,12 @@
"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": {
"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",
......@@ -1727,6 +1733,35 @@
"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": {
"version": "3.12.0",
"resolved": "http://registry.npm.taobao.org/crypto-browserify/download/crypto-browserify-3.12.0.tgz",
......@@ -2241,8 +2276,7 @@
"ansi-regex": {
"version": "2.1.1",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"aproba": {
"version": "1.2.0",
......@@ -2263,14 +2297,12 @@
"balanced-match": {
"version": "1.0.0",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"brace-expansion": {
"version": "1.1.11",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
......@@ -2285,20 +2317,17 @@
"code-point-at": {
"version": "1.1.0",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"concat-map": {
"version": "0.0.1",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"console-control-strings": {
"version": "1.1.0",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"core-util-is": {
"version": "1.0.2",
......@@ -2415,8 +2444,7 @@
"inherits": {
"version": "2.0.3",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"ini": {
"version": "1.3.5",
......@@ -2428,7 +2456,6 @@
"version": "1.0.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"number-is-nan": "^1.0.0"
}
......@@ -2443,7 +2470,6 @@
"version": "3.0.4",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"brace-expansion": "^1.1.7"
}
......@@ -2451,14 +2477,12 @@
"minimist": {
"version": "0.0.8",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"minipass": {
"version": "2.3.5",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"safe-buffer": "^5.1.2",
"yallist": "^3.0.0"
......@@ -2477,7 +2501,6 @@
"version": "0.5.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"minimist": "0.0.8"
}
......@@ -2558,8 +2581,7 @@
"number-is-nan": {
"version": "1.0.1",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"object-assign": {
"version": "4.1.1",
......@@ -2571,7 +2593,6 @@
"version": "1.4.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"wrappy": "1"
}
......@@ -2657,8 +2678,7 @@
"safe-buffer": {
"version": "5.1.2",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"safer-buffer": {
"version": "2.1.2",
......@@ -2694,7 +2714,6 @@
"version": "1.0.2",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",
......@@ -2714,7 +2733,6 @@
"version": "3.0.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"ansi-regex": "^2.0.0"
}
......@@ -2758,14 +2776,12 @@
"wrappy": {
"version": "1.0.2",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"yallist": {
"version": "3.0.3",
"bundled": true,
"dev": true,
"optional": true
"dev": true
}
}
},
......@@ -3094,6 +3110,12 @@
"integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=",
"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": {
"version": "3.0.1",
"resolved": "https://registry.npm.taobao.org/isobject/download/isobject-3.0.1.tgz",
......@@ -3184,10 +3206,9 @@
}
},
"lodash": {
"version": "4.17.14",
"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",
"integrity": "sha1-nOSHrmbJYlT+ILWZ8htoFgKAeLo=",
"dev": true
"version": "4.17.15",
"resolved": "https://registry.npm.taobao.org/lodash/download/lodash-4.17.15.tgz",
"integrity": "sha1-tEf2ZwoEVbv+7dETku/zMOoJdUg="
},
"loose-envify": {
"version": "1.4.0",
......@@ -3238,6 +3259,17 @@
"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": {
"version": "1.3.5",
"resolved": "http://registry.npm.taobao.org/md5.js/download/md5.js-1.3.5.tgz",
......@@ -3430,6 +3462,12 @@
"integrity": "sha1-rCetpmFn+ohJpq3dg39rGJrSCBw=",
"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": {
"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",
......@@ -3657,6 +3695,12 @@
"integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=",
"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": {
"version": "1.0.6",
"resolved": "http://registry.npm.taobao.org/path-parse/download/path-parse-1.0.6.tgz",
......@@ -4074,6 +4118,21 @@
"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": {
"version": "0.4.4",
"resolved": "https://registry.npm.taobao.org/smoothscroll-polyfill/download/smoothscroll-polyfill-0.4.4.tgz",
......@@ -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": {
"version": "1.7.0",
"resolved": "https://registry.npm.taobao.org/worker-farm/download/worker-farm-1.7.0.tgz",
......
......@@ -22,6 +22,7 @@
"author": "Dec-F",
"license": "ISC",
"dependencies": {
"lodash": "^4.17.15",
"rrweb": "^0.7.18"
},
"devDependencies": {
......@@ -31,6 +32,7 @@
"@babel/preset-env": "^7.4.5",
"babel-loader": "^8.0.6",
"cross-env": "^5.2.0",
"md5": "^2.2.1",
"webpack": "^4.35.2",
"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";
export default class Monitor {
rrwebHandler = null;
tracksWorker = new TracksWorker();
// 记录
record() {
this.rrwebHandler && this.rrwebHandler();
console.log('开始录制')
this.rrwebHandler = rrweb.record({
emit: event => {
this.tracksWorker.postMessage({ type: "record", event });
},
}
});
}
// 停止
stop() {
if (!this.rrwebHandler) {
throw new Error("没有正在录制的实例");
}
console.log('停止录制')
this.rrwebHandler();
}
// 重置
reset(event) {
this.rrwebHandler && this.rrwebHandler();
console.log('重置数据')
this.tracksWorker.postMessage({ type: "reset", event });
}
// 发送信息
postMessage(action) {
this.tracksWorker.postMessage(action);
}
......
import md5 from 'md5';
import utils from './utils';
import _ from 'lodash';
// 原始数据数组
let events = [];
// 包装后的数据对象
let wrapEvents = [];
// 分条视频id
let recordKey = '';
// 全量快照是否已经返回
let isCdnReturn = false;
onmessage = ({ data: { type, event } }) => {
switch (type) {
case "record":
// todo : 根据事件类型优先级触发上传策略
// todo : 数据本地存储
wrapEvents.push(utils.dataWrapper({
recordKey,
isCdn: false
}, event));
events.push(event);
// 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 : 数据压缩
events.push(event);
console.log(events);
if (events.length > 100) {
window.localStorage.setItem("rrevents", JSON.stringify(events));
// todo : 根据事件类型优先级触发上传策略(click)
if(event.data.source === 2 && isCdnReturn) {
console.log('点击上上传events', wrapEvents);
events = [];
console.log("local");
wrapEvents = [];
}
// todo : 数据超出100条上线,自动上传
if (wrapEvents.length > 100 && isCdnReturn) {
console.log('超出线上100条上传events', wrapEvents)
events = [];
wrapEvents = [];
}
break;
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;
default:
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