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