@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.
Files changed (234) hide show
  1. package/RRWEB_INTEGRATION.md +336 -0
  2. package/VIEWSHOT_INTEGRATION_TEST.md +123 -0
  3. package/copy-react-native-dist.sh +38 -0
  4. package/dist/components/GestureCaptureWrapper/GestureCaptureWrapper.d.ts +6 -0
  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/GestureCaptureWrapper.d.ts +6 -0
  11. package/dist/components/GestureCaptureWrapper.js +1 -0
  12. package/dist/components/GestureCaptureWrapper.js.map +1 -0
  13. package/dist/components/ScreenRecorderView/ScreenRecorderView.d.ts +5 -0
  14. package/dist/components/ScreenRecorderView/ScreenRecorderView.js +1 -0
  15. package/dist/components/ScreenRecorderView/ScreenRecorderView.js.map +1 -0
  16. package/dist/components/ScreenRecorderView/index.d.ts +1 -0
  17. package/dist/components/ScreenRecorderView/index.js +1 -0
  18. package/dist/components/ScreenRecorderView/index.js.map +1 -0
  19. package/dist/components/index.d.ts +1 -0
  20. package/dist/components/index.js +1 -0
  21. package/dist/components/index.js.map +1 -0
  22. package/dist/config/constants.d.ts +18 -0
  23. package/dist/config/constants.js +1 -0
  24. package/dist/config/constants.js.map +1 -0
  25. package/dist/config/defaults.d.ts +4 -0
  26. package/dist/config/defaults.js +1 -0
  27. package/dist/config/defaults.js.map +1 -0
  28. package/dist/config/index.d.ts +5 -0
  29. package/dist/config/index.js +1 -0
  30. package/dist/config/index.js.map +1 -0
  31. package/dist/config/masking.d.ts +2 -30
  32. package/dist/config/masking.js +1 -1
  33. package/dist/config/masking.js.map +1 -1
  34. package/dist/config/session-recorder.d.ts +2 -0
  35. package/dist/config/session-recorder.js +1 -0
  36. package/dist/config/session-recorder.js.map +1 -0
  37. package/dist/config/validators.d.ts +10 -0
  38. package/dist/config/validators.js +1 -0
  39. package/dist/config/validators.js.map +1 -0
  40. package/dist/context/SessionRecorderContext.d.ts +12 -0
  41. package/dist/context/SessionRecorderContext.js +1 -0
  42. package/dist/context/SessionRecorderContext.js.map +1 -0
  43. package/dist/expo.d.ts +5 -9
  44. package/dist/expo.js +1 -1
  45. package/dist/expo.js.map +1 -1
  46. package/dist/index.d.ts +6 -10
  47. package/dist/index.js +1 -1
  48. package/dist/index.js.map +1 -1
  49. package/dist/otel/helpers.d.ts +45 -3
  50. package/dist/otel/helpers.js +1 -1
  51. package/dist/otel/helpers.js.map +1 -1
  52. package/dist/otel/index.d.ts +4 -25
  53. package/dist/otel/index.js +1 -1
  54. package/dist/otel/index.js.map +1 -1
  55. package/dist/otel/instrumentations/gestureInstrumentation.js +1 -1
  56. package/dist/otel/instrumentations/gestureInstrumentation.js.map +1 -1
  57. package/dist/otel/instrumentations/index.d.ts +3 -4
  58. package/dist/otel/instrumentations/index.js +1 -1
  59. package/dist/otel/instrumentations/index.js.map +1 -1
  60. package/dist/otel/instrumentations/reactNativeInstrumentation.js +1 -1
  61. package/dist/otel/instrumentations/reactNativeInstrumentation.js.map +1 -1
  62. package/dist/otel/instrumentations/reactNavigationInstrumentation.d.ts +1 -0
  63. package/dist/otel/instrumentations/reactNavigationInstrumentation.js +1 -1
  64. package/dist/otel/instrumentations/reactNavigationInstrumentation.js.map +1 -1
  65. package/dist/patch/index.d.ts +1 -0
  66. package/dist/patch/index.js +1 -0
  67. package/dist/patch/index.js.map +1 -0
  68. package/dist/patch/xhr.d.ts +2 -0
  69. package/dist/patch/xhr.js +1 -0
  70. package/dist/patch/xhr.js.map +1 -0
  71. package/dist/recorder/eventExporter.d.ts +21 -0
  72. package/dist/recorder/eventExporter.js +1 -0
  73. package/dist/recorder/eventExporter.js.map +1 -0
  74. package/dist/recorder/gestureHandlerRecorder.d.ts +19 -0
  75. package/dist/recorder/gestureHandlerRecorder.js +1 -0
  76. package/dist/recorder/gestureHandlerRecorder.js.map +1 -0
  77. package/dist/recorder/gestureRecorder.d.ts +68 -11
  78. package/dist/recorder/gestureRecorder.js +1 -1
  79. package/dist/recorder/gestureRecorder.js.map +1 -1
  80. package/dist/recorder/index.d.ts +60 -6
  81. package/dist/recorder/index.js +1 -1
  82. package/dist/recorder/index.js.map +1 -1
  83. package/dist/recorder/navigationTracker.js +1 -1
  84. package/dist/recorder/navigationTracker.js.map +1 -1
  85. package/dist/recorder/screenRecorder.d.ts +79 -10
  86. package/dist/recorder/screenRecorder.js +1 -1
  87. package/dist/recorder/screenRecorder.js.map +1 -1
  88. package/dist/services/api.service.d.ts +62 -10
  89. package/dist/services/api.service.js +1 -1
  90. package/dist/services/api.service.js.map +1 -1
  91. package/dist/services/storage.service.d.ts +23 -16
  92. package/dist/services/storage.service.js +1 -1
  93. package/dist/services/storage.service.js.map +1 -1
  94. package/dist/session-recorder.d.ts +166 -0
  95. package/dist/session-recorder.js +1 -0
  96. package/dist/session-recorder.js.map +1 -0
  97. package/dist/types/index.d.ts +15 -76
  98. package/dist/types/index.js +1 -1
  99. package/dist/types/index.js.map +1 -1
  100. package/dist/types/rrweb.d.ts +118 -0
  101. package/dist/types/rrweb.js +1 -0
  102. package/dist/types/rrweb.js.map +1 -0
  103. package/dist/types/session-recorder.d.ts +366 -0
  104. package/dist/types/session-recorder.js +1 -0
  105. package/dist/types/session-recorder.js.map +1 -0
  106. package/dist/types/session.d.ts +59 -0
  107. package/dist/types/session.js +1 -0
  108. package/dist/types/session.js.map +1 -0
  109. package/dist/utils/app-metadata.d.ts +16 -0
  110. package/dist/utils/app-metadata.js +1 -0
  111. package/dist/utils/app-metadata.js.map +1 -0
  112. package/dist/utils/index.d.ts +7 -0
  113. package/dist/utils/index.js +1 -0
  114. package/dist/utils/index.js.map +1 -0
  115. package/dist/utils/logger.d.ts +112 -0
  116. package/dist/utils/logger.js +1 -0
  117. package/dist/utils/logger.js.map +1 -0
  118. package/dist/utils/platform.d.ts +37 -0
  119. package/dist/utils/platform.js +1 -1
  120. package/dist/utils/platform.js.map +1 -1
  121. package/dist/utils/request-utils.d.ts +21 -0
  122. package/dist/utils/request-utils.js +1 -0
  123. package/dist/utils/request-utils.js.map +1 -0
  124. package/dist/utils/rrweb-events.d.ts +65 -0
  125. package/dist/utils/rrweb-events.js +1 -0
  126. package/dist/utils/rrweb-events.js.map +1 -0
  127. package/dist/utils/session.d.ts +5 -0
  128. package/dist/utils/session.js +1 -0
  129. package/dist/utils/session.js.map +1 -0
  130. package/dist/utils/time.d.ts +4 -0
  131. package/dist/utils/time.js +1 -0
  132. package/dist/utils/time.js.map +1 -0
  133. package/dist/utils/type-utils.d.ts +16 -0
  134. package/dist/utils/type-utils.js +1 -0
  135. package/dist/utils/type-utils.js.map +1 -0
  136. package/dist/version.d.ts +1 -1
  137. package/dist/version.js +1 -1
  138. package/dist/version.js.map +1 -1
  139. package/docs/AUTO_METADATA_DETECTION.md +108 -0
  140. package/package.json +10 -9
  141. package/scripts/generate-app-metadata.js +173 -0
  142. package/src/components/GestureCaptureWrapper/GestureCaptureWrapper.tsx +86 -0
  143. package/src/components/GestureCaptureWrapper/index.ts +1 -0
  144. package/src/components/ScreenRecorderView/ScreenRecorderView.tsx +72 -0
  145. package/src/components/ScreenRecorderView/index.ts +1 -0
  146. package/src/components/index.ts +1 -0
  147. package/src/config/constants.ts +60 -0
  148. package/src/config/defaults.ts +82 -0
  149. package/src/config/index.ts +6 -0
  150. package/src/config/masking.ts +10 -61
  151. package/src/config/session-recorder.ts +55 -0
  152. package/src/config/validators.ts +31 -0
  153. package/src/context/SessionRecorderContext.tsx +75 -0
  154. package/src/expo.ts +7 -37
  155. package/src/index.ts +14 -17
  156. package/src/otel/helpers.ts +265 -11
  157. package/src/otel/index.ts +37 -247
  158. package/src/otel/instrumentations/index.ts +82 -53
  159. package/src/patch/index.ts +1 -0
  160. package/src/patch/xhr.ts +142 -0
  161. package/src/recorder/eventExporter.ts +141 -0
  162. package/src/recorder/gestureRecorder.ts +194 -125
  163. package/src/recorder/index.ts +132 -24
  164. package/src/recorder/navigationTracker.ts +12 -10
  165. package/src/recorder/screenRecorder.ts +242 -155
  166. package/src/services/api.service.ts +170 -45
  167. package/src/services/storage.service.ts +102 -74
  168. package/src/session-recorder.ts +600 -0
  169. package/src/types/index.ts +19 -79
  170. package/src/types/session-recorder.ts +423 -0
  171. package/src/types/session.ts +65 -0
  172. package/src/utils/app-metadata.ts +31 -0
  173. package/src/utils/index.ts +8 -0
  174. package/src/utils/logger.ts +225 -0
  175. package/src/utils/platform.ts +321 -6
  176. package/src/utils/request-utils.ts +61 -0
  177. package/src/utils/rrweb-events.ts +309 -0
  178. package/src/utils/session.ts +18 -0
  179. package/src/utils/time.ts +17 -0
  180. package/src/utils/type-utils.ts +75 -0
  181. package/src/version.ts +1 -1
  182. package/dist/sessionRecorder.d.ts +0 -54
  183. package/dist/sessionRecorder.js +0 -1
  184. package/dist/sessionRecorder.js.map +0 -1
  185. package/examples/sample-expo-app/README.md +0 -142
  186. package/examples/sample-expo-app/app/(tabs)/_layout.tsx +0 -60
  187. package/examples/sample-expo-app/app/(tabs)/explore.tsx +0 -110
  188. package/examples/sample-expo-app/app/(tabs)/index.tsx +0 -125
  189. package/examples/sample-expo-app/app/(tabs)/posts.tsx +0 -96
  190. package/examples/sample-expo-app/app/(tabs)/users.tsx +0 -131
  191. package/examples/sample-expo-app/app/+not-found.tsx +0 -32
  192. package/examples/sample-expo-app/app/_layout.tsx +0 -53
  193. package/examples/sample-expo-app/app/post/[id].tsx +0 -199
  194. package/examples/sample-expo-app/app/user/[id].tsx +0 -270
  195. package/examples/sample-expo-app/app.json +0 -42
  196. package/examples/sample-expo-app/assets/fonts/SpaceMono-Regular.ttf +0 -0
  197. package/examples/sample-expo-app/assets/images/adaptive-icon.png +0 -0
  198. package/examples/sample-expo-app/assets/images/favicon.png +0 -0
  199. package/examples/sample-expo-app/assets/images/icon.png +0 -0
  200. package/examples/sample-expo-app/assets/images/partial-react-logo.png +0 -0
  201. package/examples/sample-expo-app/assets/images/react-logo.png +0 -0
  202. package/examples/sample-expo-app/assets/images/react-logo@2x.png +0 -0
  203. package/examples/sample-expo-app/assets/images/react-logo@3x.png +0 -0
  204. package/examples/sample-expo-app/assets/images/splash-icon.png +0 -0
  205. package/examples/sample-expo-app/components/Collapsible.tsx +0 -45
  206. package/examples/sample-expo-app/components/ErrorView.tsx +0 -52
  207. package/examples/sample-expo-app/components/ExternalLink.tsx +0 -24
  208. package/examples/sample-expo-app/components/HapticTab.tsx +0 -18
  209. package/examples/sample-expo-app/components/HelloWave.tsx +0 -40
  210. package/examples/sample-expo-app/components/LoadingSpinner.tsx +0 -34
  211. package/examples/sample-expo-app/components/ParallaxScrollView.tsx +0 -82
  212. package/examples/sample-expo-app/components/ThemedText.tsx +0 -60
  213. package/examples/sample-expo-app/components/ThemedView.tsx +0 -14
  214. package/examples/sample-expo-app/components/ui/IconSymbol.ios.tsx +0 -32
  215. package/examples/sample-expo-app/components/ui/IconSymbol.tsx +0 -41
  216. package/examples/sample-expo-app/components/ui/TabBarBackground.ios.tsx +0 -19
  217. package/examples/sample-expo-app/components/ui/TabBarBackground.tsx +0 -6
  218. package/examples/sample-expo-app/constants/Colors.ts +0 -26
  219. package/examples/sample-expo-app/eslint.config.js +0 -10
  220. package/examples/sample-expo-app/hooks/useApi.ts +0 -41
  221. package/examples/sample-expo-app/hooks/useColorScheme.ts +0 -1
  222. package/examples/sample-expo-app/hooks/useColorScheme.web.ts +0 -21
  223. package/examples/sample-expo-app/hooks/useThemeColor.ts +0 -21
  224. package/examples/sample-expo-app/metro.config.js +0 -26
  225. package/examples/sample-expo-app/package-lock.json +0 -26296
  226. package/examples/sample-expo-app/package.json +0 -59
  227. package/examples/sample-expo-app/scripts/reset-project.js +0 -112
  228. package/examples/sample-expo-app/services/api.ts +0 -98
  229. package/examples/sample-expo-app/tsconfig.json +0 -17
  230. package/examples/sample-expo-app/utils/navigation.ts +0 -19
  231. package/src/otel/instrumentations/gestureInstrumentation.ts +0 -141
  232. package/src/otel/instrumentations/reactNativeInstrumentation.ts +0 -164
  233. package/src/otel/instrumentations/reactNavigationInstrumentation.ts +0 -114
  234. package/src/sessionRecorder.ts +0 -367
@@ -1,114 +0,0 @@
1
- import { InstrumentationBase } from '@opentelemetry/instrumentation'
2
- import { trace, SpanStatusCode } from '@opentelemetry/api'
3
-
4
- export class ReactNavigationInstrumentation extends InstrumentationBase {
5
- private navigationRef: any = null
6
-
7
- constructor() {
8
- super('react-navigation', '1.0.0', {})
9
- }
10
-
11
- init(): void {
12
- // Initialize the instrumentation
13
- }
14
-
15
- setNavigationRef(ref: any) {
16
- this.navigationRef = ref
17
- this._setupNavigationListener()
18
- }
19
-
20
- private _setupNavigationListener() {
21
- if (!this.navigationRef) return
22
-
23
- // Listen to navigation state changes
24
- this.navigationRef.addListener('state', (e: any) => {
25
- this._recordNavigationEvent('state_change', e.data)
26
- })
27
-
28
- // Listen to focus events
29
- this.navigationRef.addListener('focus', (e: any) => {
30
- this._recordNavigationEvent('focus', e.data)
31
- })
32
-
33
- // Listen to blur events
34
- this.navigationRef.addListener('blur', (e: any) => {
35
- this._recordNavigationEvent('blur', e.data)
36
- })
37
- }
38
-
39
- private _recordNavigationEvent(eventType: string, data: any) {
40
- const span = trace.getTracer('navigation').startSpan(`Navigation.${eventType}`, {
41
- attributes: {
42
- 'navigation.system': 'ReactNavigation',
43
- 'navigation.operation': eventType,
44
- 'navigation.type': eventType,
45
- 'navigation.timestamp': Date.now(),
46
- },
47
- })
48
-
49
- if (data) {
50
- if (data.routeName) {
51
- span.setAttribute('navigation.route_name', data.routeName)
52
- }
53
- if (data.params) {
54
- span.setAttribute('navigation.params', JSON.stringify(data.params))
55
- }
56
- if (data.key) {
57
- span.setAttribute('navigation.key', data.key)
58
- }
59
- }
60
-
61
- span.setStatus({ code: SpanStatusCode.OK })
62
- span.end()
63
- }
64
-
65
- // Manual navigation tracking methods
66
- recordNavigate(routeName: string, params?: Record<string, any>) {
67
- const span = trace.getTracer('navigation').startSpan('Navigation.navigate', {
68
- attributes: {
69
- 'navigation.system': 'ReactNavigation',
70
- 'navigation.operation': 'navigate',
71
- 'navigation.route_name': routeName,
72
- 'navigation.timestamp': Date.now(),
73
- },
74
- })
75
-
76
- if (params) {
77
- span.setAttribute('navigation.params', JSON.stringify(params))
78
- }
79
-
80
- span.setStatus({ code: SpanStatusCode.OK })
81
- span.end()
82
- }
83
-
84
- recordGoBack() {
85
- const span = trace.getTracer('navigation').startSpan('Navigation.goBack', {
86
- attributes: {
87
- 'navigation.system': 'ReactNavigation',
88
- 'navigation.operation': 'goBack',
89
- 'navigation.timestamp': Date.now(),
90
- },
91
- })
92
-
93
- span.setStatus({ code: SpanStatusCode.OK })
94
- span.end()
95
- }
96
-
97
- recordReset(routes: any[]) {
98
- const span = trace.getTracer('navigation').startSpan('Navigation.reset', {
99
- attributes: {
100
- 'navigation.system': 'ReactNavigation',
101
- 'navigation.operation': 'reset',
102
- 'navigation.routes_count': routes.length,
103
- 'navigation.timestamp': Date.now(),
104
- },
105
- })
106
-
107
- if (routes.length > 0) {
108
- span.setAttribute('navigation.initial_route', routes[0].name)
109
- }
110
-
111
- span.setStatus({ code: SpanStatusCode.OK })
112
- span.end()
113
- }
114
- }
@@ -1,367 +0,0 @@
1
- import { SessionRecorderOptions, RecorderConfig, TracerReactNativeConfig } from './types'
2
- import { TracerReactNativeSDK } from './otel'
3
- import { RecorderReactNativeSDK } from './recorder'
4
- import { ApiService } from './services/api.service'
5
- import { StorageService } from './services/storage.service'
6
- import {
7
- SessionType,
8
- } from '@multiplayer-app/session-recorder-common'
9
-
10
- // Define these locally since they're not exported from common
11
- export enum SessionState {
12
- started = '2',
13
- paused = '1',
14
- stopped = '0',
15
- }
16
-
17
- export interface ISession {
18
- id: string
19
- shortId: string
20
- type: SessionType
21
- state: SessionState
22
- createdAt: string
23
- updatedAt: string
24
- tempApiKey?: string
25
- metadata?: Record<string, any>
26
- }
27
-
28
- export class SessionRecorder {
29
- private _configs: SessionRecorderOptions | null = null
30
- private _tracer: TracerReactNativeSDK
31
- private _recorder: RecorderReactNativeSDK
32
- private _apiService: ApiService
33
- private _storageService: StorageService
34
- private _session: ISession | null = null
35
- private _isInitialized = false
36
-
37
- constructor() {
38
- this._tracer = new TracerReactNativeSDK()
39
- this._recorder = new RecorderReactNativeSDK()
40
- this._apiService = new ApiService()
41
- this._storageService = new StorageService()
42
- }
43
-
44
- async init(options: SessionRecorderOptions): Promise<void> {
45
- if (this._isInitialized) {
46
- console.warn('SessionRecorder already initialized')
47
- return
48
- }
49
-
50
- this._configs = options
51
-
52
- // Initialize tracer
53
- const tracerConfig: TracerReactNativeConfig = {
54
- apiKey: options.apiKey,
55
- application: options.application,
56
- version: options.version,
57
- environment: options.environment,
58
- exporterEndpoint: options.exporterEndpoint,
59
- ignoreUrls: options.ignoreUrls,
60
- captureBody: options.captureBody,
61
- captureHeaders: options.captureHeaders,
62
- sampleTraceRatio: options.sampleTraceRatio,
63
- httpMasking: options.httpMasking,
64
- }
65
-
66
- this._tracer.init(tracerConfig)
67
-
68
- // Initialize recorder
69
- const recorderConfig: RecorderConfig = {
70
- apiKey: options.apiKey,
71
- apiBaseUrl: options.apiBaseUrl,
72
- recordScreen: options.recordScreen,
73
- recordGestures: options.recordGestures,
74
- recordNavigation: options.recordNavigation,
75
-
76
- }
77
-
78
- this._recorder.init(recorderConfig)
79
-
80
- // Initialize API service
81
- this._apiService.init(options)
82
-
83
- this._isInitialized = true
84
- console.log('SessionRecorder initialized successfully')
85
- }
86
-
87
- async start(sessionId?: string, sessionType: SessionType = SessionType.PLAIN): Promise<void> {
88
- if (!this._isInitialized) {
89
- throw new Error('SessionRecorder not initialized. Call init() first.')
90
- }
91
-
92
- if (!this._configs) {
93
- throw new Error('Configuration not found')
94
- }
95
-
96
- try {
97
- // Create or use existing session
98
- if (sessionId) {
99
- this._session = {
100
- id: sessionId,
101
- shortId: sessionId.substring(0, 8),
102
- type: sessionType,
103
- state: SessionState.started,
104
- createdAt: new Date().toISOString(),
105
- updatedAt: new Date().toISOString(),
106
- }
107
- } else {
108
- // Start new session via API
109
- this._session = await this._apiService.startSession({
110
- application: this._configs.application,
111
- version: this._configs.version,
112
- environment: this._configs.environment,
113
- })
114
- }
115
-
116
- if (!this._session) {
117
- throw new Error('Failed to create session')
118
- }
119
-
120
- // Set session ID in tracer
121
- this._tracer.setSessionId(this._session.id, this._session.type)
122
-
123
- // Start recording
124
- this._recorder.start(this._session.id, this._session.type)
125
-
126
- // Save session data
127
- await this._storageService.saveSessionId(this._session.id)
128
- await this._storageService.saveSessionType(this._session.type)
129
- await this._storageService.saveSessionState(this._session.state)
130
- await this._storageService.saveSessionObject(this._session)
131
-
132
- console.log('Session started:', this._session.id)
133
- } catch (error) {
134
- console.error('Failed to start session:', error)
135
- throw error
136
- }
137
- }
138
-
139
- async stop(): Promise<void> {
140
- if (!this._isInitialized || !this._session) {
141
- console.warn('Session not active')
142
- return
143
- }
144
-
145
- try {
146
- // Stop recording
147
- this._recorder.stop()
148
-
149
- // Update session state
150
- this._session.state = SessionState.stopped
151
- this._session.updatedAt = new Date().toISOString()
152
-
153
- // Save updated session
154
- await this._storageService.saveSessionState(this._session.state)
155
- await this._storageService.saveSessionObject(this._session)
156
-
157
- // Stop session via API
158
- await this._apiService.stopSession({
159
- sessionId: this._session.id,
160
- })
161
-
162
- console.log('Session stopped:', this._session.id)
163
- } catch (error) {
164
- console.error('Failed to stop session:', error)
165
- throw error
166
- }
167
- }
168
-
169
- async pause(): Promise<void> {
170
- if (!this._isInitialized || !this._session) {
171
- console.warn('Session not active')
172
- return
173
- }
174
-
175
- try {
176
- // Pause recording
177
- this._recorder.pause()
178
-
179
- // Update session state
180
- this._session.state = SessionState.paused
181
- this._session.updatedAt = new Date().toISOString()
182
-
183
- // Save updated session
184
- await this._storageService.saveSessionState(this._session.state)
185
- await this._storageService.saveSessionObject(this._session)
186
-
187
- console.log('Session paused:', this._session.id)
188
- } catch (error) {
189
- console.error('Failed to pause session:', error)
190
- throw error
191
- }
192
- }
193
-
194
- async resume(): Promise<void> {
195
- if (!this._isInitialized || !this._session) {
196
- console.warn('Session not active')
197
- return
198
- }
199
-
200
- try {
201
- // Resume recording
202
- this._recorder.resume()
203
-
204
- // Update session state
205
- this._session.state = SessionState.started
206
- this._session.updatedAt = new Date().toISOString()
207
-
208
- // Save updated session
209
- await this._storageService.saveSessionState(this._session.state)
210
- await this._storageService.saveSessionObject(this._session)
211
-
212
- console.log('Session resumed:', this._session.id)
213
- } catch (error) {
214
- console.error('Failed to resume session:', error)
215
- throw error
216
- }
217
- }
218
-
219
- async cancel(): Promise<void> {
220
- if (!this._isInitialized || !this._session) {
221
- console.warn('Session not active')
222
- return
223
- }
224
-
225
- try {
226
- // Stop recording
227
- this._recorder.stop()
228
-
229
- // Clear session data
230
- await this._storageService.clearSessionData()
231
-
232
- // Cancel session via API
233
- await this._apiService.stopSession({
234
- sessionId: this._session.id,
235
- })
236
-
237
- this._session = null
238
- console.log('Session cancelled')
239
- } catch (error) {
240
- console.error('Failed to cancel session:', error)
241
- throw error
242
- }
243
- }
244
-
245
- async save(): Promise<void> {
246
- if (!this._isInitialized || !this._session) {
247
- console.warn('Session not active')
248
- return
249
- }
250
-
251
- try {
252
- // Save session via API
253
- await this._apiService.saveSession(this._session.id)
254
-
255
- console.log('Session saved:', this._session.id)
256
- } catch (error) {
257
- console.error('Failed to save session:', error)
258
- throw error
259
- }
260
- }
261
-
262
- // Navigation methods
263
- setNavigationRef(ref: any): void {
264
- if (this._isInitialized) {
265
- this._tracer.setNavigationRef(ref)
266
- this._recorder.setNavigationRef(ref)
267
- }
268
- }
269
-
270
- // Gesture methods
271
- enableGestureTracking(): void {
272
- if (this._isInitialized) {
273
- this._tracer.enableGestureTracking()
274
- }
275
- }
276
-
277
- disableGestureTracking(): void {
278
- if (this._isInitialized) {
279
- this._tracer.disableGestureTracking()
280
- }
281
- }
282
-
283
- // Manual recording methods
284
- recordTap(x: number, y: number, target?: string): void {
285
- if (this._isInitialized) {
286
- this._tracer.recordTap(x, y, target)
287
- }
288
- }
289
-
290
- recordSwipe(direction: string, target?: string): void {
291
- if (this._isInitialized) {
292
- this._tracer.recordSwipe(direction, target)
293
- }
294
- }
295
-
296
- recordNavigate(routeName: string, params?: Record<string, any>): void {
297
- if (this._isInitialized) {
298
- this._tracer.recordNavigate(routeName, params)
299
- }
300
- }
301
-
302
- recordGoBack(): void {
303
- if (this._isInitialized) {
304
- this._tracer.recordGoBack()
305
- }
306
- }
307
-
308
- // Session attributes
309
- setSessionAttribute(key: string, value: any): void {
310
- if (this._session) {
311
- if (!this._session.metadata) {
312
- this._session.metadata = {}
313
- }
314
- this._session.metadata[key] = value
315
- this._session.updatedAt = new Date().toISOString()
316
- }
317
- }
318
-
319
- getSessionAttribute(key: string): any {
320
- return this._session?.metadata?.[key]
321
- }
322
-
323
- // Get current session
324
- getCurrentSession(): ISession | null {
325
- return this._session
326
- }
327
-
328
- // Get session data from storage
329
- async getStoredSessionData(): Promise<{
330
- sessionId: string | null
331
- sessionType: SessionType | null
332
- sessionState: SessionState | null
333
- sessionObject: ISession | null
334
- }> {
335
- return await this._storageService.getAllSessionData()
336
- }
337
-
338
- // Performance monitoring methods
339
- startTrace(name: string, attributes?: Record<string, any>): any {
340
- if (this._isInitialized) {
341
- return this._tracer.startTrace(name, attributes)
342
- }
343
- return null
344
- }
345
-
346
- endTrace(span: any, status?: any): void {
347
- if (this._isInitialized && span) {
348
- this._tracer.endTrace(span, status)
349
- }
350
- }
351
-
352
- captureException(error: Error, context?: Record<string, any>): void {
353
- if (this._isInitialized) {
354
- this._tracer.captureException(error, context)
355
- }
356
- }
357
-
358
- // Shutdown
359
- async shutdown(): Promise<void> {
360
- if (this._isInitialized) {
361
- await this.stop()
362
- await this._tracer.shutdown()
363
- this._isInitialized = false
364
- console.log('SessionRecorder shutdown')
365
- }
366
- }
367
- }