@arms/rum-reactnative 0.0.2-bate.1 → 0.0.2-bate.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -20
- package/package.json +6 -7
- package/RumSdkReactnative.podspec +0 -21
- package/android/build.gradle +0 -77
- package/android/gradle.properties +0 -5
- package/android/src/main/AndroidManifest.xml +0 -2
- package/android/src/main/java/com/rumsdkreactnative/RumSdkReactnativeModule.kt +0 -23
- package/android/src/main/java/com/rumsdkreactnative/RumSdkReactnativePackage.kt +0 -33
- package/ios/RumSdkReactnative.h +0 -5
- package/ios/RumSdkReactnative.mm +0 -18
- package/src/collector/action/index.ts +0 -67
- package/src/collector/exception/index.ts +0 -158
- package/src/collector/resource/api.ts +0 -379
- package/src/collector/view/perf.ts +0 -77
- package/src/collector/view/pv.ts +0 -73
- package/src/index.ts +0 -4
- package/src/plugin.ts +0 -41
- package/src/processor/default-processor.ts +0 -22
- package/src/processor/session-processor.ts +0 -23
- package/src/reporter/index.ts +0 -67
- package/src/shell.ts +0 -81
- package/src/types/client.ts +0 -32
- package/src/types/index.ts +0 -159
- package/src/utils/api.ts +0 -119
- package/src/utils/base.ts +0 -92
- package/src/utils/platform.ts +0 -107
- package/src/utils/session.ts +0 -168
- package/src/utils/url.ts +0 -53
- package/src/utils/view.ts +0 -93
package/src/utils/session.ts
DELETED
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
generateEventId,
|
|
3
|
-
generateGUID,
|
|
4
|
-
generateSpanId,
|
|
5
|
-
IContext,
|
|
6
|
-
IRumSession,
|
|
7
|
-
isNumber,
|
|
8
|
-
ONE_DAY,
|
|
9
|
-
ONE_HOUR,
|
|
10
|
-
ONE_MINUTE,
|
|
11
|
-
performDraw,
|
|
12
|
-
SessionConfig,
|
|
13
|
-
} from '@arms/rum-core';
|
|
14
|
-
import { getCurrentTime } from './base';
|
|
15
|
-
import { getCurView } from './view';
|
|
16
|
-
import { getStorage, setStorage } from './platform';
|
|
17
|
-
|
|
18
|
-
// 存储userID的键名
|
|
19
|
-
const USER_ID = '_arms_uid';
|
|
20
|
-
// 存储session
|
|
21
|
-
// const RUM_SESSION = '_arms_session';
|
|
22
|
-
|
|
23
|
-
interface SessionInfo {
|
|
24
|
-
sessionId: string;
|
|
25
|
-
sampled: boolean;
|
|
26
|
-
startTime: number;
|
|
27
|
-
lastTime: number;
|
|
28
|
-
isNew?: boolean;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export class RumSession implements IRumSession {
|
|
32
|
-
ctx?: IContext;
|
|
33
|
-
|
|
34
|
-
// @ts-ignore
|
|
35
|
-
sessionConfig: SessionConfig;
|
|
36
|
-
|
|
37
|
-
// private sessionId = '';
|
|
38
|
-
|
|
39
|
-
private session = '';
|
|
40
|
-
|
|
41
|
-
private userId = '';
|
|
42
|
-
|
|
43
|
-
constructor() {
|
|
44
|
-
this.initUser();
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
init(ctx: IContext) {
|
|
48
|
-
this.ctx = ctx;
|
|
49
|
-
this.sessionConfig = this.fixSessionConfig(ctx.config?.sessionConfig);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
getSessionId() {
|
|
53
|
-
return this.getSessionInfo().sessionId;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
getSampled() {
|
|
57
|
-
return this.getSessionInfo().sampled;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
checkSession(info: SessionInfo) {
|
|
61
|
-
const { overtime = 0, maxDuration = 0 } = this.sessionConfig;
|
|
62
|
-
const now = getCurrentTime();
|
|
63
|
-
return !(
|
|
64
|
-
info.startTime + maxDuration < now || info.lastTime + overtime < now
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
updateSession() {
|
|
69
|
-
const info = this.getSessionInfo();
|
|
70
|
-
if (info.isNew) {
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
const startTime = info.startTime;
|
|
74
|
-
const lastTime = getCurrentTime();
|
|
75
|
-
const sampled = info.sampled ? 1 : 0;
|
|
76
|
-
this.session = `${info.sessionId}-${sampled}-${startTime}-${lastTime}`;
|
|
77
|
-
// setStorage(RUM_SESSION, `${info.sessionId}-${sampled}-${startTime}-${lastTime}`)
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
getSessionInfo() {
|
|
81
|
-
const [sid, sampled, startTime, lastTime] = this.session.split('-');
|
|
82
|
-
let info: SessionInfo = {
|
|
83
|
-
sessionId: sid as string,
|
|
84
|
-
sampled: sampled !== '0',
|
|
85
|
-
startTime: parseInt(startTime || '') || 0,
|
|
86
|
-
lastTime: parseInt(lastTime || '') || 0,
|
|
87
|
-
};
|
|
88
|
-
if (!this.checkSession(info)) {
|
|
89
|
-
info = this.resetSession();
|
|
90
|
-
}
|
|
91
|
-
return info;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
getEventId() {
|
|
95
|
-
const sid = this.getSessionId();
|
|
96
|
-
return generateEventId(sid);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
getViewId() {
|
|
100
|
-
return this.getUUID();
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
async initUser() {
|
|
104
|
-
this.userId = (await getStorage(USER_ID)) as string;
|
|
105
|
-
if (!this.userId) {
|
|
106
|
-
this.userId = `uid_${generateSpanId(16, 36)}`;
|
|
107
|
-
await setStorage(USER_ID, this.userId);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
getUserId() {
|
|
112
|
-
return this.userId;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
private resetSession() {
|
|
116
|
-
const { sampleRate = 1 } = this.sessionConfig;
|
|
117
|
-
const sid = this.getUUID();
|
|
118
|
-
const now = getCurrentTime();
|
|
119
|
-
const sampled = performDraw(sampleRate * 100);
|
|
120
|
-
this.session = `${sid}-${sampled ? 1 : 0}-${now}-${now}`;
|
|
121
|
-
// setStorage(RUM_SESSION, this.session);
|
|
122
|
-
return {
|
|
123
|
-
sessionId: sid,
|
|
124
|
-
sampled: sampled,
|
|
125
|
-
startTime: now,
|
|
126
|
-
lastTime: now,
|
|
127
|
-
isNew: true,
|
|
128
|
-
} as SessionInfo;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
private getUUID() {
|
|
132
|
-
return generateGUID().replace(/-/g, '');
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
fixSessionConfig(sessionConfig: SessionConfig = {}): SessionConfig {
|
|
136
|
-
let { sampleRate, maxDuration, overtime } = sessionConfig;
|
|
137
|
-
if (!isNumber(sampleRate) || sampleRate < 0 || sampleRate > 1) {
|
|
138
|
-
sampleRate = 1;
|
|
139
|
-
}
|
|
140
|
-
if (
|
|
141
|
-
!isNumber(maxDuration) ||
|
|
142
|
-
maxDuration < 4 * ONE_HOUR ||
|
|
143
|
-
maxDuration > ONE_DAY
|
|
144
|
-
) {
|
|
145
|
-
maxDuration = ONE_DAY;
|
|
146
|
-
}
|
|
147
|
-
if (
|
|
148
|
-
!isNumber(overtime) ||
|
|
149
|
-
overtime > ONE_HOUR ||
|
|
150
|
-
overtime < 10 * ONE_MINUTE
|
|
151
|
-
) {
|
|
152
|
-
overtime = 30 * ONE_MINUTE;
|
|
153
|
-
}
|
|
154
|
-
return { sampleRate, maxDuration, overtime };
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
getBaseEvent() {
|
|
158
|
-
const session_id = this.getSessionId();
|
|
159
|
-
const event_id = this.getEventId();
|
|
160
|
-
return {
|
|
161
|
-
timestamp: getCurrentTime(),
|
|
162
|
-
session_id,
|
|
163
|
-
event_id,
|
|
164
|
-
view: this.ctx ? getCurView(this.ctx) : undefined,
|
|
165
|
-
times: 1,
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
}
|
package/src/utils/url.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* 根据指定 URL 获取视图的名称,默认为其path部分
|
|
4
|
-
* @param url 需要提取路径部分的 URL
|
|
5
|
-
* @param isHash 是否为 hash 模式路由的 URL
|
|
6
|
-
*/
|
|
7
|
-
export function getPathByURL(url: string, isHash = false) {
|
|
8
|
-
try {
|
|
9
|
-
const urlObj = getURL(url);
|
|
10
|
-
if (!urlObj) return;
|
|
11
|
-
if (isHash) {
|
|
12
|
-
return urlObj.hash;
|
|
13
|
-
} else {
|
|
14
|
-
return urlObj.pathname;
|
|
15
|
-
}
|
|
16
|
-
} catch (error) {
|
|
17
|
-
return '';
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// /**
|
|
22
|
-
// * 检查是否为上报域名
|
|
23
|
-
// * @param ctx
|
|
24
|
-
// * @param url 需要提取路径部分的 URL
|
|
25
|
-
// */
|
|
26
|
-
// export function isEndpoint(ctx: IContext, url: string): boolean {
|
|
27
|
-
// const { endpoint } = ctx.getConfig();
|
|
28
|
-
// try {
|
|
29
|
-
// return getURL(url).hostname === getURL(endpoint).hostname
|
|
30
|
-
// } catch (e) {
|
|
31
|
-
// return false;
|
|
32
|
-
// }
|
|
33
|
-
// }
|
|
34
|
-
|
|
35
|
-
const REGEX = /^(?:([^:\/?#]+):\/\/)?((?:([^\/?#@]*)@)?([^\/?#:]*)(?:\:(\d*))?)?([^?#]*)(?:\?([^#]*))?(?:#((?:.|\n)*))?/i
|
|
36
|
-
|
|
37
|
-
export function getURL(url: string) {
|
|
38
|
-
const parts = decodeURIComponent(url).match(REGEX);
|
|
39
|
-
if (!parts) return null;
|
|
40
|
-
const auth = (parts[3] || '').split(':');
|
|
41
|
-
const host = auth.length ? (parts[2] || '').replace(/(.*\@)/, '') : parts[2];
|
|
42
|
-
return {
|
|
43
|
-
uri: parts[0],
|
|
44
|
-
protocol: parts[1],
|
|
45
|
-
host: host,
|
|
46
|
-
hostname: parts[4],
|
|
47
|
-
port: parts[5],
|
|
48
|
-
pathname: parts[6],
|
|
49
|
-
search: parts[7],
|
|
50
|
-
// query: mapSearchParams(parts[7]),
|
|
51
|
-
hash: parts[8]
|
|
52
|
-
}
|
|
53
|
-
}
|
package/src/utils/view.ts
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
IContext,
|
|
3
|
-
isFunction,
|
|
4
|
-
// IRumSession,
|
|
5
|
-
// IViewData
|
|
6
|
-
} from '@arms/rum-core';
|
|
7
|
-
import { NavigationContainerRef, NavigationListener } from '../types'
|
|
8
|
-
// import { IPage } from "../types/client";
|
|
9
|
-
|
|
10
|
-
// export const PAGE_ID = '__rum_view_id';
|
|
11
|
-
//
|
|
12
|
-
// /**
|
|
13
|
-
// * 获取 RUM 内置的view_id标识
|
|
14
|
-
// * @param page
|
|
15
|
-
// * @param session
|
|
16
|
-
// * @returns
|
|
17
|
-
// */
|
|
18
|
-
// export async function getRumViewId(page: IPage, session?: IRumSession): Promise<string> {
|
|
19
|
-
// if (!page) return;
|
|
20
|
-
// if (page.id) {
|
|
21
|
-
// return page.id;
|
|
22
|
-
// }
|
|
23
|
-
// if (!session) return;
|
|
24
|
-
// return page.id = session.getViewId();
|
|
25
|
-
// }
|
|
26
|
-
//
|
|
27
|
-
// /**
|
|
28
|
-
// * 获取当前 view
|
|
29
|
-
// * @param viewId
|
|
30
|
-
// * @param ctx
|
|
31
|
-
// * @returns
|
|
32
|
-
// */
|
|
33
|
-
// export function getViewById(viewId: string, ctx: IContext): IViewData {
|
|
34
|
-
// if (!viewId || !ctx) return;
|
|
35
|
-
// return ctx.getViews().find(view => view.id === viewId);
|
|
36
|
-
// }
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* 获取当前 view
|
|
40
|
-
* @param ctx
|
|
41
|
-
* @returns
|
|
42
|
-
*/
|
|
43
|
-
export function getCurView(ctx: IContext) {
|
|
44
|
-
if (!ctx) return;
|
|
45
|
-
const views = ctx.getViews();
|
|
46
|
-
if (views && views.length) {
|
|
47
|
-
return views[views.length - 1];
|
|
48
|
-
}
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
let currentNavigationRef: NavigationContainerRef | undefined;
|
|
53
|
-
const navigateListeners: NavigationListener[] = [];
|
|
54
|
-
|
|
55
|
-
export function addNavigateListener(listener: NavigationListener) {
|
|
56
|
-
if (isFunction(listener)) {
|
|
57
|
-
navigateListeners.push(listener);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export function removeNavigateListener(listener: NavigationListener) {
|
|
62
|
-
navigateListeners.splice(navigateListeners.indexOf(listener), 1);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function triggerNavigateChange(event: any) {
|
|
66
|
-
if (!currentNavigationRef) return;
|
|
67
|
-
let route = event;
|
|
68
|
-
if (isFunction(currentNavigationRef.getCurrentRoute)) {
|
|
69
|
-
route = currentNavigationRef.getCurrentRoute();
|
|
70
|
-
}
|
|
71
|
-
if (!route) return;
|
|
72
|
-
navigateListeners.forEach(listener => {
|
|
73
|
-
listener(route);
|
|
74
|
-
})
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export function startTrackingViews(nav: any) {
|
|
78
|
-
if (!nav || currentNavigationRef) return;
|
|
79
|
-
if (isFunction(nav.events)) {
|
|
80
|
-
// react-native-navigation
|
|
81
|
-
nav.events().registerComponentDidAppearListener(triggerNavigateChange)
|
|
82
|
-
} else {
|
|
83
|
-
// @react-native/navigation
|
|
84
|
-
nav.addListener('state', triggerNavigateChange)
|
|
85
|
-
}
|
|
86
|
-
currentNavigationRef = nav;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export function stopTrackingViews() {
|
|
90
|
-
if (!currentNavigationRef) return;
|
|
91
|
-
currentNavigationRef.removeListener('state', triggerNavigateChange)
|
|
92
|
-
currentNavigationRef = undefined;
|
|
93
|
-
}
|