@multiplayer-app/session-recorder-react-native 0.0.1 → 1.0.0

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 (228) hide show
  1. package/README.md +708 -83
  2. package/SessionRecorderNative.podspec +26 -0
  3. package/android/build.gradle +34 -0
  4. package/copy-react-native-dist.sh +34 -16
  5. package/dist/components/ScreenRecorderView/ScreenRecorderView.js +1 -1
  6. package/dist/components/ScreenRecorderView/ScreenRecorderView.js.map +1 -1
  7. package/dist/components/SessionRecorderWidget/ErrorBanner.d.ts +7 -0
  8. package/dist/components/SessionRecorderWidget/ErrorBanner.js +1 -0
  9. package/dist/components/SessionRecorderWidget/ErrorBanner.js.map +1 -0
  10. package/dist/components/SessionRecorderWidget/FinalPopover.d.ts +12 -0
  11. package/dist/components/SessionRecorderWidget/FinalPopover.js +1 -0
  12. package/dist/components/SessionRecorderWidget/FinalPopover.js.map +1 -0
  13. package/dist/components/SessionRecorderWidget/FloatingButton.d.ts +8 -0
  14. package/dist/components/SessionRecorderWidget/FloatingButton.js +1 -0
  15. package/dist/components/SessionRecorderWidget/FloatingButton.js.map +1 -0
  16. package/dist/components/SessionRecorderWidget/InitialPopover.d.ts +16 -0
  17. package/dist/components/SessionRecorderWidget/InitialPopover.js +1 -0
  18. package/dist/components/SessionRecorderWidget/InitialPopover.js.map +1 -0
  19. package/dist/components/SessionRecorderWidget/ModalContainer.d.ts +8 -0
  20. package/dist/components/SessionRecorderWidget/ModalContainer.js +1 -0
  21. package/dist/components/SessionRecorderWidget/ModalContainer.js.map +1 -0
  22. package/dist/components/SessionRecorderWidget/ModalHeader.d.ts +6 -0
  23. package/dist/components/SessionRecorderWidget/ModalHeader.js +1 -0
  24. package/dist/components/SessionRecorderWidget/ModalHeader.js.map +1 -0
  25. package/dist/components/SessionRecorderWidget/SessionRecorderWidget.d.ts +5 -0
  26. package/dist/components/SessionRecorderWidget/SessionRecorderWidget.js +1 -0
  27. package/dist/components/SessionRecorderWidget/SessionRecorderWidget.js.map +1 -0
  28. package/dist/components/SessionRecorderWidget/icons.d.ts +11 -0
  29. package/dist/components/SessionRecorderWidget/icons.js +1 -0
  30. package/dist/components/SessionRecorderWidget/icons.js.map +1 -0
  31. package/dist/components/SessionRecorderWidget/index.d.ts +2 -0
  32. package/dist/components/SessionRecorderWidget/index.js +1 -0
  33. package/dist/components/SessionRecorderWidget/index.js.map +1 -0
  34. package/dist/components/SessionRecorderWidget/styles.d.ts +165 -0
  35. package/dist/components/SessionRecorderWidget/styles.js +1 -0
  36. package/dist/components/SessionRecorderWidget/styles.js.map +1 -0
  37. package/dist/components/index.d.ts +2 -1
  38. package/dist/components/index.js +1 -1
  39. package/dist/components/index.js.map +1 -1
  40. package/dist/config/constants.js +1 -1
  41. package/dist/config/constants.js.map +1 -1
  42. package/dist/config/defaults.d.ts +4 -4
  43. package/dist/config/defaults.js +1 -1
  44. package/dist/config/defaults.js.map +1 -1
  45. package/dist/config/masking.d.ts +2 -2
  46. package/dist/config/masking.js +1 -1
  47. package/dist/config/masking.js.map +1 -1
  48. package/dist/config/session-recorder.js +1 -1
  49. package/dist/config/session-recorder.js.map +1 -1
  50. package/dist/config/validators.d.ts +1 -1
  51. package/dist/config/validators.js +1 -1
  52. package/dist/config/validators.js.map +1 -1
  53. package/dist/config/widget.d.ts +9 -0
  54. package/dist/config/widget.js +1 -0
  55. package/dist/config/widget.js.map +1 -0
  56. package/dist/context/SessionRecorderContext.d.ts +12 -3
  57. package/dist/context/SessionRecorderContext.js +1 -1
  58. package/dist/context/SessionRecorderContext.js.map +1 -1
  59. package/dist/context/SessionRecorderStore.d.ts +12 -0
  60. package/dist/context/SessionRecorderStore.js +1 -0
  61. package/dist/context/SessionRecorderStore.js.map +1 -0
  62. package/dist/context/useSessionRecorderStore.d.ts +8 -0
  63. package/dist/context/useSessionRecorderStore.js +1 -0
  64. package/dist/context/useSessionRecorderStore.js.map +1 -0
  65. package/dist/context/useStoreSelector.d.ts +4 -0
  66. package/dist/context/useStoreSelector.js +1 -0
  67. package/dist/context/useStoreSelector.js.map +1 -0
  68. package/dist/index.d.ts +1 -1
  69. package/dist/index.js +1 -1
  70. package/dist/index.js.map +1 -1
  71. package/dist/native/GestureRecorderNative.d.ts +57 -0
  72. package/dist/native/GestureRecorderNative.js +1 -0
  73. package/dist/native/GestureRecorderNative.js.map +1 -0
  74. package/dist/native/SessionRecorderNative.d.ts +33 -0
  75. package/dist/native/SessionRecorderNative.js +1 -0
  76. package/dist/native/SessionRecorderNative.js.map +1 -0
  77. package/dist/native/index.d.ts +2 -0
  78. package/dist/native/index.js +1 -0
  79. package/dist/native/index.js.map +1 -0
  80. package/dist/otel/index.js +1 -1
  81. package/dist/otel/index.js.map +1 -1
  82. package/dist/patch/xhr.js +1 -1
  83. package/dist/patch/xhr.js.map +1 -1
  84. package/dist/recorder/eventExporter.d.ts +4 -1
  85. package/dist/recorder/eventExporter.js +1 -1
  86. package/dist/recorder/eventExporter.js.map +1 -1
  87. package/dist/recorder/gestureRecorder.d.ts +28 -62
  88. package/dist/recorder/gestureRecorder.js +1 -1
  89. package/dist/recorder/gestureRecorder.js.map +1 -1
  90. package/dist/recorder/index.d.ts +2 -0
  91. package/dist/recorder/index.js +1 -1
  92. package/dist/recorder/index.js.map +1 -1
  93. package/dist/recorder/navigationTracker.d.ts +4 -19
  94. package/dist/recorder/navigationTracker.js +1 -1
  95. package/dist/recorder/navigationTracker.js.map +1 -1
  96. package/dist/recorder/screenRecorder.d.ts +11 -5
  97. package/dist/recorder/screenRecorder.js +1 -1
  98. package/dist/recorder/screenRecorder.js.map +1 -1
  99. package/dist/services/api.service.d.ts +12 -3
  100. package/dist/services/api.service.js +1 -1
  101. package/dist/services/api.service.js.map +1 -1
  102. package/dist/services/network.service.d.ts +46 -0
  103. package/dist/services/network.service.js +1 -0
  104. package/dist/services/network.service.js.map +1 -0
  105. package/dist/services/screenMaskingService.d.ts +47 -0
  106. package/dist/services/screenMaskingService.js +1 -0
  107. package/dist/services/screenMaskingService.js.map +1 -0
  108. package/dist/services/storage.service.d.ts +18 -2
  109. package/dist/services/storage.service.js +1 -1
  110. package/dist/services/storage.service.js.map +1 -1
  111. package/dist/session-recorder.d.ts +18 -33
  112. package/dist/session-recorder.js +1 -1
  113. package/dist/session-recorder.js.map +1 -1
  114. package/dist/types/configs.d.ts +85 -0
  115. package/dist/types/configs.js +1 -0
  116. package/dist/types/configs.js.map +1 -0
  117. package/dist/types/index.d.ts +1 -0
  118. package/dist/types/index.js +1 -1
  119. package/dist/types/index.js.map +1 -1
  120. package/dist/types/session-recorder.d.ts +105 -132
  121. package/dist/types/session-recorder.js +1 -1
  122. package/dist/types/session-recorder.js.map +1 -1
  123. package/dist/utils/constants.optional.d.ts +21 -0
  124. package/dist/utils/constants.optional.expo.d.ts +3 -0
  125. package/dist/utils/constants.optional.expo.js +1 -0
  126. package/dist/utils/constants.optional.expo.js.map +1 -0
  127. package/dist/utils/constants.optional.js +1 -0
  128. package/dist/utils/constants.optional.js.map +1 -0
  129. package/dist/utils/createStore.d.ts +8 -0
  130. package/dist/utils/createStore.js +1 -0
  131. package/dist/utils/createStore.js.map +1 -0
  132. package/dist/utils/logger.d.ts +2 -7
  133. package/dist/utils/logger.js +1 -1
  134. package/dist/utils/logger.js.map +1 -1
  135. package/dist/utils/platform.d.ts +11 -0
  136. package/dist/utils/platform.js +1 -1
  137. package/dist/utils/platform.js.map +1 -1
  138. package/dist/utils/rrweb-events.d.ts +4 -3
  139. package/dist/utils/rrweb-events.js +1 -1
  140. package/dist/utils/rrweb-events.js.map +1 -1
  141. package/dist/utils/session.d.ts +2 -1
  142. package/dist/utils/session.js +1 -1
  143. package/dist/utils/session.js.map +1 -1
  144. package/dist/utils/shallowEqual.d.ts +1 -0
  145. package/dist/utils/shallowEqual.js +1 -0
  146. package/dist/utils/shallowEqual.js.map +1 -0
  147. package/dist/version.d.ts +1 -1
  148. package/dist/version.js +1 -1
  149. package/ios/GestureRecorderNative.m +21 -0
  150. package/ios/GestureRecorderNative.swift +316 -0
  151. package/ios/SessionRecorderNative.m +17 -0
  152. package/ios/SessionRecorderNative.podspec +26 -0
  153. package/ios/SessionRecorderNative.swift +599 -0
  154. package/package.json +15 -16
  155. package/react-native.config.js +12 -0
  156. package/RRWEB_INTEGRATION.md +0 -336
  157. package/VIEWSHOT_INTEGRATION_TEST.md +0 -123
  158. package/babel.config.js +0 -13
  159. package/dist/components/GestureCaptureWrapper/GestureCaptureWrapper.d.ts +0 -6
  160. package/dist/components/GestureCaptureWrapper/GestureCaptureWrapper.js +0 -1
  161. package/dist/components/GestureCaptureWrapper/GestureCaptureWrapper.js.map +0 -1
  162. package/dist/components/GestureCaptureWrapper/index.d.ts +0 -1
  163. package/dist/components/GestureCaptureWrapper/index.js +0 -1
  164. package/dist/components/GestureCaptureWrapper/index.js.map +0 -1
  165. package/dist/components/GestureCaptureWrapper.d.ts +0 -6
  166. package/dist/components/GestureCaptureWrapper.js +0 -1
  167. package/dist/components/GestureCaptureWrapper.js.map +0 -1
  168. package/dist/expo.d.ts +0 -7
  169. package/dist/expo.js +0 -1
  170. package/dist/expo.js.map +0 -1
  171. package/dist/otel/instrumentations/gestureInstrumentation.d.ts +0 -15
  172. package/dist/otel/instrumentations/gestureInstrumentation.js +0 -1
  173. package/dist/otel/instrumentations/gestureInstrumentation.js.map +0 -1
  174. package/dist/otel/instrumentations/reactNativeInstrumentation.d.ts +0 -8
  175. package/dist/otel/instrumentations/reactNativeInstrumentation.js +0 -1
  176. package/dist/otel/instrumentations/reactNativeInstrumentation.js.map +0 -1
  177. package/dist/otel/instrumentations/reactNavigationInstrumentation.d.ts +0 -13
  178. package/dist/otel/instrumentations/reactNavigationInstrumentation.js +0 -1
  179. package/dist/otel/instrumentations/reactNavigationInstrumentation.js.map +0 -1
  180. package/dist/recorder/gestureHandlerRecorder.d.ts +0 -19
  181. package/dist/recorder/gestureHandlerRecorder.js +0 -1
  182. package/dist/recorder/gestureHandlerRecorder.js.map +0 -1
  183. package/dist/types/rrweb.d.ts +0 -118
  184. package/dist/types/rrweb.js +0 -1
  185. package/dist/types/rrweb.js.map +0 -1
  186. package/scripts/generate-app-metadata.js +0 -173
  187. package/src/components/GestureCaptureWrapper/GestureCaptureWrapper.tsx +0 -86
  188. package/src/components/GestureCaptureWrapper/index.ts +0 -1
  189. package/src/components/ScreenRecorderView/ScreenRecorderView.tsx +0 -72
  190. package/src/components/ScreenRecorderView/index.ts +0 -1
  191. package/src/components/index.ts +0 -1
  192. package/src/config/constants.ts +0 -60
  193. package/src/config/defaults.ts +0 -82
  194. package/src/config/index.ts +0 -6
  195. package/src/config/masking.ts +0 -27
  196. package/src/config/session-recorder.ts +0 -55
  197. package/src/config/validators.ts +0 -31
  198. package/src/context/SessionRecorderContext.tsx +0 -75
  199. package/src/expo.ts +0 -11
  200. package/src/index.ts +0 -17
  201. package/src/otel/helpers.ts +0 -275
  202. package/src/otel/index.ts +0 -138
  203. package/src/otel/instrumentations/index.ts +0 -115
  204. package/src/patch/index.ts +0 -1
  205. package/src/patch/xhr.ts +0 -142
  206. package/src/recorder/eventExporter.ts +0 -141
  207. package/src/recorder/gestureRecorder.ts +0 -498
  208. package/src/recorder/index.ts +0 -179
  209. package/src/recorder/navigationTracker.ts +0 -449
  210. package/src/recorder/screenRecorder.ts +0 -498
  211. package/src/services/api.service.ts +0 -203
  212. package/src/services/storage.service.ts +0 -158
  213. package/src/session-recorder.ts +0 -600
  214. package/src/types/expo.d.ts +0 -23
  215. package/src/types/index.ts +0 -28
  216. package/src/types/session-recorder.ts +0 -423
  217. package/src/types/session.ts +0 -65
  218. package/src/utils/app-metadata.ts +0 -31
  219. package/src/utils/index.ts +0 -8
  220. package/src/utils/logger.ts +0 -225
  221. package/src/utils/platform.ts +0 -384
  222. package/src/utils/request-utils.ts +0 -61
  223. package/src/utils/rrweb-events.ts +0 -309
  224. package/src/utils/session.ts +0 -18
  225. package/src/utils/time.ts +0 -17
  226. package/src/utils/type-utils.ts +0 -75
  227. package/src/version.ts +0 -1
  228. package/tsconfig.json +0 -24
@@ -1,498 +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 !== 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++
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. Make sure react-native-view-shot is properly installed and linked:', 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 = 0 // 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): eventWithTime {
201
- return createIncrementalSnapshotUtil(
202
- base64Image,
203
- this.captureFormat,
204
- )
205
- }
206
-
207
-
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
217
- }
218
-
219
- const incrementalEvent = this.createIncrementalSnapshotWithImageUpdate(base64Image)
220
- this.recordEvent(incrementalEvent)
221
- return true
222
- }
223
-
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++
233
- }
234
-
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
- }
245
-
246
- // Generate hash for current capture
247
- const currentHash = this._generateScreenHash(currentBase64)
248
-
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)
262
- }
263
-
264
- private _sendEvent(event: ScreenEvent): void {
265
- // Screen event recorded
266
- // Send event to backend or store locally
267
- }
268
-
269
- private _recordOpenTelemetrySpan(event: ScreenEvent): void {
270
- try {
271
- const span = trace.getTracer('screen').startSpan(`Screen.${event.type}`, {
272
- attributes: {
273
- 'screen.type': event.type,
274
- 'screen.timestamp': event.timestamp,
275
- 'screen.platform': 'react-native',
276
- },
277
- })
278
-
279
- if (event.metadata) {
280
- Object.entries(event.metadata).forEach(([key, value]) => {
281
- span.setAttribute(`screen.metadata.${key}`, String(value))
282
- })
283
- }
284
-
285
- span.setStatus({ code: SpanStatusCode.OK })
286
- span.end()
287
- } catch (error) {
288
- // Failed to record OpenTelemetry span for screen - silently continue
289
- }
290
- }
291
-
292
- private _recordScreenCaptureError(error: Error): void {
293
- try {
294
- const span = trace.getTracer('screen').startSpan('Screen.capture.error', {
295
- attributes: {
296
- 'screen.error': true,
297
- 'screen.error.type': error.name,
298
- 'screen.error.message': error.message,
299
- 'screen.timestamp': Date.now(),
300
- },
301
- })
302
-
303
- span.setStatus({ code: SpanStatusCode.ERROR, message: error.message })
304
- span.recordException(error)
305
- span.end()
306
- } catch (spanError) {
307
- // Failed to record error span - silently continue
308
- }
309
- }
310
-
311
- async captureSpecificElement(
312
- elementRef: any,
313
- options?: {
314
- format?: 'png' | 'jpg' | 'webp'
315
- quality?: number
316
- },
317
- ): Promise<string | null> {
318
- try {
319
- return await captureRef(elementRef)
320
- } catch (error) {
321
- // Failed to capture specific element - silently continue
322
- return null
323
- }
324
- }
325
-
326
- // Configuration methods
327
- setCaptureInterval(intervalMs: number): void {
328
- if (this.captureInterval) {
329
- clearInterval(this.captureInterval)
330
- }
331
-
332
- if (this.isRecording) {
333
- this.captureInterval = setInterval(() => {
334
- this._captureScreen()
335
- }, intervalMs)
336
- }
337
- }
338
-
339
- setCaptureQuality(quality: number): void {
340
- this.captureQuality = Math.max(0.1, Math.min(1.0, quality))
341
- }
342
-
343
- setCaptureFormat(format: 'png' | 'jpg'): void {
344
- this.captureFormat = format
345
- }
346
-
347
- setMaxCaptures(max: number): void {
348
- this.maxCaptures = Math.max(1, max)
349
- }
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
-
367
- // Performance monitoring
368
- recordScreenPerformance(screenName: string, loadTime: number): void {
369
- const event: ScreenEvent = {
370
- screenName,
371
- type: 'screenCapture',
372
- timestamp: Date.now(),
373
- metadata: {
374
- screenName,
375
- loadTime,
376
- performance: 'monitoring',
377
- captureCount: this.captureCount,
378
- },
379
- }
380
-
381
- this.events.push(event)
382
- this._sendEvent(event)
383
- this._recordOpenTelemetrySpan(event)
384
- this.events.push(event)
385
- this._sendEvent(event)
386
- this._recordOpenTelemetrySpan(event)
387
- }
388
-
389
- // Error tracking
390
- recordScreenError(error: Error, screenName?: string): void {
391
- const event: ScreenEvent = {
392
- screenName: screenName || 'unknown',
393
- type: 'screenCapture',
394
- timestamp: Date.now(),
395
- metadata: {
396
- error: true,
397
- errorType: error.name,
398
- errorMessage: error.message,
399
- screenName,
400
- captureCount: this.captureCount,
401
- },
402
- }
403
-
404
- this.events.push(event)
405
- this._sendEvent(event)
406
- this._recordOpenTelemetrySpan(event)
407
- this.events.push(event)
408
- this._sendEvent(event)
409
- this._recordScreenCaptureError(error)
410
- }
411
-
412
- // Get recorded events
413
- getEvents(): ScreenEvent[] {
414
- return [...this.events]
415
- }
416
-
417
- // Clear events
418
- clearEvents(): void {
419
- this.events = []
420
- this.captureCount = 0
421
- }
422
-
423
- // Get screen capture statistics
424
- getScreenStats(): Record<string, any> {
425
- const stats = {
426
- totalCaptures: this.captureCount,
427
- totalEvents: this.events.length,
428
- averageCaptureTime: 0,
429
- successRate: 0,
430
- }
431
-
432
- if (this.events.length > 0) {
433
- const captureTimes = this.events.map((event) => event.metadata?.captureTime || 0).filter((time) => time > 0)
434
-
435
- if (captureTimes.length > 0) {
436
- stats.averageCaptureTime = captureTimes.reduce((a, b) => a + b, 0) / captureTimes.length
437
- }
438
-
439
- const successfulCaptures = this.events.filter((event) => event.dataUrl).length
440
- stats.successRate = (successfulCaptures / this.events.length) * 100
441
- }
442
-
443
- return stats
444
- }
445
-
446
- // Get recording status
447
- isRecordingEnabled(): boolean {
448
- return this.isRecording
449
- }
450
-
451
- // Get current configuration
452
- getConfiguration(): Record<string, any> {
453
- return {
454
- captureInterval: this.captureInterval ? 5000 : 0, // Default 5 seconds
455
- captureQuality: this.captureQuality,
456
- captureFormat: this.captureFormat,
457
- maxCaptures: this.maxCaptures,
458
- screenDimensions: this.screenDimensions,
459
- }
460
- }
461
-
462
- // Shutdown
463
- shutdown(): void {
464
- this.stop()
465
- this.clearEvents()
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
- }
497
- }
498
- }
@@ -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
- }