@multiplayer-app/session-recorder-react-native 0.0.1-alpha.1 → 0.0.1-alpha.10
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/RRWEB_INTEGRATION.md +336 -0
- package/VIEWSHOT_INTEGRATION_TEST.md +123 -0
- package/copy-react-native-dist.sh +38 -0
- package/dist/components/GestureCaptureWrapper/GestureCaptureWrapper.d.ts +6 -0
- package/dist/components/GestureCaptureWrapper/GestureCaptureWrapper.js +1 -0
- package/dist/components/GestureCaptureWrapper/GestureCaptureWrapper.js.map +1 -0
- package/dist/components/GestureCaptureWrapper/index.d.ts +1 -0
- package/dist/components/GestureCaptureWrapper/index.js +1 -0
- package/dist/components/GestureCaptureWrapper/index.js.map +1 -0
- package/dist/components/GestureCaptureWrapper.d.ts +6 -0
- package/dist/components/GestureCaptureWrapper.js +1 -0
- package/dist/components/GestureCaptureWrapper.js.map +1 -0
- package/dist/components/ScreenRecorderView/ScreenRecorderView.d.ts +5 -0
- package/dist/components/ScreenRecorderView/ScreenRecorderView.js +1 -0
- package/dist/components/ScreenRecorderView/ScreenRecorderView.js.map +1 -0
- package/dist/components/ScreenRecorderView/index.d.ts +1 -0
- package/dist/components/ScreenRecorderView/index.js +1 -0
- package/dist/components/ScreenRecorderView/index.js.map +1 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +1 -0
- package/dist/components/index.js.map +1 -0
- package/dist/config/constants.d.ts +18 -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/context/SessionRecorderContext.d.ts +12 -0
- package/dist/context/SessionRecorderContext.js +1 -0
- package/dist/context/SessionRecorderContext.js.map +1 -0
- package/dist/expo.d.ts +5 -9
- package/dist/expo.js +1 -1
- package/dist/expo.js.map +1 -1
- package/dist/index.d.ts +6 -10
- 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 +4 -25
- package/dist/otel/index.js +1 -1
- package/dist/otel/index.js.map +1 -1
- package/dist/otel/instrumentations/gestureInstrumentation.js +1 -1
- package/dist/otel/instrumentations/gestureInstrumentation.js.map +1 -1
- package/dist/otel/instrumentations/index.d.ts +3 -4
- package/dist/otel/instrumentations/index.js +1 -1
- package/dist/otel/instrumentations/index.js.map +1 -1
- package/dist/otel/instrumentations/reactNativeInstrumentation.js +1 -1
- package/dist/otel/instrumentations/reactNativeInstrumentation.js.map +1 -1
- package/dist/otel/instrumentations/reactNavigationInstrumentation.d.ts +1 -0
- package/dist/otel/instrumentations/reactNavigationInstrumentation.js +1 -1
- package/dist/otel/instrumentations/reactNavigationInstrumentation.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/eventExporter.d.ts +21 -0
- package/dist/recorder/eventExporter.js +1 -0
- package/dist/recorder/eventExporter.js.map +1 -0
- package/dist/recorder/gestureHandlerRecorder.d.ts +19 -0
- package/dist/recorder/gestureHandlerRecorder.js +1 -0
- package/dist/recorder/gestureHandlerRecorder.js.map +1 -0
- package/dist/recorder/gestureRecorder.d.ts +68 -11
- package/dist/recorder/gestureRecorder.js +1 -1
- package/dist/recorder/gestureRecorder.js.map +1 -1
- package/dist/recorder/index.d.ts +60 -6
- package/dist/recorder/index.js +1 -1
- package/dist/recorder/index.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 +79 -10
- 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 +166 -0
- package/dist/session-recorder.js +1 -0
- package/dist/session-recorder.js.map +1 -0
- package/dist/types/index.d.ts +15 -76
- package/dist/types/index.js +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/types/rrweb.d.ts +118 -0
- package/dist/types/rrweb.js +1 -0
- package/dist/types/rrweb.js.map +1 -0
- 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/app-metadata.d.ts +16 -0
- package/dist/utils/app-metadata.js +1 -0
- package/dist/utils/app-metadata.js.map +1 -0
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/logger.d.ts +112 -0
- package/dist/utils/logger.js +1 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/platform.d.ts +37 -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/rrweb-events.d.ts +65 -0
- package/dist/utils/rrweb-events.js +1 -0
- package/dist/utils/rrweb-events.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/dist/version.js.map +1 -1
- package/docs/AUTO_METADATA_DETECTION.md +108 -0
- package/package.json +10 -9
- package/scripts/generate-app-metadata.js +173 -0
- package/src/components/GestureCaptureWrapper/GestureCaptureWrapper.tsx +86 -0
- package/src/components/GestureCaptureWrapper/index.ts +1 -0
- package/src/components/ScreenRecorderView/ScreenRecorderView.tsx +72 -0
- package/src/components/ScreenRecorderView/index.ts +1 -0
- package/src/components/index.ts +1 -0
- 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/context/SessionRecorderContext.tsx +75 -0
- package/src/expo.ts +7 -37
- package/src/index.ts +14 -17
- package/src/otel/helpers.ts +265 -11
- package/src/otel/index.ts +37 -247
- package/src/otel/instrumentations/index.ts +82 -53
- package/src/patch/index.ts +1 -0
- package/src/patch/xhr.ts +142 -0
- package/src/recorder/eventExporter.ts +141 -0
- package/src/recorder/gestureRecorder.ts +194 -125
- package/src/recorder/index.ts +132 -24
- package/src/recorder/navigationTracker.ts +12 -10
- package/src/recorder/screenRecorder.ts +242 -155
- package/src/services/api.service.ts +170 -45
- package/src/services/storage.service.ts +102 -74
- package/src/session-recorder.ts +600 -0
- package/src/types/index.ts +19 -79
- package/src/types/session-recorder.ts +423 -0
- package/src/types/session.ts +65 -0
- package/src/utils/app-metadata.ts +31 -0
- package/src/utils/index.ts +8 -0
- package/src/utils/logger.ts +225 -0
- package/src/utils/platform.ts +321 -6
- package/src/utils/request-utils.ts +61 -0
- package/src/utils/rrweb-events.ts +309 -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/dist/sessionRecorder.d.ts +0 -54
- package/dist/sessionRecorder.js +0 -1
- package/dist/sessionRecorder.js.map +0 -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/otel/instrumentations/gestureInstrumentation.ts +0 -141
- package/src/otel/instrumentations/reactNativeInstrumentation.ts +0 -164
- package/src/otel/instrumentations/reactNavigationInstrumentation.ts +0 -114
- package/src/sessionRecorder.ts +0 -367
|
@@ -1,19 +1,39 @@
|
|
|
1
|
-
import { ScreenEvent, RecorderConfig } from '../types'
|
|
1
|
+
import { ScreenEvent, RecorderConfig, EventRecorder } from '../types'
|
|
2
|
+
import { eventWithTime } from '@rrweb/types'
|
|
2
3
|
import { trace, SpanStatusCode } from '@opentelemetry/api'
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
import { Dimensions } from 'react-native'
|
|
5
|
+
import { captureRef } from 'react-native-view-shot'
|
|
6
|
+
import {
|
|
7
|
+
createRecordingMetaEvent,
|
|
8
|
+
createFullSnapshotEvent,
|
|
9
|
+
createIncrementalSnapshotWithImageUpdate as createIncrementalSnapshotUtil,
|
|
10
|
+
generateScreenHash,
|
|
11
|
+
logger,
|
|
12
|
+
} from '../utils'
|
|
13
|
+
|
|
14
|
+
export class ScreenRecorder implements EventRecorder {
|
|
5
15
|
private config?: RecorderConfig
|
|
6
16
|
private isRecording = false
|
|
7
17
|
private events: ScreenEvent[] = []
|
|
8
18
|
private captureInterval?: NodeJS.Timeout
|
|
9
19
|
private captureCount: number = 0
|
|
10
20
|
private maxCaptures: number = 100 // Limit captures to prevent memory issues
|
|
11
|
-
private captureQuality: number = 0.
|
|
12
|
-
private captureFormat: 'png' | 'jpg'
|
|
21
|
+
private captureQuality: number = 0.3
|
|
22
|
+
private captureFormat: 'png' | 'jpg' = 'jpg'
|
|
13
23
|
private screenDimensions: { width: number; height: number } | null = null
|
|
14
|
-
|
|
15
|
-
|
|
24
|
+
private currentScreen: string | null = null
|
|
25
|
+
private eventRecorder?: EventRecorder
|
|
26
|
+
private nodeIdCounter: number = 1
|
|
27
|
+
private viewShotRef: any = null
|
|
28
|
+
private lastScreenCapture: string | null = null
|
|
29
|
+
private lastScreenHash: string | null = null
|
|
30
|
+
private enableChangeDetection: boolean = true
|
|
31
|
+
private hashSampleSize: number = 100
|
|
32
|
+
private currentImageNodeId: number | null = null
|
|
33
|
+
|
|
34
|
+
init(config: RecorderConfig, eventRecorder?: EventRecorder): void {
|
|
16
35
|
this.config = config
|
|
36
|
+
this.eventRecorder = eventRecorder
|
|
17
37
|
this._getScreenDimensions()
|
|
18
38
|
}
|
|
19
39
|
|
|
@@ -21,14 +41,26 @@ export class ScreenRecorder {
|
|
|
21
41
|
this.isRecording = true
|
|
22
42
|
this.events = []
|
|
23
43
|
this.captureCount = 0
|
|
44
|
+
this.lastScreenCapture = null
|
|
45
|
+
this.lastScreenHash = null
|
|
46
|
+
this.currentImageNodeId = null // Reset image node ID for new session
|
|
47
|
+
logger.info('ScreenRecorder', 'Screen recording started')
|
|
48
|
+
// Emit screen recording started meta event
|
|
49
|
+
|
|
50
|
+
this.recordEvent(createRecordingMetaEvent())
|
|
51
|
+
|
|
24
52
|
this._startPeriodicCapture()
|
|
25
|
-
|
|
53
|
+
|
|
54
|
+
// Capture initial screen immediately
|
|
55
|
+
this._captureScreen()
|
|
56
|
+
|
|
57
|
+
// Screen recording started
|
|
26
58
|
}
|
|
27
59
|
|
|
28
60
|
stop(): void {
|
|
29
61
|
this.isRecording = false
|
|
30
62
|
this._stopPeriodicCapture()
|
|
31
|
-
|
|
63
|
+
// Screen recording stopped
|
|
32
64
|
}
|
|
33
65
|
|
|
34
66
|
pause(): void {
|
|
@@ -38,15 +70,14 @@ export class ScreenRecorder {
|
|
|
38
70
|
|
|
39
71
|
resume(): void {
|
|
40
72
|
this.isRecording = true
|
|
41
|
-
this._startPeriodicCapture()
|
|
73
|
+
// this._startPeriodicCapture()
|
|
42
74
|
}
|
|
43
75
|
|
|
44
76
|
private _getScreenDimensions(): void {
|
|
45
77
|
try {
|
|
46
|
-
const { Dimensions } = require('react-native')
|
|
47
78
|
this.screenDimensions = Dimensions.get('window')
|
|
48
79
|
} catch (error) {
|
|
49
|
-
|
|
80
|
+
// Failed to get screen dimensions - silently continue
|
|
50
81
|
this.screenDimensions = { width: 375, height: 667 } // Default fallback
|
|
51
82
|
}
|
|
52
83
|
}
|
|
@@ -56,7 +87,7 @@ export class ScreenRecorder {
|
|
|
56
87
|
clearInterval(this.captureInterval)
|
|
57
88
|
}
|
|
58
89
|
|
|
59
|
-
// Capture screen every 5 seconds
|
|
90
|
+
// Capture screen every 5 seconds (reduced frequency)
|
|
60
91
|
this.captureInterval = setInterval(() => {
|
|
61
92
|
this._captureScreen()
|
|
62
93
|
}, 5000)
|
|
@@ -73,145 +104,166 @@ export class ScreenRecorder {
|
|
|
73
104
|
if (!this.isRecording || this.captureCount >= this.maxCaptures) return
|
|
74
105
|
|
|
75
106
|
try {
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
107
|
+
const base64Image = await this._captureScreenBase64()
|
|
108
|
+
|
|
109
|
+
if (base64Image) {
|
|
110
|
+
// Check if screen has changed by comparing with previous capture
|
|
111
|
+
const hasChanged = this.enableChangeDetection ? this._hasScreenChanged(base64Image) : true
|
|
112
|
+
|
|
113
|
+
if (hasChanged) {
|
|
114
|
+
// Use incremental snapshot if we have an existing image node, otherwise create full snapshot
|
|
115
|
+
if (this.currentImageNodeId !== null && this.lastScreenCapture) {
|
|
116
|
+
const success = this.updateScreenWithIncrementalSnapshot(base64Image)
|
|
117
|
+
if (!success) {
|
|
118
|
+
// Fallback to full snapshot if incremental update fails
|
|
119
|
+
this._createAndEmitFullSnapshotEvent(base64Image)
|
|
120
|
+
}
|
|
121
|
+
} else {
|
|
122
|
+
// First capture or no existing image node - create full snapshot
|
|
123
|
+
this._createAndEmitFullSnapshotEvent(base64Image)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
this.lastScreenCapture = base64Image
|
|
127
|
+
this.lastScreenHash = this._generateScreenHash(base64Image)
|
|
128
|
+
this.captureCount++
|
|
93
129
|
}
|
|
94
|
-
|
|
95
|
-
this.events.push(screenEvent)
|
|
96
|
-
this.captureCount++
|
|
97
|
-
this._sendEvent(screenEvent)
|
|
98
|
-
this._recordOpenTelemetrySpan(screenEvent)
|
|
99
130
|
}
|
|
100
131
|
} catch (error) {
|
|
101
|
-
|
|
102
|
-
this._recordScreenCaptureError(error instanceof Error ? error : new Error(String(error)))
|
|
132
|
+
this._recordScreenCaptureError(error as Error)
|
|
103
133
|
}
|
|
104
134
|
}
|
|
105
135
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
private async _performScreenCapture(): Promise<string | null> {
|
|
136
|
+
private async _captureScreenBase64(): Promise<string | null> {
|
|
109
137
|
try {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
return await this._captureWithViewShot()
|
|
138
|
+
if (!this.viewShotRef) {
|
|
139
|
+
logger.warn('ScreenRecorder', 'ViewShot ref not available for screen capture')
|
|
140
|
+
return null
|
|
114
141
|
}
|
|
115
|
-
} catch (error) {
|
|
116
|
-
console.warn('react-native-view-shot not available:', error)
|
|
117
|
-
}
|
|
118
142
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
143
|
+
// Capture the screen using react-native-view-shot
|
|
144
|
+
const result = await captureRef(this.viewShotRef, {
|
|
145
|
+
format: this.captureFormat,
|
|
146
|
+
quality: this.captureQuality,
|
|
147
|
+
result: 'base64',
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
return result
|
|
125
151
|
} catch (error) {
|
|
126
|
-
|
|
152
|
+
logger.error('ScreenRecorder', 'Failed to capture screen. Make sure react-native-view-shot is properly installed and linked:', error)
|
|
153
|
+
return null
|
|
127
154
|
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
private _createAndEmitFullSnapshotEvent(base64Image: string): void {
|
|
158
|
+
if (!this.screenDimensions) return
|
|
128
159
|
|
|
129
|
-
//
|
|
130
|
-
|
|
160
|
+
// Use the new createFullSnapshot method
|
|
161
|
+
const fullSnapshotEvent = this.createFullSnapshot(base64Image)
|
|
162
|
+
this.recordEvent(fullSnapshotEvent)
|
|
131
163
|
}
|
|
132
164
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
165
|
+
/**
|
|
166
|
+
* Create a full snapshot event with the given base64 image
|
|
167
|
+
* @param base64Image - Base64 encoded image data
|
|
168
|
+
* @returns Full snapshot event
|
|
169
|
+
*/
|
|
170
|
+
createFullSnapshot(base64Image: string): eventWithTime {
|
|
171
|
+
if (!this.screenDimensions) {
|
|
172
|
+
throw new Error('Screen dimensions not available')
|
|
173
|
+
}
|
|
136
174
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
const rootViewRef = this._getRootViewRef()
|
|
175
|
+
const { width, height } = this.screenDimensions
|
|
176
|
+
this.nodeIdCounter = 1
|
|
140
177
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
178
|
+
// Use utility function to create full snapshot event
|
|
179
|
+
const fullSnapshotEvent = createFullSnapshotEvent(
|
|
180
|
+
base64Image,
|
|
181
|
+
width,
|
|
182
|
+
height,
|
|
183
|
+
this.captureFormat,
|
|
184
|
+
{ current: this.nodeIdCounter },
|
|
185
|
+
)
|
|
147
186
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
return null
|
|
187
|
+
// Store the image node ID for future incremental updates
|
|
188
|
+
// The image node ID is the first node created (after the document)
|
|
189
|
+
this.currentImageNodeId = 0 // First element node is the image
|
|
190
|
+
|
|
191
|
+
return fullSnapshotEvent
|
|
154
192
|
}
|
|
155
193
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
194
|
+
/**
|
|
195
|
+
* Create an incremental snapshot event with mutation data to update image src
|
|
196
|
+
* @param base64Image - New base64 encoded image data
|
|
197
|
+
* @param imageNodeId - ID of the image node to update
|
|
198
|
+
* @returns Incremental snapshot event with mutation data
|
|
199
|
+
*/
|
|
200
|
+
createIncrementalSnapshotWithImageUpdate(base64Image: string): eventWithTime {
|
|
201
|
+
return createIncrementalSnapshotUtil(
|
|
202
|
+
base64Image,
|
|
203
|
+
this.captureFormat,
|
|
204
|
+
)
|
|
205
|
+
}
|
|
159
206
|
|
|
160
|
-
const options = {
|
|
161
|
-
format: this.captureFormat,
|
|
162
|
-
quality: this.captureQuality,
|
|
163
|
-
}
|
|
164
207
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
208
|
+
/**
|
|
209
|
+
* Update the screen with a new image using incremental snapshot
|
|
210
|
+
* @param base64Image - New base64 encoded image data
|
|
211
|
+
* @returns true if update was successful, false otherwise
|
|
212
|
+
*/
|
|
213
|
+
updateScreenWithIncrementalSnapshot(base64Image: string): boolean {
|
|
214
|
+
if (this.currentImageNodeId === null) {
|
|
215
|
+
logger.warn('ScreenRecorder', 'No image node ID available for incremental update')
|
|
216
|
+
return false
|
|
168
217
|
}
|
|
169
|
-
|
|
218
|
+
|
|
219
|
+
const incrementalEvent = this.createIncrementalSnapshotWithImageUpdate(base64Image)
|
|
220
|
+
this.recordEvent(incrementalEvent)
|
|
221
|
+
return true
|
|
170
222
|
}
|
|
171
223
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}
|
|
224
|
+
/**
|
|
225
|
+
* Force a full snapshot (useful when screen dimensions change or for debugging)
|
|
226
|
+
* @param base64Image - Base64 encoded image data
|
|
227
|
+
*/
|
|
228
|
+
forceFullSnapshot(base64Image: string): void {
|
|
229
|
+
this._createAndEmitFullSnapshotEvent(base64Image)
|
|
230
|
+
this.lastScreenCapture = base64Image
|
|
231
|
+
this.lastScreenHash = this._generateScreenHash(base64Image)
|
|
232
|
+
this.captureCount++
|
|
182
233
|
}
|
|
183
234
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
235
|
+
/**
|
|
236
|
+
* Check if the screen has changed by comparing with the previous capture
|
|
237
|
+
* @param currentBase64 - Current screen capture as base64
|
|
238
|
+
* @returns true if screen has changed, false otherwise
|
|
239
|
+
*/
|
|
240
|
+
private _hasScreenChanged(currentBase64: string): boolean {
|
|
241
|
+
// If this is the first capture, consider it changed
|
|
242
|
+
if (!this.lastScreenCapture) {
|
|
243
|
+
return true
|
|
244
|
+
}
|
|
189
245
|
|
|
190
|
-
//
|
|
191
|
-
const
|
|
192
|
-
<svg width="${width}" height="${height}" xmlns="http://www.w3.org/2000/svg">
|
|
193
|
-
<rect width="100%" height="100%" fill="#f0f0f0"/>
|
|
194
|
-
<text x="50%" y="50%" text-anchor="middle" dy=".3em" fill="#666" font-family="Arial" font-size="16">
|
|
195
|
-
Screen Capture Placeholder
|
|
196
|
-
</text>
|
|
197
|
-
<text x="50%" y="60%" text-anchor="middle" dy=".3em" fill="#666" font-family="Arial" font-size="14">
|
|
198
|
-
Captured at ${new Date().toLocaleTimeString()}
|
|
199
|
-
</text>
|
|
200
|
-
</svg>
|
|
201
|
-
`
|
|
246
|
+
// Generate hash for current capture
|
|
247
|
+
const currentHash = this._generateScreenHash(currentBase64)
|
|
202
248
|
|
|
203
|
-
//
|
|
204
|
-
|
|
205
|
-
|
|
249
|
+
// Compare with previous hash
|
|
250
|
+
return currentHash !== this.lastScreenHash
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Generate a simple hash for screen comparison
|
|
255
|
+
* This is a lightweight hash that focuses on the beginning and end of the base64 string
|
|
256
|
+
* to detect changes without doing a full comparison
|
|
257
|
+
* @param base64Image - Base64 encoded image
|
|
258
|
+
* @returns Hash string for comparison
|
|
259
|
+
*/
|
|
260
|
+
private _generateScreenHash(base64Image: string): string {
|
|
261
|
+
return generateScreenHash(base64Image, this.hashSampleSize)
|
|
206
262
|
}
|
|
207
263
|
|
|
208
264
|
private _sendEvent(event: ScreenEvent): void {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
timestamp: event.timestamp,
|
|
212
|
-
captureCount: event.metadata?.captureCount,
|
|
213
|
-
captureTime: event.metadata?.captureTime,
|
|
214
|
-
})
|
|
265
|
+
// Screen event recorded
|
|
266
|
+
// Send event to backend or store locally
|
|
215
267
|
}
|
|
216
268
|
|
|
217
269
|
private _recordOpenTelemetrySpan(event: ScreenEvent): void {
|
|
@@ -233,7 +285,7 @@ export class ScreenRecorder {
|
|
|
233
285
|
span.setStatus({ code: SpanStatusCode.OK })
|
|
234
286
|
span.end()
|
|
235
287
|
} catch (error) {
|
|
236
|
-
|
|
288
|
+
// Failed to record OpenTelemetry span for screen - silently continue
|
|
237
289
|
}
|
|
238
290
|
}
|
|
239
291
|
|
|
@@ -252,36 +304,21 @@ export class ScreenRecorder {
|
|
|
252
304
|
span.recordException(error)
|
|
253
305
|
span.end()
|
|
254
306
|
} catch (spanError) {
|
|
255
|
-
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
// Manual screen capture methods
|
|
260
|
-
async captureScreenNow(): Promise<string | null> {
|
|
261
|
-
if (!this.isRecording) {
|
|
262
|
-
console.warn('Screen recording not active')
|
|
263
|
-
return null
|
|
307
|
+
// Failed to record error span - silently continue
|
|
264
308
|
}
|
|
265
|
-
|
|
266
|
-
return await this._performScreenCapture()
|
|
267
309
|
}
|
|
268
310
|
|
|
269
|
-
async captureSpecificElement(
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
311
|
+
async captureSpecificElement(
|
|
312
|
+
elementRef: any,
|
|
313
|
+
options?: {
|
|
314
|
+
format?: 'png' | 'jpg' | 'webp'
|
|
315
|
+
quality?: number
|
|
316
|
+
},
|
|
317
|
+
): Promise<string | null> {
|
|
273
318
|
try {
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
const captureOptions = {
|
|
277
|
-
format: options?.format || this.captureFormat,
|
|
278
|
-
quality: options?.quality || this.captureQuality,
|
|
279
|
-
result: 'data-uri',
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
return await ViewShot.captureRef(elementRef, captureOptions)
|
|
319
|
+
return await captureRef(elementRef)
|
|
283
320
|
} catch (error) {
|
|
284
|
-
|
|
321
|
+
// Failed to capture specific element - silently continue
|
|
285
322
|
return null
|
|
286
323
|
}
|
|
287
324
|
}
|
|
@@ -303,7 +340,7 @@ export class ScreenRecorder {
|
|
|
303
340
|
this.captureQuality = Math.max(0.1, Math.min(1.0, quality))
|
|
304
341
|
}
|
|
305
342
|
|
|
306
|
-
setCaptureFormat(format: 'png' | 'jpg'
|
|
343
|
+
setCaptureFormat(format: 'png' | 'jpg'): void {
|
|
307
344
|
this.captureFormat = format
|
|
308
345
|
}
|
|
309
346
|
|
|
@@ -311,9 +348,26 @@ export class ScreenRecorder {
|
|
|
311
348
|
this.maxCaptures = Math.max(1, max)
|
|
312
349
|
}
|
|
313
350
|
|
|
351
|
+
/**
|
|
352
|
+
* Enable or disable change detection
|
|
353
|
+
* @param enabled - Whether to enable change detection
|
|
354
|
+
*/
|
|
355
|
+
setChangeDetection(enabled: boolean): void {
|
|
356
|
+
this.enableChangeDetection = enabled
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Set the hash sample size for change detection
|
|
361
|
+
* @param size - Number of characters to sample from each part of the image
|
|
362
|
+
*/
|
|
363
|
+
setHashSampleSize(size: number): void {
|
|
364
|
+
this.hashSampleSize = Math.max(10, Math.min(1000, size))
|
|
365
|
+
}
|
|
366
|
+
|
|
314
367
|
// Performance monitoring
|
|
315
368
|
recordScreenPerformance(screenName: string, loadTime: number): void {
|
|
316
369
|
const event: ScreenEvent = {
|
|
370
|
+
screenName,
|
|
317
371
|
type: 'screenCapture',
|
|
318
372
|
timestamp: Date.now(),
|
|
319
373
|
metadata: {
|
|
@@ -324,7 +378,9 @@ export class ScreenRecorder {
|
|
|
324
378
|
},
|
|
325
379
|
}
|
|
326
380
|
|
|
327
|
-
this.events.push(event)
|
|
381
|
+
this.events.push(event)
|
|
382
|
+
this._sendEvent(event)
|
|
383
|
+
this._recordOpenTelemetrySpan(event)
|
|
328
384
|
this.events.push(event)
|
|
329
385
|
this._sendEvent(event)
|
|
330
386
|
this._recordOpenTelemetrySpan(event)
|
|
@@ -333,6 +389,7 @@ export class ScreenRecorder {
|
|
|
333
389
|
// Error tracking
|
|
334
390
|
recordScreenError(error: Error, screenName?: string): void {
|
|
335
391
|
const event: ScreenEvent = {
|
|
392
|
+
screenName: screenName || 'unknown',
|
|
336
393
|
type: 'screenCapture',
|
|
337
394
|
timestamp: Date.now(),
|
|
338
395
|
metadata: {
|
|
@@ -344,7 +401,9 @@ export class ScreenRecorder {
|
|
|
344
401
|
},
|
|
345
402
|
}
|
|
346
403
|
|
|
347
|
-
this.events.push(event)
|
|
404
|
+
this.events.push(event)
|
|
405
|
+
this._sendEvent(event)
|
|
406
|
+
this._recordOpenTelemetrySpan(event)
|
|
348
407
|
this.events.push(event)
|
|
349
408
|
this._sendEvent(event)
|
|
350
409
|
this._recordScreenCaptureError(error)
|
|
@@ -371,15 +430,13 @@ export class ScreenRecorder {
|
|
|
371
430
|
}
|
|
372
431
|
|
|
373
432
|
if (this.events.length > 0) {
|
|
374
|
-
const captureTimes = this.events
|
|
375
|
-
.map(event => event.metadata?.captureTime || 0)
|
|
376
|
-
.filter(time => time > 0)
|
|
433
|
+
const captureTimes = this.events.map((event) => event.metadata?.captureTime || 0).filter((time) => time > 0)
|
|
377
434
|
|
|
378
435
|
if (captureTimes.length > 0) {
|
|
379
436
|
stats.averageCaptureTime = captureTimes.reduce((a, b) => a + b, 0) / captureTimes.length
|
|
380
437
|
}
|
|
381
438
|
|
|
382
|
-
const successfulCaptures = this.events.filter(event => event.dataUrl).length
|
|
439
|
+
const successfulCaptures = this.events.filter((event) => event.dataUrl).length
|
|
383
440
|
stats.successRate = (successfulCaptures / this.events.length) * 100
|
|
384
441
|
}
|
|
385
442
|
|
|
@@ -406,6 +463,36 @@ export class ScreenRecorder {
|
|
|
406
463
|
shutdown(): void {
|
|
407
464
|
this.stop()
|
|
408
465
|
this.clearEvents()
|
|
409
|
-
|
|
466
|
+
// Screen recorder shutdown
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* Set the viewshot ref for screen capture
|
|
471
|
+
* @param ref - React Native View ref for screen capture
|
|
472
|
+
*/
|
|
473
|
+
setViewShotRef(ref: any): void {
|
|
474
|
+
this.viewShotRef = ref
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* Force capture screen (useful after touch interactions)
|
|
479
|
+
* This bypasses the change detection and always captures
|
|
480
|
+
*/
|
|
481
|
+
forceCapture(): void {
|
|
482
|
+
if (!this.isRecording) {
|
|
483
|
+
return
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
this._captureScreen()
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
/**
|
|
490
|
+
* Record an rrweb event
|
|
491
|
+
* @param event - The rrweb event to record
|
|
492
|
+
*/
|
|
493
|
+
recordEvent(event: any): void {
|
|
494
|
+
if (this.eventRecorder) {
|
|
495
|
+
this.eventRecorder.recordEvent(event)
|
|
496
|
+
}
|
|
410
497
|
}
|
|
411
498
|
}
|