@multiplayer-app/session-recorder-react-native 0.0.1-alpha.1 → 0.0.1-alpha.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/dist/config/constants.d.ts +19 -0
- package/dist/config/constants.js +1 -0
- package/dist/config/constants.js.map +1 -0
- package/dist/config/defaults.d.ts +4 -0
- package/dist/config/defaults.js +1 -0
- package/dist/config/defaults.js.map +1 -0
- package/dist/config/index.d.ts +5 -0
- package/dist/config/index.js +1 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/masking.d.ts +2 -30
- package/dist/config/masking.js +1 -1
- package/dist/config/masking.js.map +1 -1
- package/dist/config/session-recorder.d.ts +2 -0
- package/dist/config/session-recorder.js +1 -0
- package/dist/config/session-recorder.js.map +1 -0
- package/dist/config/validators.d.ts +10 -0
- package/dist/config/validators.js +1 -0
- package/dist/config/validators.js.map +1 -0
- package/dist/expo.d.ts +2 -2
- package/dist/expo.js +1 -1
- package/dist/expo.js.map +1 -1
- package/dist/exporters.d.ts +3 -0
- package/dist/exporters.js +1 -0
- package/dist/exporters.js.map +1 -0
- package/dist/index.d.ts +3 -9
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/otel/helpers.d.ts +45 -3
- package/dist/otel/helpers.js +1 -1
- package/dist/otel/helpers.js.map +1 -1
- package/dist/otel/index.d.ts +9 -5
- package/dist/otel/index.js +1 -1
- package/dist/otel/index.js.map +1 -1
- package/dist/otel/instrumentations/index.js +1 -1
- package/dist/otel/instrumentations/index.js.map +1 -1
- package/dist/patch/index.d.ts +1 -0
- package/dist/patch/index.js +1 -0
- package/dist/patch/index.js.map +1 -0
- package/dist/patch/xhr.d.ts +2 -0
- package/dist/patch/xhr.js +1 -0
- package/dist/patch/xhr.js.map +1 -0
- package/dist/recorder/gestureRecorder.js +1 -1
- package/dist/recorder/gestureRecorder.js.map +1 -1
- package/dist/recorder/navigationTracker.js +1 -1
- package/dist/recorder/navigationTracker.js.map +1 -1
- package/dist/recorder/screenRecorder.d.ts +1 -0
- package/dist/recorder/screenRecorder.js +1 -1
- package/dist/recorder/screenRecorder.js.map +1 -1
- package/dist/services/api.service.d.ts +62 -10
- package/dist/services/api.service.js +1 -1
- package/dist/services/api.service.js.map +1 -1
- package/dist/services/storage.service.d.ts +23 -16
- package/dist/services/storage.service.js +1 -1
- package/dist/services/storage.service.js.map +1 -1
- package/dist/session-recorder.d.ts +131 -0
- package/dist/session-recorder.js +1 -0
- package/dist/session-recorder.js.map +1 -0
- package/dist/sessionRecorder.d.ts +113 -34
- package/dist/sessionRecorder.js +1 -1
- package/dist/sessionRecorder.js.map +1 -1
- package/dist/types/index.d.ts +2 -81
- package/dist/types/index.js +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/types/session-recorder.d.ts +366 -0
- package/dist/types/session-recorder.js +1 -0
- package/dist/types/session-recorder.js.map +1 -0
- package/dist/types/session.d.ts +59 -0
- package/dist/types/session.js +1 -0
- package/dist/types/session.js.map +1 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/platform.d.ts +5 -0
- package/dist/utils/platform.js +1 -1
- package/dist/utils/platform.js.map +1 -1
- package/dist/utils/request-utils.d.ts +21 -0
- package/dist/utils/request-utils.js +1 -0
- package/dist/utils/request-utils.js.map +1 -0
- package/dist/utils/session.d.ts +5 -0
- package/dist/utils/session.js +1 -0
- package/dist/utils/session.js.map +1 -0
- package/dist/utils/time.d.ts +4 -0
- package/dist/utils/time.js +1 -0
- package/dist/utils/time.js.map +1 -0
- package/dist/utils/type-utils.d.ts +16 -0
- package/dist/utils/type-utils.js +1 -0
- package/dist/utils/type-utils.js.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -3
- package/src/config/constants.ts +60 -0
- package/src/config/defaults.ts +82 -0
- package/src/config/index.ts +6 -0
- package/src/config/masking.ts +10 -61
- package/src/config/session-recorder.ts +55 -0
- package/src/config/validators.ts +31 -0
- package/src/expo.ts +2 -22
- package/src/index.ts +3 -15
- package/src/otel/helpers.ts +247 -11
- package/src/otel/index.ts +109 -76
- package/src/otel/instrumentations/index.ts +8 -8
- package/src/patch/index.ts +1 -0
- package/src/patch/xhr.ts +142 -0
- package/src/recorder/gestureRecorder.ts +12 -12
- package/src/recorder/navigationTracker.ts +10 -10
- package/src/recorder/screenRecorder.ts +26 -26
- package/src/services/api.service.ts +169 -37
- package/src/services/storage.service.ts +101 -74
- package/src/session-recorder.ts +570 -0
- package/src/types/index.ts +2 -88
- package/src/types/session-recorder.ts +423 -0
- package/src/types/session.ts +65 -0
- package/src/utils/index.ts +6 -0
- package/src/utils/platform.ts +13 -0
- package/src/utils/request-utils.ts +61 -0
- package/src/utils/session.ts +18 -0
- package/src/utils/time.ts +17 -0
- package/src/utils/type-utils.ts +75 -0
- package/src/version.ts +1 -1
- package/examples/sample-expo-app/README.md +0 -142
- package/examples/sample-expo-app/app/(tabs)/_layout.tsx +0 -60
- package/examples/sample-expo-app/app/(tabs)/explore.tsx +0 -110
- package/examples/sample-expo-app/app/(tabs)/index.tsx +0 -125
- package/examples/sample-expo-app/app/(tabs)/posts.tsx +0 -96
- package/examples/sample-expo-app/app/(tabs)/users.tsx +0 -131
- package/examples/sample-expo-app/app/+not-found.tsx +0 -32
- package/examples/sample-expo-app/app/_layout.tsx +0 -53
- package/examples/sample-expo-app/app/post/[id].tsx +0 -199
- package/examples/sample-expo-app/app/user/[id].tsx +0 -270
- package/examples/sample-expo-app/app.json +0 -42
- package/examples/sample-expo-app/assets/fonts/SpaceMono-Regular.ttf +0 -0
- package/examples/sample-expo-app/assets/images/adaptive-icon.png +0 -0
- package/examples/sample-expo-app/assets/images/favicon.png +0 -0
- package/examples/sample-expo-app/assets/images/icon.png +0 -0
- package/examples/sample-expo-app/assets/images/partial-react-logo.png +0 -0
- package/examples/sample-expo-app/assets/images/react-logo.png +0 -0
- package/examples/sample-expo-app/assets/images/react-logo@2x.png +0 -0
- package/examples/sample-expo-app/assets/images/react-logo@3x.png +0 -0
- package/examples/sample-expo-app/assets/images/splash-icon.png +0 -0
- package/examples/sample-expo-app/components/Collapsible.tsx +0 -45
- package/examples/sample-expo-app/components/ErrorView.tsx +0 -52
- package/examples/sample-expo-app/components/ExternalLink.tsx +0 -24
- package/examples/sample-expo-app/components/HapticTab.tsx +0 -18
- package/examples/sample-expo-app/components/HelloWave.tsx +0 -40
- package/examples/sample-expo-app/components/LoadingSpinner.tsx +0 -34
- package/examples/sample-expo-app/components/ParallaxScrollView.tsx +0 -82
- package/examples/sample-expo-app/components/ThemedText.tsx +0 -60
- package/examples/sample-expo-app/components/ThemedView.tsx +0 -14
- package/examples/sample-expo-app/components/ui/IconSymbol.ios.tsx +0 -32
- package/examples/sample-expo-app/components/ui/IconSymbol.tsx +0 -41
- package/examples/sample-expo-app/components/ui/TabBarBackground.ios.tsx +0 -19
- package/examples/sample-expo-app/components/ui/TabBarBackground.tsx +0 -6
- package/examples/sample-expo-app/constants/Colors.ts +0 -26
- package/examples/sample-expo-app/eslint.config.js +0 -10
- package/examples/sample-expo-app/hooks/useApi.ts +0 -41
- package/examples/sample-expo-app/hooks/useColorScheme.ts +0 -1
- package/examples/sample-expo-app/hooks/useColorScheme.web.ts +0 -21
- package/examples/sample-expo-app/hooks/useThemeColor.ts +0 -21
- package/examples/sample-expo-app/metro.config.js +0 -26
- package/examples/sample-expo-app/package-lock.json +0 -26296
- package/examples/sample-expo-app/package.json +0 -59
- package/examples/sample-expo-app/scripts/reset-project.js +0 -112
- package/examples/sample-expo-app/services/api.ts +0 -98
- package/examples/sample-expo-app/tsconfig.json +0 -17
- package/examples/sample-expo-app/utils/navigation.ts +0 -19
- package/src/sessionRecorder.ts +0 -367
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "sample-expo-app",
|
|
3
|
-
"main": "expo-router/entry",
|
|
4
|
-
"version": "1.0.0",
|
|
5
|
-
"scripts": {
|
|
6
|
-
"start": "expo start",
|
|
7
|
-
"reset-project": "node ./scripts/reset-project.js",
|
|
8
|
-
"android": "expo start --android",
|
|
9
|
-
"ios": "expo start --ios",
|
|
10
|
-
"web": "expo start --web",
|
|
11
|
-
"lint": "expo lint",
|
|
12
|
-
"postinstall": "expo-yarn-workspaces check workspaces"
|
|
13
|
-
},
|
|
14
|
-
"dependencies": {
|
|
15
|
-
"@expo/vector-icons": "^14.1.0",
|
|
16
|
-
"@multiplayer-app/session-recorder-react-native": "file:../..",
|
|
17
|
-
"@react-native-async-storage/async-storage": "2.1.2",
|
|
18
|
-
"@react-native-community/netinfo": "^11.1.0",
|
|
19
|
-
"@react-navigation/bottom-tabs": "^7.3.10",
|
|
20
|
-
"@react-navigation/elements": "^2.3.8",
|
|
21
|
-
"@react-navigation/native": "^7.1.6",
|
|
22
|
-
"axios": "^1.6.0",
|
|
23
|
-
"expo": "~53.0.22",
|
|
24
|
-
"expo-blur": "~14.1.5",
|
|
25
|
-
"expo-constants": "~17.1.7",
|
|
26
|
-
"expo-font": "~13.3.2",
|
|
27
|
-
"expo-haptics": "~14.1.4",
|
|
28
|
-
"expo-image": "~2.4.0",
|
|
29
|
-
"expo-linking": "~7.1.7",
|
|
30
|
-
"expo-router": "~5.1.5",
|
|
31
|
-
"expo-splash-screen": "~0.30.10",
|
|
32
|
-
"expo-status-bar": "~2.2.3",
|
|
33
|
-
"expo-symbols": "~0.4.5",
|
|
34
|
-
"expo-system-ui": "~5.0.11",
|
|
35
|
-
"expo-web-browser": "~14.2.0",
|
|
36
|
-
"react": "19.0.0",
|
|
37
|
-
"react-dom": "19.0.0",
|
|
38
|
-
"react-native": "^0.79.5",
|
|
39
|
-
"react-native-gesture-handler": "~2.24.0",
|
|
40
|
-
"react-native-mmkv": "^2.11.0",
|
|
41
|
-
"react-native-reanimated": "~3.17.4",
|
|
42
|
-
"react-native-safe-area-context": "5.4.0",
|
|
43
|
-
"react-native-screens": "~4.11.1",
|
|
44
|
-
"react-native-screenshot": "^1.0.0",
|
|
45
|
-
"react-native-view-shot": "^4.0.3",
|
|
46
|
-
"react-native-web": "~0.20.0",
|
|
47
|
-
"react-native-webview": "13.13.5"
|
|
48
|
-
},
|
|
49
|
-
"devDependencies": {
|
|
50
|
-
"@babel/core": "^7.25.2",
|
|
51
|
-
"@react-native/metro-config": "^0.81.1",
|
|
52
|
-
"@types/react": "~19.0.10",
|
|
53
|
-
"eslint": "^9.25.0",
|
|
54
|
-
"eslint-config-expo": "~9.2.0",
|
|
55
|
-
"expo-yarn-workspaces": "^2.3.2",
|
|
56
|
-
"typescript": "~5.8.3"
|
|
57
|
-
},
|
|
58
|
-
"private": true
|
|
59
|
-
}
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* This script is used to reset the project to a blank state.
|
|
5
|
-
* It deletes or moves the /app, /components, /hooks, /scripts, and /constants directories to /app-example based on user input and creates a new /app directory with an index.tsx and _layout.tsx file.
|
|
6
|
-
* You can remove the `reset-project` script from package.json and safely delete this file after running it.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
const fs = require("fs");
|
|
10
|
-
const path = require("path");
|
|
11
|
-
const readline = require("readline");
|
|
12
|
-
|
|
13
|
-
const root = process.cwd();
|
|
14
|
-
const oldDirs = ["app", "components", "hooks", "constants", "scripts"];
|
|
15
|
-
const exampleDir = "app-example";
|
|
16
|
-
const newAppDir = "app";
|
|
17
|
-
const exampleDirPath = path.join(root, exampleDir);
|
|
18
|
-
|
|
19
|
-
const indexContent = `import { Text, View } from "react-native";
|
|
20
|
-
|
|
21
|
-
export default function Index() {
|
|
22
|
-
return (
|
|
23
|
-
<View
|
|
24
|
-
style={{
|
|
25
|
-
flex: 1,
|
|
26
|
-
justifyContent: "center",
|
|
27
|
-
alignItems: "center",
|
|
28
|
-
}}
|
|
29
|
-
>
|
|
30
|
-
<Text>Edit app/index.tsx to edit this screen.</Text>
|
|
31
|
-
</View>
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
`;
|
|
35
|
-
|
|
36
|
-
const layoutContent = `import { Stack } from "expo-router";
|
|
37
|
-
|
|
38
|
-
export default function RootLayout() {
|
|
39
|
-
return <Stack />;
|
|
40
|
-
}
|
|
41
|
-
`;
|
|
42
|
-
|
|
43
|
-
const rl = readline.createInterface({
|
|
44
|
-
input: process.stdin,
|
|
45
|
-
output: process.stdout,
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
const moveDirectories = async (userInput) => {
|
|
49
|
-
try {
|
|
50
|
-
if (userInput === "y") {
|
|
51
|
-
// Create the app-example directory
|
|
52
|
-
await fs.promises.mkdir(exampleDirPath, { recursive: true });
|
|
53
|
-
console.log(`📁 /${exampleDir} directory created.`);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// Move old directories to new app-example directory or delete them
|
|
57
|
-
for (const dir of oldDirs) {
|
|
58
|
-
const oldDirPath = path.join(root, dir);
|
|
59
|
-
if (fs.existsSync(oldDirPath)) {
|
|
60
|
-
if (userInput === "y") {
|
|
61
|
-
const newDirPath = path.join(root, exampleDir, dir);
|
|
62
|
-
await fs.promises.rename(oldDirPath, newDirPath);
|
|
63
|
-
console.log(`➡️ /${dir} moved to /${exampleDir}/${dir}.`);
|
|
64
|
-
} else {
|
|
65
|
-
await fs.promises.rm(oldDirPath, { recursive: true, force: true });
|
|
66
|
-
console.log(`❌ /${dir} deleted.`);
|
|
67
|
-
}
|
|
68
|
-
} else {
|
|
69
|
-
console.log(`➡️ /${dir} does not exist, skipping.`);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// Create new /app directory
|
|
74
|
-
const newAppDirPath = path.join(root, newAppDir);
|
|
75
|
-
await fs.promises.mkdir(newAppDirPath, { recursive: true });
|
|
76
|
-
console.log("\n📁 New /app directory created.");
|
|
77
|
-
|
|
78
|
-
// Create index.tsx
|
|
79
|
-
const indexPath = path.join(newAppDirPath, "index.tsx");
|
|
80
|
-
await fs.promises.writeFile(indexPath, indexContent);
|
|
81
|
-
console.log("📄 app/index.tsx created.");
|
|
82
|
-
|
|
83
|
-
// Create _layout.tsx
|
|
84
|
-
const layoutPath = path.join(newAppDirPath, "_layout.tsx");
|
|
85
|
-
await fs.promises.writeFile(layoutPath, layoutContent);
|
|
86
|
-
console.log("📄 app/_layout.tsx created.");
|
|
87
|
-
|
|
88
|
-
console.log("\n✅ Project reset complete. Next steps:");
|
|
89
|
-
console.log(
|
|
90
|
-
`1. Run \`npx expo start\` to start a development server.\n2. Edit app/index.tsx to edit the main screen.${
|
|
91
|
-
userInput === "y"
|
|
92
|
-
? `\n3. Delete the /${exampleDir} directory when you're done referencing it.`
|
|
93
|
-
: ""
|
|
94
|
-
}`
|
|
95
|
-
);
|
|
96
|
-
} catch (error) {
|
|
97
|
-
console.error(`❌ Error during script execution: ${error.message}`);
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
rl.question(
|
|
102
|
-
"Do you want to move existing files to /app-example instead of deleting them? (Y/n): ",
|
|
103
|
-
(answer) => {
|
|
104
|
-
const userInput = answer.trim().toLowerCase() || "y";
|
|
105
|
-
if (userInput === "y" || userInput === "n") {
|
|
106
|
-
moveDirectories(userInput).finally(() => rl.close());
|
|
107
|
-
} else {
|
|
108
|
-
console.log("❌ Invalid input. Please enter 'Y' or 'N'.");
|
|
109
|
-
rl.close();
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
);
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
|
|
3
|
-
const API_BASE_URL = 'https://jsonplaceholder.typicode.com';
|
|
4
|
-
|
|
5
|
-
export interface Post {
|
|
6
|
-
id: number;
|
|
7
|
-
title: string;
|
|
8
|
-
body: string;
|
|
9
|
-
userId: number;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface User {
|
|
13
|
-
id: number;
|
|
14
|
-
name: string;
|
|
15
|
-
username: string;
|
|
16
|
-
email: string;
|
|
17
|
-
phone: string;
|
|
18
|
-
website: string;
|
|
19
|
-
company: {
|
|
20
|
-
name: string;
|
|
21
|
-
catchPhrase: string;
|
|
22
|
-
bs: string;
|
|
23
|
-
};
|
|
24
|
-
address: {
|
|
25
|
-
street: string;
|
|
26
|
-
suite: string;
|
|
27
|
-
city: string;
|
|
28
|
-
zipcode: string;
|
|
29
|
-
geo: {
|
|
30
|
-
lat: string;
|
|
31
|
-
lng: string;
|
|
32
|
-
};
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export interface Comment {
|
|
37
|
-
id: number;
|
|
38
|
-
postId: number;
|
|
39
|
-
name: string;
|
|
40
|
-
email: string;
|
|
41
|
-
body: string;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
class ApiService {
|
|
45
|
-
private api = axios.create({
|
|
46
|
-
baseURL: API_BASE_URL,
|
|
47
|
-
timeout: 10000,
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
// Posts
|
|
51
|
-
async getPosts(): Promise<Post[]> {
|
|
52
|
-
const response = await this.api.get('/posts');
|
|
53
|
-
return response.data;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
async getPost(id: number): Promise<Post> {
|
|
57
|
-
const response = await this.api.get(`/posts/${id}`);
|
|
58
|
-
return response.data;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
async getPostComments(postId: number): Promise<Comment[]> {
|
|
62
|
-
const response = await this.api.get(`/posts/${postId}/comments`);
|
|
63
|
-
return response.data;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Users
|
|
67
|
-
async getUsers(): Promise<User[]> {
|
|
68
|
-
const response = await this.api.get('/users');
|
|
69
|
-
return response.data;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
async getUser(id: number): Promise<User> {
|
|
73
|
-
const response = await this.api.get(`/users/${id}`);
|
|
74
|
-
return response.data;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
async getUserPosts(userId: number): Promise<Post[]> {
|
|
78
|
-
const response = await this.api.get(`/users/${userId}/posts`);
|
|
79
|
-
return response.data;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// Create/Update/Delete operations (for demo purposes)
|
|
83
|
-
async createPost(post: Omit<Post, 'id'>): Promise<Post> {
|
|
84
|
-
const response = await this.api.post('/posts', post);
|
|
85
|
-
return response.data;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
async updatePost(id: number, post: Partial<Post>): Promise<Post> {
|
|
89
|
-
const response = await this.api.put(`/posts/${id}`, post);
|
|
90
|
-
return response.data;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
async deletePost(id: number): Promise<void> {
|
|
94
|
-
await this.api.delete(`/posts/${id}`);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export const apiService = new ApiService();
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
// Navigation utility to avoid router import issues
|
|
2
|
-
export const navigateTo = {
|
|
3
|
-
post: (id: number) => {
|
|
4
|
-
// This will be handled by the router in the component
|
|
5
|
-
return `/post/${id}`
|
|
6
|
-
},
|
|
7
|
-
user: (id: number) => {
|
|
8
|
-
return `/user/${id}`
|
|
9
|
-
},
|
|
10
|
-
posts: () => {
|
|
11
|
-
return '/(tabs)/posts'
|
|
12
|
-
},
|
|
13
|
-
users: () => {
|
|
14
|
-
return '/(tabs)/users'
|
|
15
|
-
},
|
|
16
|
-
home: () => {
|
|
17
|
-
return '/(tabs)/'
|
|
18
|
-
},
|
|
19
|
-
}
|
package/src/sessionRecorder.ts
DELETED
|
@@ -1,367 +0,0 @@
|
|
|
1
|
-
import { SessionRecorderOptions, RecorderConfig, TracerReactNativeConfig } from './types'
|
|
2
|
-
import { TracerReactNativeSDK } from './otel'
|
|
3
|
-
import { RecorderReactNativeSDK } from './recorder'
|
|
4
|
-
import { ApiService } from './services/api.service'
|
|
5
|
-
import { StorageService } from './services/storage.service'
|
|
6
|
-
import {
|
|
7
|
-
SessionType,
|
|
8
|
-
} from '@multiplayer-app/session-recorder-common'
|
|
9
|
-
|
|
10
|
-
// Define these locally since they're not exported from common
|
|
11
|
-
export enum SessionState {
|
|
12
|
-
started = '2',
|
|
13
|
-
paused = '1',
|
|
14
|
-
stopped = '0',
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface ISession {
|
|
18
|
-
id: string
|
|
19
|
-
shortId: string
|
|
20
|
-
type: SessionType
|
|
21
|
-
state: SessionState
|
|
22
|
-
createdAt: string
|
|
23
|
-
updatedAt: string
|
|
24
|
-
tempApiKey?: string
|
|
25
|
-
metadata?: Record<string, any>
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export class SessionRecorder {
|
|
29
|
-
private _configs: SessionRecorderOptions | null = null
|
|
30
|
-
private _tracer: TracerReactNativeSDK
|
|
31
|
-
private _recorder: RecorderReactNativeSDK
|
|
32
|
-
private _apiService: ApiService
|
|
33
|
-
private _storageService: StorageService
|
|
34
|
-
private _session: ISession | null = null
|
|
35
|
-
private _isInitialized = false
|
|
36
|
-
|
|
37
|
-
constructor() {
|
|
38
|
-
this._tracer = new TracerReactNativeSDK()
|
|
39
|
-
this._recorder = new RecorderReactNativeSDK()
|
|
40
|
-
this._apiService = new ApiService()
|
|
41
|
-
this._storageService = new StorageService()
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async init(options: SessionRecorderOptions): Promise<void> {
|
|
45
|
-
if (this._isInitialized) {
|
|
46
|
-
console.warn('SessionRecorder already initialized')
|
|
47
|
-
return
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
this._configs = options
|
|
51
|
-
|
|
52
|
-
// Initialize tracer
|
|
53
|
-
const tracerConfig: TracerReactNativeConfig = {
|
|
54
|
-
apiKey: options.apiKey,
|
|
55
|
-
application: options.application,
|
|
56
|
-
version: options.version,
|
|
57
|
-
environment: options.environment,
|
|
58
|
-
exporterEndpoint: options.exporterEndpoint,
|
|
59
|
-
ignoreUrls: options.ignoreUrls,
|
|
60
|
-
captureBody: options.captureBody,
|
|
61
|
-
captureHeaders: options.captureHeaders,
|
|
62
|
-
sampleTraceRatio: options.sampleTraceRatio,
|
|
63
|
-
httpMasking: options.httpMasking,
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
this._tracer.init(tracerConfig)
|
|
67
|
-
|
|
68
|
-
// Initialize recorder
|
|
69
|
-
const recorderConfig: RecorderConfig = {
|
|
70
|
-
apiKey: options.apiKey,
|
|
71
|
-
apiBaseUrl: options.apiBaseUrl,
|
|
72
|
-
recordScreen: options.recordScreen,
|
|
73
|
-
recordGestures: options.recordGestures,
|
|
74
|
-
recordNavigation: options.recordNavigation,
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
this._recorder.init(recorderConfig)
|
|
79
|
-
|
|
80
|
-
// Initialize API service
|
|
81
|
-
this._apiService.init(options)
|
|
82
|
-
|
|
83
|
-
this._isInitialized = true
|
|
84
|
-
console.log('SessionRecorder initialized successfully')
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
async start(sessionId?: string, sessionType: SessionType = SessionType.PLAIN): Promise<void> {
|
|
88
|
-
if (!this._isInitialized) {
|
|
89
|
-
throw new Error('SessionRecorder not initialized. Call init() first.')
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (!this._configs) {
|
|
93
|
-
throw new Error('Configuration not found')
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
try {
|
|
97
|
-
// Create or use existing session
|
|
98
|
-
if (sessionId) {
|
|
99
|
-
this._session = {
|
|
100
|
-
id: sessionId,
|
|
101
|
-
shortId: sessionId.substring(0, 8),
|
|
102
|
-
type: sessionType,
|
|
103
|
-
state: SessionState.started,
|
|
104
|
-
createdAt: new Date().toISOString(),
|
|
105
|
-
updatedAt: new Date().toISOString(),
|
|
106
|
-
}
|
|
107
|
-
} else {
|
|
108
|
-
// Start new session via API
|
|
109
|
-
this._session = await this._apiService.startSession({
|
|
110
|
-
application: this._configs.application,
|
|
111
|
-
version: this._configs.version,
|
|
112
|
-
environment: this._configs.environment,
|
|
113
|
-
})
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if (!this._session) {
|
|
117
|
-
throw new Error('Failed to create session')
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// Set session ID in tracer
|
|
121
|
-
this._tracer.setSessionId(this._session.id, this._session.type)
|
|
122
|
-
|
|
123
|
-
// Start recording
|
|
124
|
-
this._recorder.start(this._session.id, this._session.type)
|
|
125
|
-
|
|
126
|
-
// Save session data
|
|
127
|
-
await this._storageService.saveSessionId(this._session.id)
|
|
128
|
-
await this._storageService.saveSessionType(this._session.type)
|
|
129
|
-
await this._storageService.saveSessionState(this._session.state)
|
|
130
|
-
await this._storageService.saveSessionObject(this._session)
|
|
131
|
-
|
|
132
|
-
console.log('Session started:', this._session.id)
|
|
133
|
-
} catch (error) {
|
|
134
|
-
console.error('Failed to start session:', error)
|
|
135
|
-
throw error
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
async stop(): Promise<void> {
|
|
140
|
-
if (!this._isInitialized || !this._session) {
|
|
141
|
-
console.warn('Session not active')
|
|
142
|
-
return
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
try {
|
|
146
|
-
// Stop recording
|
|
147
|
-
this._recorder.stop()
|
|
148
|
-
|
|
149
|
-
// Update session state
|
|
150
|
-
this._session.state = SessionState.stopped
|
|
151
|
-
this._session.updatedAt = new Date().toISOString()
|
|
152
|
-
|
|
153
|
-
// Save updated session
|
|
154
|
-
await this._storageService.saveSessionState(this._session.state)
|
|
155
|
-
await this._storageService.saveSessionObject(this._session)
|
|
156
|
-
|
|
157
|
-
// Stop session via API
|
|
158
|
-
await this._apiService.stopSession({
|
|
159
|
-
sessionId: this._session.id,
|
|
160
|
-
})
|
|
161
|
-
|
|
162
|
-
console.log('Session stopped:', this._session.id)
|
|
163
|
-
} catch (error) {
|
|
164
|
-
console.error('Failed to stop session:', error)
|
|
165
|
-
throw error
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
async pause(): Promise<void> {
|
|
170
|
-
if (!this._isInitialized || !this._session) {
|
|
171
|
-
console.warn('Session not active')
|
|
172
|
-
return
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
try {
|
|
176
|
-
// Pause recording
|
|
177
|
-
this._recorder.pause()
|
|
178
|
-
|
|
179
|
-
// Update session state
|
|
180
|
-
this._session.state = SessionState.paused
|
|
181
|
-
this._session.updatedAt = new Date().toISOString()
|
|
182
|
-
|
|
183
|
-
// Save updated session
|
|
184
|
-
await this._storageService.saveSessionState(this._session.state)
|
|
185
|
-
await this._storageService.saveSessionObject(this._session)
|
|
186
|
-
|
|
187
|
-
console.log('Session paused:', this._session.id)
|
|
188
|
-
} catch (error) {
|
|
189
|
-
console.error('Failed to pause session:', error)
|
|
190
|
-
throw error
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
async resume(): Promise<void> {
|
|
195
|
-
if (!this._isInitialized || !this._session) {
|
|
196
|
-
console.warn('Session not active')
|
|
197
|
-
return
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
try {
|
|
201
|
-
// Resume recording
|
|
202
|
-
this._recorder.resume()
|
|
203
|
-
|
|
204
|
-
// Update session state
|
|
205
|
-
this._session.state = SessionState.started
|
|
206
|
-
this._session.updatedAt = new Date().toISOString()
|
|
207
|
-
|
|
208
|
-
// Save updated session
|
|
209
|
-
await this._storageService.saveSessionState(this._session.state)
|
|
210
|
-
await this._storageService.saveSessionObject(this._session)
|
|
211
|
-
|
|
212
|
-
console.log('Session resumed:', this._session.id)
|
|
213
|
-
} catch (error) {
|
|
214
|
-
console.error('Failed to resume session:', error)
|
|
215
|
-
throw error
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
async cancel(): Promise<void> {
|
|
220
|
-
if (!this._isInitialized || !this._session) {
|
|
221
|
-
console.warn('Session not active')
|
|
222
|
-
return
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
try {
|
|
226
|
-
// Stop recording
|
|
227
|
-
this._recorder.stop()
|
|
228
|
-
|
|
229
|
-
// Clear session data
|
|
230
|
-
await this._storageService.clearSessionData()
|
|
231
|
-
|
|
232
|
-
// Cancel session via API
|
|
233
|
-
await this._apiService.stopSession({
|
|
234
|
-
sessionId: this._session.id,
|
|
235
|
-
})
|
|
236
|
-
|
|
237
|
-
this._session = null
|
|
238
|
-
console.log('Session cancelled')
|
|
239
|
-
} catch (error) {
|
|
240
|
-
console.error('Failed to cancel session:', error)
|
|
241
|
-
throw error
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
async save(): Promise<void> {
|
|
246
|
-
if (!this._isInitialized || !this._session) {
|
|
247
|
-
console.warn('Session not active')
|
|
248
|
-
return
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
try {
|
|
252
|
-
// Save session via API
|
|
253
|
-
await this._apiService.saveSession(this._session.id)
|
|
254
|
-
|
|
255
|
-
console.log('Session saved:', this._session.id)
|
|
256
|
-
} catch (error) {
|
|
257
|
-
console.error('Failed to save session:', error)
|
|
258
|
-
throw error
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
// Navigation methods
|
|
263
|
-
setNavigationRef(ref: any): void {
|
|
264
|
-
if (this._isInitialized) {
|
|
265
|
-
this._tracer.setNavigationRef(ref)
|
|
266
|
-
this._recorder.setNavigationRef(ref)
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
// Gesture methods
|
|
271
|
-
enableGestureTracking(): void {
|
|
272
|
-
if (this._isInitialized) {
|
|
273
|
-
this._tracer.enableGestureTracking()
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
disableGestureTracking(): void {
|
|
278
|
-
if (this._isInitialized) {
|
|
279
|
-
this._tracer.disableGestureTracking()
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
// Manual recording methods
|
|
284
|
-
recordTap(x: number, y: number, target?: string): void {
|
|
285
|
-
if (this._isInitialized) {
|
|
286
|
-
this._tracer.recordTap(x, y, target)
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
recordSwipe(direction: string, target?: string): void {
|
|
291
|
-
if (this._isInitialized) {
|
|
292
|
-
this._tracer.recordSwipe(direction, target)
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
recordNavigate(routeName: string, params?: Record<string, any>): void {
|
|
297
|
-
if (this._isInitialized) {
|
|
298
|
-
this._tracer.recordNavigate(routeName, params)
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
recordGoBack(): void {
|
|
303
|
-
if (this._isInitialized) {
|
|
304
|
-
this._tracer.recordGoBack()
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
// Session attributes
|
|
309
|
-
setSessionAttribute(key: string, value: any): void {
|
|
310
|
-
if (this._session) {
|
|
311
|
-
if (!this._session.metadata) {
|
|
312
|
-
this._session.metadata = {}
|
|
313
|
-
}
|
|
314
|
-
this._session.metadata[key] = value
|
|
315
|
-
this._session.updatedAt = new Date().toISOString()
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
getSessionAttribute(key: string): any {
|
|
320
|
-
return this._session?.metadata?.[key]
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
// Get current session
|
|
324
|
-
getCurrentSession(): ISession | null {
|
|
325
|
-
return this._session
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
// Get session data from storage
|
|
329
|
-
async getStoredSessionData(): Promise<{
|
|
330
|
-
sessionId: string | null
|
|
331
|
-
sessionType: SessionType | null
|
|
332
|
-
sessionState: SessionState | null
|
|
333
|
-
sessionObject: ISession | null
|
|
334
|
-
}> {
|
|
335
|
-
return await this._storageService.getAllSessionData()
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
// Performance monitoring methods
|
|
339
|
-
startTrace(name: string, attributes?: Record<string, any>): any {
|
|
340
|
-
if (this._isInitialized) {
|
|
341
|
-
return this._tracer.startTrace(name, attributes)
|
|
342
|
-
}
|
|
343
|
-
return null
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
endTrace(span: any, status?: any): void {
|
|
347
|
-
if (this._isInitialized && span) {
|
|
348
|
-
this._tracer.endTrace(span, status)
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
captureException(error: Error, context?: Record<string, any>): void {
|
|
353
|
-
if (this._isInitialized) {
|
|
354
|
-
this._tracer.captureException(error, context)
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
// Shutdown
|
|
359
|
-
async shutdown(): Promise<void> {
|
|
360
|
-
if (this._isInitialized) {
|
|
361
|
-
await this.stop()
|
|
362
|
-
await this._tracer.shutdown()
|
|
363
|
-
this._isInitialized = false
|
|
364
|
-
console.log('SessionRecorder shutdown')
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
}
|