@multiplayer-app/session-recorder-react-native 0.0.1-beta.7 → 0.0.1-beta.9
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/app.plugin.js +42 -0
- package/docs/NATIVE_MODULE_SETUP.md +177 -0
- package/ios/SessionRecorderNative.podspec +5 -0
- package/package.json +10 -1
- package/plugin/package.json +20 -0
- package/plugin/src/index.js +42 -0
- package/android/src/main/AndroidManifest.xml +0 -2
- package/android/src/main/java/com/multiplayer/sessionrecorder/ScreenMaskingModule.kt +0 -202
- package/android/src/main/java/com/multiplayer/sessionrecorder/ScreenMaskingPackage.kt +0 -16
- package/android/src/main/java/com/multiplayer/sessionrecorder/SessionRecorderModule.kt +0 -202
- package/android/src/main/java/com/multiplayer/sessionrecorder/SessionRecorderPackage.kt +0 -16
- package/babel.config.js +0 -13
- package/docs/AUTO_METADATA_DETECTION.md +0 -108
- package/docs/TROUBLESHOOTING.md +0 -168
- package/ios/ScreenMasking.m +0 -12
- package/ios/ScreenMasking.podspec +0 -21
- package/ios/ScreenMasking.swift +0 -205
- package/ios/SessionRecorder.podspec +0 -21
- package/scripts/generate-app-metadata.js +0 -173
- package/src/components/GestureCaptureWrapper/GestureCaptureWrapper.tsx +0 -86
- package/src/components/GestureCaptureWrapper/index.ts +0 -1
- package/src/components/ScreenRecorderView/ScreenRecorderView.tsx +0 -72
- package/src/components/ScreenRecorderView/index.ts +0 -1
- package/src/components/SessionRecorderWidget/FinalPopover.tsx +0 -62
- package/src/components/SessionRecorderWidget/FloatingButton.tsx +0 -136
- package/src/components/SessionRecorderWidget/InitialPopover.tsx +0 -89
- package/src/components/SessionRecorderWidget/ModalContainer.tsx +0 -128
- package/src/components/SessionRecorderWidget/ModalHeader.tsx +0 -24
- package/src/components/SessionRecorderWidget/SessionRecorderWidget.tsx +0 -109
- package/src/components/SessionRecorderWidget/icons.tsx +0 -52
- package/src/components/SessionRecorderWidget/index.ts +0 -3
- package/src/components/SessionRecorderWidget/styles.ts +0 -150
- package/src/components/index.ts +0 -3
- package/src/config/constants.ts +0 -60
- package/src/config/defaults.ts +0 -83
- package/src/config/index.ts +0 -6
- package/src/config/masking.ts +0 -28
- package/src/config/session-recorder.ts +0 -55
- package/src/config/validators.ts +0 -31
- package/src/context/SessionRecorderContext.tsx +0 -53
- package/src/index.ts +0 -9
- package/src/native/ScreenMasking.ts +0 -34
- package/src/native/SessionRecorderNative.ts +0 -34
- package/src/otel/helpers.ts +0 -275
- package/src/otel/index.ts +0 -138
- package/src/otel/instrumentations/index.ts +0 -115
- package/src/patch/index.ts +0 -1
- package/src/patch/xhr.ts +0 -141
- package/src/recorder/eventExporter.ts +0 -141
- package/src/recorder/gestureRecorder.ts +0 -498
- package/src/recorder/index.ts +0 -179
- package/src/recorder/navigationTracker.ts +0 -449
- package/src/recorder/screenRecorder.ts +0 -527
- package/src/services/api.service.ts +0 -203
- package/src/services/screenMaskingService.ts +0 -118
- package/src/services/storage.service.ts +0 -199
- package/src/session-recorder.ts +0 -606
- package/src/types/expo.d.ts +0 -23
- package/src/types/index.ts +0 -28
- package/src/types/session-recorder.ts +0 -429
- package/src/types/session.ts +0 -65
- package/src/utils/app-metadata.ts +0 -31
- package/src/utils/index.ts +0 -8
- package/src/utils/logger.ts +0 -225
- package/src/utils/nativeModuleTest.ts +0 -60
- package/src/utils/platform.ts +0 -384
- package/src/utils/request-utils.ts +0 -61
- package/src/utils/rrweb-events.ts +0 -309
- package/src/utils/session.ts +0 -18
- package/src/utils/time.ts +0 -17
- package/src/utils/type-utils.ts +0 -75
- package/src/version.ts +0 -1
- package/tsconfig.json +0 -24
- /package/ios/{SessionRecorder.m → SessionRecorderNative.m} +0 -0
- /package/ios/{SessionRecorder.swift → SessionRecorderNative.swift} +0 -0
|
@@ -1,527 +0,0 @@
|
|
|
1
|
-
import { ScreenEvent, RecorderConfig, EventRecorder } from '../types'
|
|
2
|
-
import { eventWithTime } from '@rrweb/types'
|
|
3
|
-
import { trace, SpanStatusCode } from '@opentelemetry/api'
|
|
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
|
-
import { screenMaskingService, ScreenMaskingConfig } from '../services/screenMaskingService'
|
|
14
|
-
|
|
15
|
-
export class ScreenRecorder implements EventRecorder {
|
|
16
|
-
private config?: RecorderConfig
|
|
17
|
-
private isRecording = false
|
|
18
|
-
private events: ScreenEvent[] = []
|
|
19
|
-
private captureInterval?: NodeJS.Timeout
|
|
20
|
-
private captureCount: number = 0
|
|
21
|
-
private maxCaptures: number = 100 // Limit captures to prevent memory issues
|
|
22
|
-
private captureQuality: number = 0.1
|
|
23
|
-
private captureFormat: 'png' | 'jpg' = 'jpg'
|
|
24
|
-
private screenDimensions: { width: number; height: number } | null = null
|
|
25
|
-
private currentScreen: string | null = null
|
|
26
|
-
private eventRecorder?: EventRecorder
|
|
27
|
-
private nodeIdCounter: number = 1
|
|
28
|
-
private viewShotRef: any = null
|
|
29
|
-
private lastScreenCapture: string | null = null
|
|
30
|
-
private lastScreenHash: string | null = null
|
|
31
|
-
private enableChangeDetection: boolean = true
|
|
32
|
-
private hashSampleSize: number = 100
|
|
33
|
-
private currentImageNodeId: number | null = null
|
|
34
|
-
private maskingConfig?: ScreenMaskingConfig
|
|
35
|
-
|
|
36
|
-
init(config: RecorderConfig, eventRecorder?: EventRecorder): void {
|
|
37
|
-
this.config = config
|
|
38
|
-
this.eventRecorder = eventRecorder
|
|
39
|
-
this._getScreenDimensions()
|
|
40
|
-
|
|
41
|
-
// Initialize masking configuration
|
|
42
|
-
this.maskingConfig = {
|
|
43
|
-
enabled: true,
|
|
44
|
-
inputMasking: this.config?.masking?.inputMasking ?? true,
|
|
45
|
-
defaultOptions: {
|
|
46
|
-
quality: this.captureQuality,
|
|
47
|
-
},
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// Update the masking service configuration
|
|
51
|
-
screenMaskingService.updateConfig(this.maskingConfig)
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
start(): void {
|
|
55
|
-
this.isRecording = true
|
|
56
|
-
this.events = []
|
|
57
|
-
this.captureCount = 0
|
|
58
|
-
this.lastScreenCapture = null
|
|
59
|
-
this.lastScreenHash = null
|
|
60
|
-
this.currentImageNodeId = null // Reset image node ID for new session
|
|
61
|
-
logger.info('ScreenRecorder', 'Screen recording started')
|
|
62
|
-
// Emit screen recording started meta event
|
|
63
|
-
|
|
64
|
-
this.recordEvent(createRecordingMetaEvent())
|
|
65
|
-
|
|
66
|
-
this._startPeriodicCapture()
|
|
67
|
-
|
|
68
|
-
// Capture initial screen immediately
|
|
69
|
-
this._captureScreen()
|
|
70
|
-
|
|
71
|
-
// Screen recording started
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
stop(): void {
|
|
75
|
-
this.isRecording = false
|
|
76
|
-
this._stopPeriodicCapture()
|
|
77
|
-
// Screen recording stopped
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
pause(): void {
|
|
81
|
-
this.isRecording = false
|
|
82
|
-
this._stopPeriodicCapture()
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
resume(): void {
|
|
86
|
-
this.isRecording = true
|
|
87
|
-
// this._startPeriodicCapture()
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
private _getScreenDimensions(): void {
|
|
91
|
-
try {
|
|
92
|
-
this.screenDimensions = Dimensions.get('window')
|
|
93
|
-
} catch (error) {
|
|
94
|
-
// Failed to get screen dimensions - silently continue
|
|
95
|
-
this.screenDimensions = { width: 375, height: 667 } // Default fallback
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
private _startPeriodicCapture(): void {
|
|
100
|
-
if (this.captureInterval) {
|
|
101
|
-
clearInterval(this.captureInterval)
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// Capture screen every 5 seconds (reduced frequency)
|
|
105
|
-
this.captureInterval = setInterval(() => {
|
|
106
|
-
this._captureScreen()
|
|
107
|
-
}, 5000)
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
private _stopPeriodicCapture(): void {
|
|
111
|
-
if (this.captureInterval) {
|
|
112
|
-
clearInterval(this.captureInterval)
|
|
113
|
-
this.captureInterval = undefined
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
private async _captureScreen(): Promise<void> {
|
|
118
|
-
if (!this.isRecording || this.captureCount >= this.maxCaptures) return
|
|
119
|
-
|
|
120
|
-
try {
|
|
121
|
-
const base64Image = await this._captureScreenBase64()
|
|
122
|
-
|
|
123
|
-
if (base64Image) {
|
|
124
|
-
// Check if screen has changed by comparing with previous capture
|
|
125
|
-
const hasChanged = this.enableChangeDetection ? this._hasScreenChanged(base64Image) : true
|
|
126
|
-
|
|
127
|
-
if (hasChanged) {
|
|
128
|
-
// Use incremental snapshot if we have an existing image node, otherwise create full snapshot
|
|
129
|
-
if (this.currentImageNodeId !== null && this.lastScreenCapture) {
|
|
130
|
-
const success = this.updateScreenWithIncrementalSnapshot(base64Image)
|
|
131
|
-
if (!success) {
|
|
132
|
-
// Fallback to full snapshot if incremental update fails
|
|
133
|
-
this._createAndEmitFullSnapshotEvent(base64Image)
|
|
134
|
-
}
|
|
135
|
-
} else {
|
|
136
|
-
// First capture or no existing image node - create full snapshot
|
|
137
|
-
this._createAndEmitFullSnapshotEvent(base64Image)
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
this.lastScreenCapture = base64Image
|
|
141
|
-
this.lastScreenHash = this._generateScreenHash(base64Image)
|
|
142
|
-
this.captureCount++
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
} catch (error) {
|
|
146
|
-
this._recordScreenCaptureError(error as Error)
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
private async _captureScreenBase64(): Promise<string | null> {
|
|
151
|
-
try {
|
|
152
|
-
// Try native masking first if available
|
|
153
|
-
if (screenMaskingService.isScreenMaskingAvailable()) {
|
|
154
|
-
logger.info('ScreenRecorder', 'Using native masking for screen capture')
|
|
155
|
-
const maskedImage = await screenMaskingService.captureMaskedScreen({
|
|
156
|
-
quality: this.captureQuality,
|
|
157
|
-
})
|
|
158
|
-
|
|
159
|
-
if (maskedImage) {
|
|
160
|
-
return maskedImage
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
logger.warn('ScreenRecorder', 'Native masking failed, falling back to view-shot')
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
// Fallback to react-native-view-shot
|
|
167
|
-
if (!this.viewShotRef) {
|
|
168
|
-
logger.warn('ScreenRecorder', 'ViewShot ref not available for screen capture')
|
|
169
|
-
return null
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// Capture the screen using react-native-view-shot
|
|
173
|
-
const result = await captureRef(this.viewShotRef, {
|
|
174
|
-
format: this.captureFormat,
|
|
175
|
-
quality: this.captureQuality,
|
|
176
|
-
result: 'base64',
|
|
177
|
-
})
|
|
178
|
-
|
|
179
|
-
return result
|
|
180
|
-
} catch (error) {
|
|
181
|
-
logger.error('ScreenRecorder', 'Failed to capture screen. Make sure react-native-view-shot is properly installed and linked:', error)
|
|
182
|
-
return null
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
private _createAndEmitFullSnapshotEvent(base64Image: string): void {
|
|
187
|
-
if (!this.screenDimensions) return
|
|
188
|
-
|
|
189
|
-
// Use the new createFullSnapshot method
|
|
190
|
-
const fullSnapshotEvent = this.createFullSnapshot(base64Image)
|
|
191
|
-
this.recordEvent(fullSnapshotEvent)
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* Create a full snapshot event with the given base64 image
|
|
196
|
-
* @param base64Image - Base64 encoded image data
|
|
197
|
-
* @returns Full snapshot event
|
|
198
|
-
*/
|
|
199
|
-
createFullSnapshot(base64Image: string): eventWithTime {
|
|
200
|
-
if (!this.screenDimensions) {
|
|
201
|
-
throw new Error('Screen dimensions not available')
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
const { width, height } = this.screenDimensions
|
|
205
|
-
this.nodeIdCounter = 1
|
|
206
|
-
|
|
207
|
-
// Use utility function to create full snapshot event
|
|
208
|
-
const fullSnapshotEvent = createFullSnapshotEvent(
|
|
209
|
-
base64Image,
|
|
210
|
-
width,
|
|
211
|
-
height,
|
|
212
|
-
this.captureFormat,
|
|
213
|
-
{ current: this.nodeIdCounter },
|
|
214
|
-
)
|
|
215
|
-
|
|
216
|
-
// Store the image node ID for future incremental updates
|
|
217
|
-
// The image node ID is the first node created (after the document)
|
|
218
|
-
this.currentImageNodeId = 0 // First element node is the image
|
|
219
|
-
|
|
220
|
-
return fullSnapshotEvent
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* Create an incremental snapshot event with mutation data to update image src
|
|
225
|
-
* @param base64Image - New base64 encoded image data
|
|
226
|
-
* @param imageNodeId - ID of the image node to update
|
|
227
|
-
* @returns Incremental snapshot event with mutation data
|
|
228
|
-
*/
|
|
229
|
-
createIncrementalSnapshotWithImageUpdate(base64Image: string): eventWithTime {
|
|
230
|
-
return createIncrementalSnapshotUtil(
|
|
231
|
-
base64Image,
|
|
232
|
-
this.captureFormat,
|
|
233
|
-
)
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* Update the screen with a new image using incremental snapshot
|
|
239
|
-
* @param base64Image - New base64 encoded image data
|
|
240
|
-
* @returns true if update was successful, false otherwise
|
|
241
|
-
*/
|
|
242
|
-
updateScreenWithIncrementalSnapshot(base64Image: string): boolean {
|
|
243
|
-
if (this.currentImageNodeId === null) {
|
|
244
|
-
logger.warn('ScreenRecorder', 'No image node ID available for incremental update')
|
|
245
|
-
return false
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
const incrementalEvent = this.createIncrementalSnapshotWithImageUpdate(base64Image)
|
|
249
|
-
this.recordEvent(incrementalEvent)
|
|
250
|
-
return true
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* Force a full snapshot (useful when screen dimensions change or for debugging)
|
|
255
|
-
* @param base64Image - Base64 encoded image data
|
|
256
|
-
*/
|
|
257
|
-
forceFullSnapshot(base64Image: string): void {
|
|
258
|
-
this._createAndEmitFullSnapshotEvent(base64Image)
|
|
259
|
-
this.lastScreenCapture = base64Image
|
|
260
|
-
this.lastScreenHash = this._generateScreenHash(base64Image)
|
|
261
|
-
this.captureCount++
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
/**
|
|
265
|
-
* Check if the screen has changed by comparing with the previous capture
|
|
266
|
-
* @param currentBase64 - Current screen capture as base64
|
|
267
|
-
* @returns true if screen has changed, false otherwise
|
|
268
|
-
*/
|
|
269
|
-
private _hasScreenChanged(currentBase64: string): boolean {
|
|
270
|
-
// If this is the first capture, consider it changed
|
|
271
|
-
if (!this.lastScreenCapture) {
|
|
272
|
-
return true
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
// Generate hash for current capture
|
|
276
|
-
const currentHash = this._generateScreenHash(currentBase64)
|
|
277
|
-
|
|
278
|
-
// Compare with previous hash
|
|
279
|
-
return currentHash !== this.lastScreenHash
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
/**
|
|
283
|
-
* Generate a simple hash for screen comparison
|
|
284
|
-
* This is a lightweight hash that focuses on the beginning and end of the base64 string
|
|
285
|
-
* to detect changes without doing a full comparison
|
|
286
|
-
* @param base64Image - Base64 encoded image
|
|
287
|
-
* @returns Hash string for comparison
|
|
288
|
-
*/
|
|
289
|
-
private _generateScreenHash(base64Image: string): string {
|
|
290
|
-
return generateScreenHash(base64Image, this.hashSampleSize)
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
private _sendEvent(event: ScreenEvent): void {
|
|
294
|
-
// Screen event recorded
|
|
295
|
-
// Send event to backend or store locally
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
private _recordOpenTelemetrySpan(event: ScreenEvent): void {
|
|
299
|
-
try {
|
|
300
|
-
const span = trace.getTracer('screen').startSpan(`Screen.${event.type}`, {
|
|
301
|
-
attributes: {
|
|
302
|
-
'screen.type': event.type,
|
|
303
|
-
'screen.timestamp': event.timestamp,
|
|
304
|
-
'screen.platform': 'react-native',
|
|
305
|
-
},
|
|
306
|
-
})
|
|
307
|
-
|
|
308
|
-
if (event.metadata) {
|
|
309
|
-
Object.entries(event.metadata).forEach(([key, value]) => {
|
|
310
|
-
span.setAttribute(`screen.metadata.${key}`, String(value))
|
|
311
|
-
})
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
span.setStatus({ code: SpanStatusCode.OK })
|
|
315
|
-
span.end()
|
|
316
|
-
} catch (error) {
|
|
317
|
-
// Failed to record OpenTelemetry span for screen - silently continue
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
private _recordScreenCaptureError(error: Error): void {
|
|
322
|
-
try {
|
|
323
|
-
const span = trace.getTracer('screen').startSpan('Screen.capture.error', {
|
|
324
|
-
attributes: {
|
|
325
|
-
'screen.error': true,
|
|
326
|
-
'screen.error.type': error.name,
|
|
327
|
-
'screen.error.message': error.message,
|
|
328
|
-
'screen.timestamp': Date.now(),
|
|
329
|
-
},
|
|
330
|
-
})
|
|
331
|
-
|
|
332
|
-
span.setStatus({ code: SpanStatusCode.ERROR, message: error.message })
|
|
333
|
-
span.recordException(error)
|
|
334
|
-
span.end()
|
|
335
|
-
} catch (spanError) {
|
|
336
|
-
// Failed to record error span - silently continue
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
async captureSpecificElement(
|
|
341
|
-
elementRef: any,
|
|
342
|
-
options?: {
|
|
343
|
-
format?: 'png' | 'jpg' | 'webp'
|
|
344
|
-
quality?: number
|
|
345
|
-
},
|
|
346
|
-
): Promise<string | null> {
|
|
347
|
-
try {
|
|
348
|
-
return await captureRef(elementRef)
|
|
349
|
-
} catch (error) {
|
|
350
|
-
// Failed to capture specific element - silently continue
|
|
351
|
-
return null
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
// Configuration methods
|
|
356
|
-
setCaptureInterval(intervalMs: number): void {
|
|
357
|
-
if (this.captureInterval) {
|
|
358
|
-
clearInterval(this.captureInterval)
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
if (this.isRecording) {
|
|
362
|
-
this.captureInterval = setInterval(() => {
|
|
363
|
-
this._captureScreen()
|
|
364
|
-
}, intervalMs)
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
setCaptureQuality(quality: number): void {
|
|
369
|
-
this.captureQuality = Math.max(0.1, Math.min(1.0, quality))
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
setCaptureFormat(format: 'png' | 'jpg'): void {
|
|
373
|
-
this.captureFormat = format
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
setMaxCaptures(max: number): void {
|
|
377
|
-
this.maxCaptures = Math.max(1, max)
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
/**
|
|
381
|
-
* Enable or disable change detection
|
|
382
|
-
* @param enabled - Whether to enable change detection
|
|
383
|
-
*/
|
|
384
|
-
setChangeDetection(enabled: boolean): void {
|
|
385
|
-
this.enableChangeDetection = enabled
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
/**
|
|
389
|
-
* Set the hash sample size for change detection
|
|
390
|
-
* @param size - Number of characters to sample from each part of the image
|
|
391
|
-
*/
|
|
392
|
-
setHashSampleSize(size: number): void {
|
|
393
|
-
this.hashSampleSize = Math.max(10, Math.min(1000, size))
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
// Performance monitoring
|
|
397
|
-
recordScreenPerformance(screenName: string, loadTime: number): void {
|
|
398
|
-
const event: ScreenEvent = {
|
|
399
|
-
screenName,
|
|
400
|
-
type: 'screenCapture',
|
|
401
|
-
timestamp: Date.now(),
|
|
402
|
-
metadata: {
|
|
403
|
-
screenName,
|
|
404
|
-
loadTime,
|
|
405
|
-
performance: 'monitoring',
|
|
406
|
-
captureCount: this.captureCount,
|
|
407
|
-
},
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
this.events.push(event)
|
|
411
|
-
this._sendEvent(event)
|
|
412
|
-
this._recordOpenTelemetrySpan(event)
|
|
413
|
-
this.events.push(event)
|
|
414
|
-
this._sendEvent(event)
|
|
415
|
-
this._recordOpenTelemetrySpan(event)
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
// Error tracking
|
|
419
|
-
recordScreenError(error: Error, screenName?: string): void {
|
|
420
|
-
const event: ScreenEvent = {
|
|
421
|
-
screenName: screenName || 'unknown',
|
|
422
|
-
type: 'screenCapture',
|
|
423
|
-
timestamp: Date.now(),
|
|
424
|
-
metadata: {
|
|
425
|
-
error: true,
|
|
426
|
-
errorType: error.name,
|
|
427
|
-
errorMessage: error.message,
|
|
428
|
-
screenName,
|
|
429
|
-
captureCount: this.captureCount,
|
|
430
|
-
},
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
this.events.push(event)
|
|
434
|
-
this._sendEvent(event)
|
|
435
|
-
this._recordOpenTelemetrySpan(event)
|
|
436
|
-
this.events.push(event)
|
|
437
|
-
this._sendEvent(event)
|
|
438
|
-
this._recordScreenCaptureError(error)
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
// Get recorded events
|
|
442
|
-
getEvents(): ScreenEvent[] {
|
|
443
|
-
return [...this.events]
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
// Clear events
|
|
447
|
-
clearEvents(): void {
|
|
448
|
-
this.events = []
|
|
449
|
-
this.captureCount = 0
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
// Get screen capture statistics
|
|
453
|
-
getScreenStats(): Record<string, any> {
|
|
454
|
-
const stats = {
|
|
455
|
-
totalCaptures: this.captureCount,
|
|
456
|
-
totalEvents: this.events.length,
|
|
457
|
-
averageCaptureTime: 0,
|
|
458
|
-
successRate: 0,
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
if (this.events.length > 0) {
|
|
462
|
-
const captureTimes = this.events.map((event) => event.metadata?.captureTime || 0).filter((time) => time > 0)
|
|
463
|
-
|
|
464
|
-
if (captureTimes.length > 0) {
|
|
465
|
-
stats.averageCaptureTime = captureTimes.reduce((a, b) => a + b, 0) / captureTimes.length
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
const successfulCaptures = this.events.filter((event) => event.dataUrl).length
|
|
469
|
-
stats.successRate = (successfulCaptures / this.events.length) * 100
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
return stats
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
// Get recording status
|
|
476
|
-
isRecordingEnabled(): boolean {
|
|
477
|
-
return this.isRecording
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
// Get current configuration
|
|
481
|
-
getConfiguration(): Record<string, any> {
|
|
482
|
-
return {
|
|
483
|
-
captureInterval: this.captureInterval ? 2000 : 0, // Default 5 seconds
|
|
484
|
-
captureQuality: this.captureQuality,
|
|
485
|
-
captureFormat: this.captureFormat,
|
|
486
|
-
maxCaptures: this.maxCaptures,
|
|
487
|
-
screenDimensions: this.screenDimensions,
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
// Shutdown
|
|
492
|
-
shutdown(): void {
|
|
493
|
-
this.stop()
|
|
494
|
-
this.clearEvents()
|
|
495
|
-
// Screen recorder shutdown
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
/**
|
|
499
|
-
* Set the viewshot ref for screen capture
|
|
500
|
-
* @param ref - React Native View ref for screen capture
|
|
501
|
-
*/
|
|
502
|
-
setViewShotRef(ref: any): void {
|
|
503
|
-
this.viewShotRef = ref
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
/**
|
|
507
|
-
* Force capture screen (useful after touch interactions)
|
|
508
|
-
* This bypasses the change detection and always captures
|
|
509
|
-
*/
|
|
510
|
-
forceCapture(): void {
|
|
511
|
-
if (!this.isRecording) {
|
|
512
|
-
return
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
this._captureScreen()
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
/**
|
|
519
|
-
* Record an rrweb event
|
|
520
|
-
* @param event - The rrweb event to record
|
|
521
|
-
*/
|
|
522
|
-
recordEvent(event: any): void {
|
|
523
|
-
if (this.eventRecorder) {
|
|
524
|
-
this.eventRecorder.recordEvent(event)
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
}
|