@multiplayer-app/session-recorder-react-native 1.3.36 → 2.0.17-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +13 -8
- package/src/NativeSessionRecorderModule.ts +4 -2
- package/src/NativeSessionRecorderModuleSpec.ts +4 -2
- package/src/NativeSessionRecorderNative.ts +1 -1
- package/src/index.ts +0 -1
- package/src/native/SessionRecorderNative.ts +22 -13
- package/src/otel/helpers.ts +5 -1
- package/src/otel/index.ts +1 -1
- package/src/otel/instrumentations/index.ts +22 -22
- package/src/patch/configs.ts +15 -10
- package/src/patch/fetch.ts +98 -89
- package/src/patch/index.ts +1 -1
- package/src/patch/xhr.ts +3 -4
- package/src/services/screenRecordingService.ts +7 -2
- package/src/services/storage.service.ts +4 -1
- package/src/session-recorder.ts +4 -0
- package/src/types/configs.ts +1 -2
- package/lib/module/NativeSessionRecorderModule.js +0 -5
- package/lib/module/NativeSessionRecorderModule.js.map +0 -1
- package/lib/module/NativeSessionRecorderModuleSpec.js +0 -5
- package/lib/module/NativeSessionRecorderModuleSpec.js.map +0 -1
- package/lib/module/NativeSessionRecorderNative.js +0 -5
- package/lib/module/NativeSessionRecorderNative.js.map +0 -1
- package/lib/module/components/ErrorBoundary.js +0 -32
- package/lib/module/components/ErrorBoundary.js.map +0 -1
- package/lib/module/components/ScreenRecorderView/ScreenRecorderView.js +0 -23
- package/lib/module/components/ScreenRecorderView/ScreenRecorderView.js.map +0 -1
- package/lib/module/components/ScreenRecorderView/index.js +0 -4
- package/lib/module/components/ScreenRecorderView/index.js.map +0 -1
- package/lib/module/components/SessionRecorderWidget/ErrorBanner.js +0 -64
- package/lib/module/components/SessionRecorderWidget/ErrorBanner.js.map +0 -1
- package/lib/module/components/SessionRecorderWidget/FinalPopover.js +0 -74
- package/lib/module/components/SessionRecorderWidget/FinalPopover.js.map +0 -1
- package/lib/module/components/SessionRecorderWidget/FloatingButton.js +0 -191
- package/lib/module/components/SessionRecorderWidget/FloatingButton.js.map +0 -1
- package/lib/module/components/SessionRecorderWidget/InitialPopover.js +0 -138
- package/lib/module/components/SessionRecorderWidget/InitialPopover.js.map +0 -1
- package/lib/module/components/SessionRecorderWidget/ModalContainer.js +0 -177
- package/lib/module/components/SessionRecorderWidget/ModalContainer.js.map +0 -1
- package/lib/module/components/SessionRecorderWidget/ModalHeader.js +0 -27
- package/lib/module/components/SessionRecorderWidget/ModalHeader.js.map +0 -1
- package/lib/module/components/SessionRecorderWidget/SessionRecorderWidget.js +0 -133
- package/lib/module/components/SessionRecorderWidget/SessionRecorderWidget.js.map +0 -1
- package/lib/module/components/SessionRecorderWidget/icons.js +0 -93
- package/lib/module/components/SessionRecorderWidget/icons.js.map +0 -1
- package/lib/module/components/SessionRecorderWidget/index.js +0 -5
- package/lib/module/components/SessionRecorderWidget/index.js.map +0 -1
- package/lib/module/components/SessionRecorderWidget/styles.js +0 -173
- package/lib/module/components/SessionRecorderWidget/styles.js.map +0 -1
- package/lib/module/components/index.js +0 -6
- package/lib/module/components/index.js.map +0 -1
- package/lib/module/config/constants.js +0 -47
- package/lib/module/config/constants.js.map +0 -1
- package/lib/module/config/defaults.js +0 -87
- package/lib/module/config/defaults.js.map +0 -1
- package/lib/module/config/index.js +0 -9
- package/lib/module/config/index.js.map +0 -1
- package/lib/module/config/masking.js +0 -35
- package/lib/module/config/masking.js.map +0 -1
- package/lib/module/config/session-recorder.js +0 -50
- package/lib/module/config/session-recorder.js.map +0 -1
- package/lib/module/config/validators.js +0 -28
- package/lib/module/config/validators.js.map +0 -1
- package/lib/module/config/widget.js +0 -35
- package/lib/module/config/widget.js.map +0 -1
- package/lib/module/context/SessionRecorderContext.js +0 -100
- package/lib/module/context/SessionRecorderContext.js.map +0 -1
- package/lib/module/context/SessionRecorderStore.js +0 -12
- package/lib/module/context/SessionRecorderStore.js.map +0 -1
- package/lib/module/context/createStore.js +0 -27
- package/lib/module/context/createStore.js.map +0 -1
- package/lib/module/context/useSessionRecorderStore.js +0 -45
- package/lib/module/context/useSessionRecorderStore.js.map +0 -1
- package/lib/module/context/useStoreSelector.js +0 -27
- package/lib/module/context/useStoreSelector.js.map +0 -1
- package/lib/module/index.js +0 -14
- package/lib/module/index.js.map +0 -1
- package/lib/module/native/SessionRecorderNative.js +0 -76
- package/lib/module/native/SessionRecorderNative.js.map +0 -1
- package/lib/module/native/index.js +0 -4
- package/lib/module/native/index.js.map +0 -1
- package/lib/module/otel/CrashBufferSpanProcessor.js +0 -42
- package/lib/module/otel/CrashBufferSpanProcessor.js.map +0 -1
- package/lib/module/otel/helpers.js +0 -218
- package/lib/module/otel/helpers.js.map +0 -1
- package/lib/module/otel/index.js +0 -202
- package/lib/module/otel/index.js.map +0 -1
- package/lib/module/otel/instrumentations/index.js +0 -122
- package/lib/module/otel/instrumentations/index.js.map +0 -1
- package/lib/module/package.json +0 -1
- package/lib/module/patch/configs.js +0 -18
- package/lib/module/patch/configs.js.map +0 -1
- package/lib/module/patch/fetch.js +0 -224
- package/lib/module/patch/fetch.js.map +0 -1
- package/lib/module/patch/index.js +0 -6
- package/lib/module/patch/index.js.map +0 -1
- package/lib/module/patch/xhr.js +0 -100
- package/lib/module/patch/xhr.js.map +0 -1
- package/lib/module/recorder/gestureRecorder.js +0 -641
- package/lib/module/recorder/gestureRecorder.js.map +0 -1
- package/lib/module/recorder/index.js +0 -176
- package/lib/module/recorder/index.js.map +0 -1
- package/lib/module/recorder/navigationRecorder.js +0 -238
- package/lib/module/recorder/navigationRecorder.js.map +0 -1
- package/lib/module/recorder/screenRecorder.js +0 -527
- package/lib/module/recorder/screenRecorder.js.map +0 -1
- package/lib/module/services/api.service.js +0 -166
- package/lib/module/services/api.service.js.map +0 -1
- package/lib/module/services/crashBuffer.service.js +0 -280
- package/lib/module/services/crashBuffer.service.js.map +0 -1
- package/lib/module/services/network.service.js +0 -178
- package/lib/module/services/network.service.js.map +0 -1
- package/lib/module/services/screenRecordingService.js +0 -107
- package/lib/module/services/screenRecordingService.js.map +0 -1
- package/lib/module/services/socket.service.js +0 -186
- package/lib/module/services/socket.service.js.map +0 -1
- package/lib/module/services/storage.service.js +0 -178
- package/lib/module/services/storage.service.js.map +0 -1
- package/lib/module/session-recorder.js +0 -750
- package/lib/module/session-recorder.js.map +0 -1
- package/lib/module/types/configs.js +0 -4
- package/lib/module/types/configs.js.map +0 -1
- package/lib/module/types/expo-constants.d.js +0 -2
- package/lib/module/types/expo-constants.d.js.map +0 -1
- package/lib/module/types/index.js +0 -10
- package/lib/module/types/index.js.map +0 -1
- package/lib/module/types/session-recorder.js +0 -68
- package/lib/module/types/session-recorder.js.map +0 -1
- package/lib/module/utils/app-metadata.js +0 -28
- package/lib/module/utils/app-metadata.js.map +0 -1
- package/lib/module/utils/constants.optional.expo.js +0 -6
- package/lib/module/utils/constants.optional.expo.js.map +0 -1
- package/lib/module/utils/constants.optional.js +0 -8
- package/lib/module/utils/constants.optional.js.map +0 -1
- package/lib/module/utils/index.js +0 -11
- package/lib/module/utils/index.js.map +0 -1
- package/lib/module/utils/logger.js +0 -185
- package/lib/module/utils/logger.js.map +0 -1
- package/lib/module/utils/platform.js +0 -340
- package/lib/module/utils/platform.js.map +0 -1
- package/lib/module/utils/request-utils.js +0 -58
- package/lib/module/utils/request-utils.js.map +0 -1
- package/lib/module/utils/rrweb-events.js +0 -276
- package/lib/module/utils/rrweb-events.js.map +0 -1
- package/lib/module/utils/session.js +0 -21
- package/lib/module/utils/session.js.map +0 -1
- package/lib/module/utils/shallowEqual.js +0 -17
- package/lib/module/utils/shallowEqual.js.map +0 -1
- package/lib/module/utils/time.js +0 -17
- package/lib/module/utils/time.js.map +0 -1
- package/lib/module/utils/type-utils.js +0 -69
- package/lib/module/utils/type-utils.js.map +0 -1
- package/lib/module/version.js +0 -4
- package/lib/module/version.js.map +0 -1
- package/lib/typescript/package.json +0 -1
- package/lib/typescript/src/NativeSessionRecorderModule.d.ts +0 -25
- package/lib/typescript/src/NativeSessionRecorderModule.d.ts.map +0 -1
- package/lib/typescript/src/NativeSessionRecorderModuleSpec.d.ts +0 -25
- package/lib/typescript/src/NativeSessionRecorderModuleSpec.d.ts.map +0 -1
- package/lib/typescript/src/NativeSessionRecorderNative.d.ts +0 -25
- package/lib/typescript/src/NativeSessionRecorderNative.d.ts.map +0 -1
- package/lib/typescript/src/components/ErrorBoundary.d.ts +0 -16
- package/lib/typescript/src/components/ErrorBoundary.d.ts.map +0 -1
- package/lib/typescript/src/components/ScreenRecorderView/ScreenRecorderView.d.ts +0 -6
- package/lib/typescript/src/components/ScreenRecorderView/ScreenRecorderView.d.ts.map +0 -1
- package/lib/typescript/src/components/ScreenRecorderView/index.d.ts +0 -2
- package/lib/typescript/src/components/ScreenRecorderView/index.d.ts.map +0 -1
- package/lib/typescript/src/components/SessionRecorderWidget/ErrorBanner.d.ts +0 -8
- package/lib/typescript/src/components/SessionRecorderWidget/ErrorBanner.d.ts.map +0 -1
- package/lib/typescript/src/components/SessionRecorderWidget/FinalPopover.d.ts +0 -13
- package/lib/typescript/src/components/SessionRecorderWidget/FinalPopover.d.ts.map +0 -1
- package/lib/typescript/src/components/SessionRecorderWidget/FloatingButton.d.ts +0 -9
- package/lib/typescript/src/components/SessionRecorderWidget/FloatingButton.d.ts.map +0 -1
- package/lib/typescript/src/components/SessionRecorderWidget/InitialPopover.d.ts +0 -17
- package/lib/typescript/src/components/SessionRecorderWidget/InitialPopover.d.ts.map +0 -1
- package/lib/typescript/src/components/SessionRecorderWidget/ModalContainer.d.ts +0 -9
- package/lib/typescript/src/components/SessionRecorderWidget/ModalContainer.d.ts.map +0 -1
- package/lib/typescript/src/components/SessionRecorderWidget/ModalHeader.d.ts +0 -7
- package/lib/typescript/src/components/SessionRecorderWidget/ModalHeader.d.ts.map +0 -1
- package/lib/typescript/src/components/SessionRecorderWidget/SessionRecorderWidget.d.ts +0 -6
- package/lib/typescript/src/components/SessionRecorderWidget/SessionRecorderWidget.d.ts.map +0 -1
- package/lib/typescript/src/components/SessionRecorderWidget/icons.d.ts +0 -12
- package/lib/typescript/src/components/SessionRecorderWidget/icons.d.ts.map +0 -1
- package/lib/typescript/src/components/SessionRecorderWidget/index.d.ts +0 -3
- package/lib/typescript/src/components/SessionRecorderWidget/index.d.ts.map +0 -1
- package/lib/typescript/src/components/SessionRecorderWidget/styles.d.ts +0 -166
- package/lib/typescript/src/components/SessionRecorderWidget/styles.d.ts.map +0 -1
- package/lib/typescript/src/components/index.d.ts +0 -4
- package/lib/typescript/src/components/index.d.ts.map +0 -1
- package/lib/typescript/src/config/constants.d.ts +0 -22
- package/lib/typescript/src/config/constants.d.ts.map +0 -1
- package/lib/typescript/src/config/defaults.d.ts +0 -5
- package/lib/typescript/src/config/defaults.d.ts.map +0 -1
- package/lib/typescript/src/config/index.d.ts +0 -6
- package/lib/typescript/src/config/index.d.ts.map +0 -1
- package/lib/typescript/src/config/masking.d.ts +0 -3
- package/lib/typescript/src/config/masking.d.ts.map +0 -1
- package/lib/typescript/src/config/session-recorder.d.ts +0 -3
- package/lib/typescript/src/config/session-recorder.d.ts.map +0 -1
- package/lib/typescript/src/config/validators.d.ts +0 -11
- package/lib/typescript/src/config/validators.d.ts.map +0 -1
- package/lib/typescript/src/config/widget.d.ts +0 -10
- package/lib/typescript/src/config/widget.d.ts.map +0 -1
- package/lib/typescript/src/context/SessionRecorderContext.d.ts +0 -22
- package/lib/typescript/src/context/SessionRecorderContext.d.ts.map +0 -1
- package/lib/typescript/src/context/SessionRecorderStore.d.ts +0 -13
- package/lib/typescript/src/context/SessionRecorderStore.d.ts.map +0 -1
- package/lib/typescript/src/context/createStore.d.ts +0 -9
- package/lib/typescript/src/context/createStore.d.ts.map +0 -1
- package/lib/typescript/src/context/useSessionRecorderStore.d.ts +0 -29
- package/lib/typescript/src/context/useSessionRecorderStore.d.ts.map +0 -1
- package/lib/typescript/src/context/useStoreSelector.d.ts +0 -5
- package/lib/typescript/src/context/useStoreSelector.d.ts.map +0 -1
- package/lib/typescript/src/index.d.ts +0 -9
- package/lib/typescript/src/index.d.ts.map +0 -1
- package/lib/typescript/src/native/SessionRecorderNative.d.ts +0 -29
- package/lib/typescript/src/native/SessionRecorderNative.d.ts.map +0 -1
- package/lib/typescript/src/native/index.d.ts +0 -2
- package/lib/typescript/src/native/index.d.ts.map +0 -1
- package/lib/typescript/src/otel/CrashBufferSpanProcessor.d.ts +0 -17
- package/lib/typescript/src/otel/CrashBufferSpanProcessor.d.ts.map +0 -1
- package/lib/typescript/src/otel/helpers.d.ts +0 -46
- package/lib/typescript/src/otel/helpers.d.ts.map +0 -1
- package/lib/typescript/src/otel/index.d.ts +0 -33
- package/lib/typescript/src/otel/index.d.ts.map +0 -1
- package/lib/typescript/src/otel/instrumentations/index.d.ts +0 -5
- package/lib/typescript/src/otel/instrumentations/index.d.ts.map +0 -1
- package/lib/typescript/src/patch/configs.d.ts +0 -9
- package/lib/typescript/src/patch/configs.d.ts.map +0 -1
- package/lib/typescript/src/patch/fetch.d.ts +0 -2
- package/lib/typescript/src/patch/fetch.d.ts.map +0 -1
- package/lib/typescript/src/patch/index.d.ts +0 -4
- package/lib/typescript/src/patch/index.d.ts.map +0 -1
- package/lib/typescript/src/patch/xhr.d.ts +0 -2
- package/lib/typescript/src/patch/xhr.d.ts.map +0 -1
- package/lib/typescript/src/recorder/gestureRecorder.d.ts +0 -66
- package/lib/typescript/src/recorder/gestureRecorder.d.ts.map +0 -1
- package/lib/typescript/src/recorder/index.d.ts +0 -79
- package/lib/typescript/src/recorder/index.d.ts.map +0 -1
- package/lib/typescript/src/recorder/navigationRecorder.d.ts +0 -29
- package/lib/typescript/src/recorder/navigationRecorder.d.ts.map +0 -1
- package/lib/typescript/src/recorder/screenRecorder.d.ts +0 -127
- package/lib/typescript/src/recorder/screenRecorder.d.ts.map +0 -1
- package/lib/typescript/src/services/api.service.d.ts +0 -116
- package/lib/typescript/src/services/api.service.d.ts.map +0 -1
- package/lib/typescript/src/services/crashBuffer.service.d.ts +0 -27
- package/lib/typescript/src/services/crashBuffer.service.d.ts.map +0 -1
- package/lib/typescript/src/services/network.service.d.ts +0 -47
- package/lib/typescript/src/services/network.service.d.ts.map +0 -1
- package/lib/typescript/src/services/screenRecordingService.d.ts +0 -48
- package/lib/typescript/src/services/screenRecordingService.d.ts.map +0 -1
- package/lib/typescript/src/services/socket.service.d.ts +0 -44
- package/lib/typescript/src/services/socket.service.d.ts.map +0 -1
- package/lib/typescript/src/services/storage.service.d.ts +0 -47
- package/lib/typescript/src/services/storage.service.d.ts.map +0 -1
- package/lib/typescript/src/session-recorder.d.ts +0 -191
- package/lib/typescript/src/session-recorder.d.ts.map +0 -1
- package/lib/typescript/src/types/configs.d.ts +0 -92
- package/lib/typescript/src/types/configs.d.ts.map +0 -1
- package/lib/typescript/src/types/index.d.ts +0 -21
- package/lib/typescript/src/types/index.d.ts.map +0 -1
- package/lib/typescript/src/types/session-recorder.d.ts +0 -367
- package/lib/typescript/src/types/session-recorder.d.ts.map +0 -1
- package/lib/typescript/src/utils/app-metadata.d.ts +0 -17
- package/lib/typescript/src/utils/app-metadata.d.ts.map +0 -1
- package/lib/typescript/src/utils/constants.optional.d.ts +0 -22
- package/lib/typescript/src/utils/constants.optional.d.ts.map +0 -1
- package/lib/typescript/src/utils/constants.optional.expo.d.ts +0 -4
- package/lib/typescript/src/utils/constants.optional.expo.d.ts.map +0 -1
- package/lib/typescript/src/utils/index.d.ts +0 -8
- package/lib/typescript/src/utils/index.d.ts.map +0 -1
- package/lib/typescript/src/utils/logger.d.ts +0 -108
- package/lib/typescript/src/utils/logger.d.ts.map +0 -1
- package/lib/typescript/src/utils/platform.d.ts +0 -58
- package/lib/typescript/src/utils/platform.d.ts.map +0 -1
- package/lib/typescript/src/utils/request-utils.d.ts +0 -22
- package/lib/typescript/src/utils/request-utils.d.ts.map +0 -1
- package/lib/typescript/src/utils/rrweb-events.d.ts +0 -67
- package/lib/typescript/src/utils/rrweb-events.d.ts.map +0 -1
- package/lib/typescript/src/utils/session.d.ts +0 -7
- package/lib/typescript/src/utils/session.d.ts.map +0 -1
- package/lib/typescript/src/utils/shallowEqual.d.ts +0 -2
- package/lib/typescript/src/utils/shallowEqual.d.ts.map +0 -1
- package/lib/typescript/src/utils/time.d.ts +0 -5
- package/lib/typescript/src/utils/time.d.ts.map +0 -1
- package/lib/typescript/src/utils/type-utils.d.ts +0 -17
- package/lib/typescript/src/utils/type-utils.d.ts.map +0 -1
- package/lib/typescript/src/version.d.ts +0 -2
- package/lib/typescript/src/version.d.ts.map +0 -1
|
@@ -1,750 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import { SessionType } from '@multiplayer-app/session-recorder-common';
|
|
4
|
-
import { Observable } from 'lib0/observable';
|
|
5
|
-
import { TracerReactNativeSDK } from "./otel/index.js";
|
|
6
|
-
import { RecorderReactNativeSDK } from "./recorder/index.js";
|
|
7
|
-
import { logger } from "./utils/index.js";
|
|
8
|
-
import { SessionState } from "./types/index.js";
|
|
9
|
-
import { SESSION_STOPPED_EVENT, REMOTE_SESSION_RECORDING_START, REMOTE_SESSION_RECORDING_STOP, SESSION_SAVE_BUFFER_EVENT } from "./config/index.js";
|
|
10
|
-
import { getFormattedDate, isSessionActive, getNavigatorInfo } from "./utils/index.js";
|
|
11
|
-
import { setShouldRecordHttpData, setMaxCapturingHttpPayloadSize } from "./patch/index.js";
|
|
12
|
-
import { BASE_CONFIG, getSessionRecorderConfig } from "./config/index.js";
|
|
13
|
-
import { StorageService } from "./services/storage.service.js";
|
|
14
|
-
import { NetworkService } from "./services/network.service.js";
|
|
15
|
-
import { CrashBufferService } from "./services/crashBuffer.service.js";
|
|
16
|
-
import { ApiService } from "./services/api.service.js";
|
|
17
|
-
import { SocketService } from "./services/socket.service.js";
|
|
18
|
-
class SessionRecorder extends Observable {
|
|
19
|
-
_apiService = new ApiService();
|
|
20
|
-
_socketService = new SocketService();
|
|
21
|
-
_tracer = new TracerReactNativeSDK();
|
|
22
|
-
_recorder = new RecorderReactNativeSDK();
|
|
23
|
-
_storageService = StorageService.getInstance();
|
|
24
|
-
_networkService = NetworkService.getInstance();
|
|
25
|
-
_crashBuffer = CrashBufferService.getInstance();
|
|
26
|
-
_isFlushingBuffer = false;
|
|
27
|
-
_startRequestController = null;
|
|
28
|
-
|
|
29
|
-
// Whether the session recorder is initialized
|
|
30
|
-
_isInitialized = false;
|
|
31
|
-
get isInitialized() {
|
|
32
|
-
return this._isInitialized;
|
|
33
|
-
}
|
|
34
|
-
set isInitialized(isInitialized) {
|
|
35
|
-
this._isInitialized = isInitialized;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Session ID and state are stored in AsyncStorage
|
|
39
|
-
_sessionId = null;
|
|
40
|
-
get sessionId() {
|
|
41
|
-
return this._sessionId;
|
|
42
|
-
}
|
|
43
|
-
set sessionId(sessionId) {
|
|
44
|
-
this._sessionId = sessionId;
|
|
45
|
-
if (sessionId) {
|
|
46
|
-
this._storageService.saveSessionId(sessionId);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
_sessionType = SessionType.MANUAL;
|
|
50
|
-
get sessionType() {
|
|
51
|
-
return this._sessionType;
|
|
52
|
-
}
|
|
53
|
-
set sessionType(sessionType) {
|
|
54
|
-
this._sessionType = sessionType;
|
|
55
|
-
this._storageService.saveSessionType(sessionType);
|
|
56
|
-
}
|
|
57
|
-
get continuousRecording() {
|
|
58
|
-
return this.sessionType === SessionType.CONTINUOUS;
|
|
59
|
-
}
|
|
60
|
-
_sessionState = null;
|
|
61
|
-
get sessionState() {
|
|
62
|
-
return this._sessionState || SessionState.stopped;
|
|
63
|
-
}
|
|
64
|
-
set sessionState(state) {
|
|
65
|
-
this._sessionState = state;
|
|
66
|
-
this.emit('state-change', [state || SessionState.stopped, this.sessionType]);
|
|
67
|
-
if (state) {
|
|
68
|
-
this._storageService.saveSessionState(state);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
_session = null;
|
|
72
|
-
get session() {
|
|
73
|
-
return this._session;
|
|
74
|
-
}
|
|
75
|
-
set session(session) {
|
|
76
|
-
this._session = session;
|
|
77
|
-
if (session) {
|
|
78
|
-
this._storageService.saveSessionObject(session);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
_sessionAttributes = null;
|
|
82
|
-
get sessionAttributes() {
|
|
83
|
-
return this._sessionAttributes || {};
|
|
84
|
-
}
|
|
85
|
-
set sessionAttributes(attributes) {
|
|
86
|
-
this._sessionAttributes = attributes;
|
|
87
|
-
}
|
|
88
|
-
_userAttributes = null;
|
|
89
|
-
get userAttributes() {
|
|
90
|
-
return this._userAttributes;
|
|
91
|
-
}
|
|
92
|
-
set userAttributes(userAttributes) {
|
|
93
|
-
this._userAttributes = userAttributes;
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Error message getter and setter
|
|
97
|
-
*/
|
|
98
|
-
get error() {
|
|
99
|
-
return this._error || '';
|
|
100
|
-
}
|
|
101
|
-
set error(v) {
|
|
102
|
-
this._error = v;
|
|
103
|
-
}
|
|
104
|
-
_error = '';
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* React Native doesn't have HTML elements, so we return null
|
|
108
|
-
*/
|
|
109
|
-
get sessionWidgetButtonElement() {
|
|
110
|
-
return null;
|
|
111
|
-
}
|
|
112
|
-
get config() {
|
|
113
|
-
return this._configs;
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Initialize debugger with default or custom configurations
|
|
117
|
-
*/
|
|
118
|
-
constructor() {
|
|
119
|
-
super();
|
|
120
|
-
this._configs = BASE_CONFIG;
|
|
121
|
-
// Initialize with stored session data if available
|
|
122
|
-
StorageService.initialize();
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Capture an exception manually and send it as an error trace.
|
|
127
|
-
*/
|
|
128
|
-
captureException(error, errorInfo) {
|
|
129
|
-
try {
|
|
130
|
-
const normalizedError = this._normalizeError(error);
|
|
131
|
-
const normalizedErrorInfo = this._normalizeErrorInfo(errorInfo);
|
|
132
|
-
this._tracer.captureException(normalizedError, normalizedErrorInfo);
|
|
133
|
-
} catch (e) {
|
|
134
|
-
this.error = e?.message || 'Failed to capture exception';
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
async _flushBuffer(sessionId) {
|
|
138
|
-
if (!sessionId || !this._crashBuffer || this._isFlushingBuffer || !this._configs?.buffering?.enabled || this.sessionState !== SessionState.stopped) {
|
|
139
|
-
return null;
|
|
140
|
-
}
|
|
141
|
-
this._isFlushingBuffer = true;
|
|
142
|
-
try {
|
|
143
|
-
const {
|
|
144
|
-
events,
|
|
145
|
-
spans,
|
|
146
|
-
startedAt,
|
|
147
|
-
stoppedAt
|
|
148
|
-
} = await this._crashBuffer.snapshot();
|
|
149
|
-
if (events.length === 0 && spans.length === 0) {
|
|
150
|
-
return null;
|
|
151
|
-
}
|
|
152
|
-
await Promise.all([this._tracer.exportTraces(spans.map(s => s.span)), this._apiService.exportEvents(sessionId, {
|
|
153
|
-
events: events.map(e => e.event)
|
|
154
|
-
}), this._apiService.updateSessionAttributes(sessionId, {
|
|
155
|
-
startedAt: new Date(startedAt).toISOString(),
|
|
156
|
-
stoppedAt: new Date(stoppedAt).toISOString(),
|
|
157
|
-
sessionAttributes: this.sessionAttributes,
|
|
158
|
-
resourceAttributes: getNavigatorInfo(),
|
|
159
|
-
userAttributes: this._userAttributes || undefined
|
|
160
|
-
})]);
|
|
161
|
-
} catch (_e) {
|
|
162
|
-
// swallow: flush is best-effort; never throw into app code
|
|
163
|
-
} finally {
|
|
164
|
-
await this._crashBuffer.clear();
|
|
165
|
-
this._isFlushingBuffer = false;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
async _createExceptionSession(span) {
|
|
169
|
-
try {
|
|
170
|
-
const session = await this._apiService.createErrorSession({
|
|
171
|
-
span
|
|
172
|
-
});
|
|
173
|
-
if (session?._id) {
|
|
174
|
-
void this._flushBuffer(session._id);
|
|
175
|
-
}
|
|
176
|
-
} catch (_ignored) {
|
|
177
|
-
// best-effort
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
async _loadStoredSessionData() {
|
|
181
|
-
try {
|
|
182
|
-
await StorageService.initialize();
|
|
183
|
-
const storedData = await this._storageService.getAllSessionData();
|
|
184
|
-
if (isSessionActive(storedData.sessionObject, storedData.sessionType)) {
|
|
185
|
-
this.session = storedData.sessionObject;
|
|
186
|
-
this.sessionId = storedData.sessionId;
|
|
187
|
-
this.sessionType = storedData.sessionType || SessionType.MANUAL;
|
|
188
|
-
this.sessionState = storedData.sessionState;
|
|
189
|
-
} else {
|
|
190
|
-
this.session = null;
|
|
191
|
-
this.sessionId = null;
|
|
192
|
-
this.sessionState = null;
|
|
193
|
-
this.sessionType = SessionType.MANUAL;
|
|
194
|
-
}
|
|
195
|
-
} catch (error) {
|
|
196
|
-
logger.error('SessionRecorder', 'Failed to load stored session data', error);
|
|
197
|
-
this.session = null;
|
|
198
|
-
this.sessionId = null;
|
|
199
|
-
this.sessionState = null;
|
|
200
|
-
this.sessionType = SessionType.MANUAL;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
* Initialize the session debugger
|
|
206
|
-
* @param configs - custom configurations for session debugger
|
|
207
|
-
*/
|
|
208
|
-
async init(configs) {
|
|
209
|
-
if (this._isInitialized) return;
|
|
210
|
-
this._isInitialized = true;
|
|
211
|
-
this._configs = getSessionRecorderConfig({
|
|
212
|
-
...this._configs,
|
|
213
|
-
...configs
|
|
214
|
-
});
|
|
215
|
-
logger.configure(this._configs.logger);
|
|
216
|
-
await this._loadStoredSessionData();
|
|
217
|
-
setMaxCapturingHttpPayloadSize(this._configs.maxCapturingHttpPayloadSize);
|
|
218
|
-
setShouldRecordHttpData(this._configs.captureBody, this._configs.captureHeaders);
|
|
219
|
-
|
|
220
|
-
// Crash buffer wiring (RN): set BEFORE tracer init so early spans don't get exported.
|
|
221
|
-
const bufferEnabled = Boolean(this._configs.buffering?.enabled);
|
|
222
|
-
const windowMs = Math.max(10_000, (this._configs.buffering?.windowMinutes || 0.5) * 60 * 1000);
|
|
223
|
-
this._tracer.setCrashBuffer(bufferEnabled ? this._crashBuffer : undefined, windowMs);
|
|
224
|
-
this._tracer.init(this._configs);
|
|
225
|
-
this._apiService.init(this._configs);
|
|
226
|
-
this._socketService.init({
|
|
227
|
-
apiKey: this._configs.apiKey,
|
|
228
|
-
socketUrl: this._configs.apiBaseUrl,
|
|
229
|
-
keepAlive: this._configs.useWebsocket,
|
|
230
|
-
clientId: this._tracer.clientId
|
|
231
|
-
});
|
|
232
|
-
this._recorder.init(this._configs, this._socketService, bufferEnabled ? this._crashBuffer : undefined, {
|
|
233
|
-
enabled: bufferEnabled,
|
|
234
|
-
windowMs
|
|
235
|
-
});
|
|
236
|
-
this._crashBuffer.on('error-span-appended', payload => {
|
|
237
|
-
if (!payload.span || this.sessionId || this.sessionState !== SessionState.stopped) {
|
|
238
|
-
return;
|
|
239
|
-
}
|
|
240
|
-
this._createExceptionSession(payload.span);
|
|
241
|
-
});
|
|
242
|
-
await this._networkService.init();
|
|
243
|
-
this._setupNetworkCallbacks();
|
|
244
|
-
this._registerSocketServiceListeners();
|
|
245
|
-
if (this.sessionId && (this.sessionState === SessionState.started || this.sessionState === SessionState.paused)) {
|
|
246
|
-
this._start();
|
|
247
|
-
} else {
|
|
248
|
-
this._startBufferOnlyRecording();
|
|
249
|
-
}
|
|
250
|
-
this.emit('init', []);
|
|
251
|
-
}
|
|
252
|
-
_startBufferOnlyRecording() {
|
|
253
|
-
if (this.sessionId || !this._crashBuffer || !this._configs?.buffering?.enabled || this.sessionState !== SessionState.stopped) {
|
|
254
|
-
return;
|
|
255
|
-
}
|
|
256
|
-
const windowMs = Math.max(10_000, (this._configs.buffering.windowMinutes || 0.5) * 60 * 1000);
|
|
257
|
-
|
|
258
|
-
// Wire buffer into tracer + recorder (only used when sessionId is null).
|
|
259
|
-
this._tracer.setCrashBuffer(this._crashBuffer, windowMs);
|
|
260
|
-
this._recorder.init(this._configs, this._socketService, this._crashBuffer, {
|
|
261
|
-
enabled: true,
|
|
262
|
-
windowMs
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
// Start capturing events without an active debug session id.
|
|
266
|
-
try {
|
|
267
|
-
this._recorder.stop();
|
|
268
|
-
} catch (_e) {}
|
|
269
|
-
this._recorder.start(null, SessionType.MANUAL);
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
/**
|
|
273
|
-
* Register socket service event listeners
|
|
274
|
-
*/
|
|
275
|
-
_registerSocketServiceListeners() {
|
|
276
|
-
this._socketService.on(SESSION_STOPPED_EVENT, () => {
|
|
277
|
-
this._stop();
|
|
278
|
-
this._clearSession();
|
|
279
|
-
});
|
|
280
|
-
this._socketService.on(REMOTE_SESSION_RECORDING_START, payload => {
|
|
281
|
-
logger.info('SessionRecorder', 'Remote session recording started', payload);
|
|
282
|
-
if (this.sessionState === SessionState.stopped) {
|
|
283
|
-
this.start();
|
|
284
|
-
}
|
|
285
|
-
});
|
|
286
|
-
this._socketService.on(REMOTE_SESSION_RECORDING_STOP, payload => {
|
|
287
|
-
logger.info('SessionRecorder', 'Remote session recording stopped', payload);
|
|
288
|
-
if (this.sessionState !== SessionState.stopped) {
|
|
289
|
-
this.stop();
|
|
290
|
-
}
|
|
291
|
-
});
|
|
292
|
-
this._socketService.on(SESSION_SAVE_BUFFER_EVENT, payload => {
|
|
293
|
-
this._flushBuffer(payload?.debugSession?._id);
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
/**
|
|
298
|
-
* Setup network state change callbacks
|
|
299
|
-
*/
|
|
300
|
-
_setupNetworkCallbacks() {
|
|
301
|
-
this._networkService.addCallback(state => {
|
|
302
|
-
if (!state.isConnected && this.sessionState === SessionState.started) {
|
|
303
|
-
logger.info('SessionRecorder', 'Network went offline - pausing session recording');
|
|
304
|
-
this.pause();
|
|
305
|
-
} else if (state.isConnected && this.sessionState === SessionState.paused) {
|
|
306
|
-
logger.info('SessionRecorder', 'Network came back online - resuming session recording');
|
|
307
|
-
this.resume();
|
|
308
|
-
}
|
|
309
|
-
});
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
/**
|
|
313
|
-
* Start a new session
|
|
314
|
-
* @param type - the type of session to start
|
|
315
|
-
* @param session - the session to start
|
|
316
|
-
*/
|
|
317
|
-
async start(type = SessionType.MANUAL, session) {
|
|
318
|
-
this._checkOperation('start');
|
|
319
|
-
|
|
320
|
-
// Check if offline - don't start recording if offline
|
|
321
|
-
if (!this._networkService.isOnline()) {
|
|
322
|
-
logger.warn('SessionRecorder', 'Cannot start session recording - device is offline');
|
|
323
|
-
throw new Error('Cannot start session recording while offline');
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
// If continuous recording is disabled, force plain mode
|
|
327
|
-
if (type === SessionType.CONTINUOUS && !this._configs?.showContinuousRecording) {
|
|
328
|
-
type = SessionType.MANUAL;
|
|
329
|
-
}
|
|
330
|
-
logger.info('SessionRecorder', 'Starting session with type:', type);
|
|
331
|
-
this.sessionType = type;
|
|
332
|
-
this._startRequestController = new AbortController();
|
|
333
|
-
if (session) {
|
|
334
|
-
this._setupSessionAndStart(session, true);
|
|
335
|
-
} else {
|
|
336
|
-
await this._createSessionAndStart();
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
/**
|
|
341
|
-
* Stop the current session with an optional comment
|
|
342
|
-
* @param comment - user-provided comment to include in session session attributes
|
|
343
|
-
*/
|
|
344
|
-
async stop(comment) {
|
|
345
|
-
try {
|
|
346
|
-
this._checkOperation('stop');
|
|
347
|
-
this._stop();
|
|
348
|
-
if (this.continuousRecording) {
|
|
349
|
-
await this._apiService.stopContinuousDebugSession(this.sessionId);
|
|
350
|
-
this.sessionType = SessionType.MANUAL;
|
|
351
|
-
} else {
|
|
352
|
-
const request = {
|
|
353
|
-
sessionAttributes: {
|
|
354
|
-
comment
|
|
355
|
-
},
|
|
356
|
-
stoppedAt: Date.now()
|
|
357
|
-
};
|
|
358
|
-
await this._apiService.stopSession(this.sessionId, request);
|
|
359
|
-
}
|
|
360
|
-
this._clearSession();
|
|
361
|
-
} catch (error) {
|
|
362
|
-
this.error = error.message;
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
/**
|
|
367
|
-
* Pause the current session
|
|
368
|
-
*/
|
|
369
|
-
async pause() {
|
|
370
|
-
try {
|
|
371
|
-
this._checkOperation('pause');
|
|
372
|
-
this._pause();
|
|
373
|
-
} catch (error) {
|
|
374
|
-
this.error = error.message;
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
/**
|
|
379
|
-
* Resume the current session
|
|
380
|
-
*/
|
|
381
|
-
async resume() {
|
|
382
|
-
try {
|
|
383
|
-
this._checkOperation('resume');
|
|
384
|
-
this._resume();
|
|
385
|
-
} catch (error) {
|
|
386
|
-
this.error = error.message;
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
/**
|
|
391
|
-
* Cancel the current session
|
|
392
|
-
*/
|
|
393
|
-
async cancel() {
|
|
394
|
-
try {
|
|
395
|
-
this._checkOperation('cancel');
|
|
396
|
-
this._stop();
|
|
397
|
-
if (this.continuousRecording) {
|
|
398
|
-
await this._apiService.stopContinuousDebugSession(this.sessionId);
|
|
399
|
-
this.sessionType = SessionType.MANUAL;
|
|
400
|
-
} else {
|
|
401
|
-
await this._apiService.cancelSession(this.sessionId);
|
|
402
|
-
}
|
|
403
|
-
this._clearSession();
|
|
404
|
-
} catch (error) {
|
|
405
|
-
this.error = error.message;
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
/**
|
|
410
|
-
* Save the continuous recording session
|
|
411
|
-
*/
|
|
412
|
-
async save() {
|
|
413
|
-
try {
|
|
414
|
-
this._checkOperation('save');
|
|
415
|
-
if (!this.continuousRecording || !this._configs?.showContinuousRecording) {
|
|
416
|
-
return;
|
|
417
|
-
}
|
|
418
|
-
const res = await this._apiService.saveContinuousDebugSession(this.sessionId, {
|
|
419
|
-
sessionAttributes: this.sessionAttributes,
|
|
420
|
-
resourceAttributes: getNavigatorInfo(),
|
|
421
|
-
stoppedAt: Date.now(),
|
|
422
|
-
name: this._getSessionName()
|
|
423
|
-
});
|
|
424
|
-
return res;
|
|
425
|
-
} catch (error) {
|
|
426
|
-
this.error = error.message;
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
/**
|
|
431
|
-
* Set the session attributes
|
|
432
|
-
* @param attributes - the attributes to set
|
|
433
|
-
*/
|
|
434
|
-
setSessionAttributes(attributes) {
|
|
435
|
-
this._sessionAttributes = attributes;
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
/**
|
|
439
|
-
* Set the user attributes
|
|
440
|
-
* @param userAttributes - the user attributes to set
|
|
441
|
-
*/
|
|
442
|
-
setUserAttributes(userAttributes) {
|
|
443
|
-
if (!this._userAttributes && !userAttributes) {
|
|
444
|
-
return;
|
|
445
|
-
}
|
|
446
|
-
this._userAttributes = userAttributes;
|
|
447
|
-
const data = {
|
|
448
|
-
userAttributes: this._userAttributes,
|
|
449
|
-
clientId: this._tracer.clientId
|
|
450
|
-
};
|
|
451
|
-
this._socketService.setUser(data);
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
/**
|
|
455
|
-
* @description Check if session should be started/stopped automatically
|
|
456
|
-
* @param {ISession} [sessionPayload]
|
|
457
|
-
* @returns {Promise<void>}
|
|
458
|
-
*/
|
|
459
|
-
async checkRemoteContinuousSession(sessionPayload) {
|
|
460
|
-
this._checkOperation('autoStartRemoteContinuousSession');
|
|
461
|
-
if (!this._configs?.showContinuousRecording) {
|
|
462
|
-
return;
|
|
463
|
-
}
|
|
464
|
-
const payload = {
|
|
465
|
-
sessionAttributes: {
|
|
466
|
-
...this.sessionAttributes,
|
|
467
|
-
...(sessionPayload?.sessionAttributes || {})
|
|
468
|
-
},
|
|
469
|
-
resourceAttributes: {
|
|
470
|
-
...getNavigatorInfo(),
|
|
471
|
-
...(sessionPayload?.resourceAttributes || {})
|
|
472
|
-
},
|
|
473
|
-
...(this._userAttributes ? {
|
|
474
|
-
userAttributes: this._userAttributes
|
|
475
|
-
} : {})
|
|
476
|
-
};
|
|
477
|
-
const {
|
|
478
|
-
state
|
|
479
|
-
} = await this._apiService.checkRemoteSession(payload);
|
|
480
|
-
if (state == 'START') {
|
|
481
|
-
if (this.sessionState !== SessionState.started) {
|
|
482
|
-
await this.start(SessionType.CONTINUOUS);
|
|
483
|
-
}
|
|
484
|
-
} else if (state == 'STOP') {
|
|
485
|
-
if (this.sessionState !== SessionState.stopped) {
|
|
486
|
-
await this.stop();
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
/**
|
|
492
|
-
* Create a new session and start it
|
|
493
|
-
*/
|
|
494
|
-
async _createSessionAndStart() {
|
|
495
|
-
const signal = this._startRequestController?.signal;
|
|
496
|
-
try {
|
|
497
|
-
const payload = {
|
|
498
|
-
sessionAttributes: this.sessionAttributes,
|
|
499
|
-
resourceAttributes: getNavigatorInfo(),
|
|
500
|
-
name: this._getSessionName(),
|
|
501
|
-
...(this._userAttributes ? {
|
|
502
|
-
userAttributes: this._userAttributes
|
|
503
|
-
} : {})
|
|
504
|
-
};
|
|
505
|
-
const request = !this.continuousRecording ? payload : {
|
|
506
|
-
debugSessionData: payload
|
|
507
|
-
};
|
|
508
|
-
const session = this.continuousRecording ? await this._apiService.startContinuousDebugSession(request, signal) : await this._apiService.startSession(request, signal);
|
|
509
|
-
if (session) {
|
|
510
|
-
session.sessionType = this.continuousRecording ? SessionType.CONTINUOUS : SessionType.MANUAL;
|
|
511
|
-
this._setupSessionAndStart(session, false);
|
|
512
|
-
}
|
|
513
|
-
} catch (error) {
|
|
514
|
-
this.error = error.message;
|
|
515
|
-
logger.error('SessionRecorder', 'Error creating session:', error.message);
|
|
516
|
-
if (this.continuousRecording) {
|
|
517
|
-
this.sessionType = SessionType.MANUAL;
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
/**
|
|
523
|
-
* Start tracing and recording for the session
|
|
524
|
-
*/
|
|
525
|
-
_start() {
|
|
526
|
-
this.sessionState = SessionState.started;
|
|
527
|
-
this.sessionType = this.sessionType;
|
|
528
|
-
if (this.sessionId) {
|
|
529
|
-
// Switch from buffer-only recording to session recording cleanly.
|
|
530
|
-
try {
|
|
531
|
-
this._recorder.stop();
|
|
532
|
-
} catch (_e) {}
|
|
533
|
-
this._tracer.start(this.sessionId, this.sessionType);
|
|
534
|
-
this._recorder.start(this.sessionId, this.sessionType);
|
|
535
|
-
if (this.session) {
|
|
536
|
-
this._socketService.subscribeToSession(this.session);
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
/**
|
|
542
|
-
* Stop tracing and recording for the session
|
|
543
|
-
*/
|
|
544
|
-
_stop() {
|
|
545
|
-
this.sessionState = SessionState.stopped;
|
|
546
|
-
this._socketService.unsubscribeFromSession(true);
|
|
547
|
-
this._tracer.stop();
|
|
548
|
-
this._recorder.stop();
|
|
549
|
-
this._startBufferOnlyRecording();
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
/**
|
|
553
|
-
* Pause the session tracing and recording
|
|
554
|
-
*/
|
|
555
|
-
_pause() {
|
|
556
|
-
this._tracer.stop();
|
|
557
|
-
this._recorder.stop();
|
|
558
|
-
this.sessionState = SessionState.paused;
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
/**
|
|
562
|
-
* Resume the session tracing and recording
|
|
563
|
-
*/
|
|
564
|
-
_resume() {
|
|
565
|
-
if (this.sessionId) {
|
|
566
|
-
this._tracer.start(this.sessionId, this.sessionType);
|
|
567
|
-
try {
|
|
568
|
-
this._recorder.stop();
|
|
569
|
-
} catch (_e) {}
|
|
570
|
-
this._recorder.start(this.sessionId, this.sessionType);
|
|
571
|
-
}
|
|
572
|
-
this.sessionState = SessionState.started;
|
|
573
|
-
}
|
|
574
|
-
_setupSessionAndStart(session, configureExporters = true) {
|
|
575
|
-
if (configureExporters && session.tempApiKey) {
|
|
576
|
-
this._configs.apiKey = session.tempApiKey;
|
|
577
|
-
this._tracer.setApiKey(session.tempApiKey);
|
|
578
|
-
this._apiService.setApiKey(session.tempApiKey);
|
|
579
|
-
this._socketService.updateConfigs({
|
|
580
|
-
apiKey: session.tempApiKey
|
|
581
|
-
});
|
|
582
|
-
}
|
|
583
|
-
this._setSession(session);
|
|
584
|
-
this._start();
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
/**
|
|
588
|
-
* Set the session ID in storage
|
|
589
|
-
* @param sessionId - the session ID to set or clear
|
|
590
|
-
*/
|
|
591
|
-
_setSession(session) {
|
|
592
|
-
this.session = {
|
|
593
|
-
...session,
|
|
594
|
-
createdAt: session.createdAt || new Date().toISOString()
|
|
595
|
-
};
|
|
596
|
-
this.sessionId = session?.shortId || session?._id;
|
|
597
|
-
}
|
|
598
|
-
_clearSession() {
|
|
599
|
-
this.session = null;
|
|
600
|
-
this.sessionId = null;
|
|
601
|
-
this.sessionState = SessionState.stopped;
|
|
602
|
-
this._storageService.clearSessionData();
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
/**
|
|
606
|
-
* Check the operation validity based on the session state and action
|
|
607
|
-
* @param action - action being checked ('init', 'start', 'stop', 'cancel', 'pause', 'resume')
|
|
608
|
-
*/
|
|
609
|
-
_checkOperation(action, _payload) {
|
|
610
|
-
if (!this._isInitialized) {
|
|
611
|
-
throw new Error('Configuration not initialized. Call init() before performing any actions.');
|
|
612
|
-
}
|
|
613
|
-
switch (action) {
|
|
614
|
-
case 'start':
|
|
615
|
-
if (this.sessionState === SessionState.started) {
|
|
616
|
-
throw new Error('Session is already started.');
|
|
617
|
-
}
|
|
618
|
-
break;
|
|
619
|
-
case 'stop':
|
|
620
|
-
if (this.sessionState !== SessionState.paused && this.sessionState !== SessionState.started) {
|
|
621
|
-
throw new Error('Cannot stop. Session is not currently started.');
|
|
622
|
-
}
|
|
623
|
-
break;
|
|
624
|
-
case 'cancel':
|
|
625
|
-
if (this.sessionState === SessionState.stopped) {
|
|
626
|
-
throw new Error('Cannot cancel. Session has already been stopped.');
|
|
627
|
-
}
|
|
628
|
-
break;
|
|
629
|
-
case 'pause':
|
|
630
|
-
if (this.sessionState !== SessionState.started) {
|
|
631
|
-
throw new Error('Cannot pause. Session is not running.');
|
|
632
|
-
}
|
|
633
|
-
break;
|
|
634
|
-
case 'resume':
|
|
635
|
-
if (this.sessionState !== SessionState.paused) {
|
|
636
|
-
throw new Error('Cannot resume. Session is not paused.');
|
|
637
|
-
}
|
|
638
|
-
break;
|
|
639
|
-
case 'save':
|
|
640
|
-
if (!this.continuousRecording) {
|
|
641
|
-
throw new Error('Cannot save continuous recording session. Continuous recording is not enabled.');
|
|
642
|
-
}
|
|
643
|
-
if (this.sessionState !== SessionState.started) {
|
|
644
|
-
throw new Error('Cannot save continuous recording session. Session is not started.');
|
|
645
|
-
}
|
|
646
|
-
break;
|
|
647
|
-
case 'autoStartRemoteContinuousSession':
|
|
648
|
-
if (this.sessionState !== SessionState.stopped) {
|
|
649
|
-
throw new Error('Cannot start remote continuous session. Session is not stopped.');
|
|
650
|
-
}
|
|
651
|
-
break;
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
// Session attributes
|
|
655
|
-
setSessionAttribute(key, value) {
|
|
656
|
-
if (this._session) {
|
|
657
|
-
if (!this._session.sessionAttributes) {
|
|
658
|
-
this._session.sessionAttributes = {};
|
|
659
|
-
}
|
|
660
|
-
this._session.sessionAttributes[key] = value;
|
|
661
|
-
this._session.updatedAt = new Date().toISOString();
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
|
|
665
|
-
/**
|
|
666
|
-
* Record a custom rrweb event
|
|
667
|
-
* Note: Screen capture and touch events are recorded automatically when session is started
|
|
668
|
-
* @param event - The rrweb event to record
|
|
669
|
-
*/
|
|
670
|
-
recordEvent(event) {
|
|
671
|
-
if (!this._isInitialized || this.sessionState !== SessionState.started) {
|
|
672
|
-
return;
|
|
673
|
-
}
|
|
674
|
-
|
|
675
|
-
// Forward the event to the recorder SDK
|
|
676
|
-
this._recorder.recordEvent(event);
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
/**
|
|
680
|
-
* Set the viewshot ref for screen capture
|
|
681
|
-
* @param ref - React Native View ref for screen capture
|
|
682
|
-
*/
|
|
683
|
-
setViewShotRef(ref) {
|
|
684
|
-
if (this._recorder) {
|
|
685
|
-
this._recorder.setViewShotRef(ref);
|
|
686
|
-
}
|
|
687
|
-
}
|
|
688
|
-
|
|
689
|
-
/**
|
|
690
|
-
* Set the navigation ref for navigation tracking
|
|
691
|
-
* @param ref - React Native Navigation ref for navigation tracking
|
|
692
|
-
*/
|
|
693
|
-
setNavigationRef(ref) {
|
|
694
|
-
if (this._recorder) {
|
|
695
|
-
this._recorder.setNavigationRef(ref);
|
|
696
|
-
}
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
/**
|
|
700
|
-
* Cleanup resources and unsubscribe from network monitoring
|
|
701
|
-
*/
|
|
702
|
-
cleanup() {
|
|
703
|
-
this._networkService.cleanup();
|
|
704
|
-
}
|
|
705
|
-
|
|
706
|
-
/**
|
|
707
|
-
* Normalize an error to an Error object
|
|
708
|
-
* @param error - the error to normalize
|
|
709
|
-
* @returns the normalized error
|
|
710
|
-
*/
|
|
711
|
-
_normalizeError(error) {
|
|
712
|
-
if (error instanceof Error) return error;
|
|
713
|
-
if (typeof error === 'string') return new Error(error);
|
|
714
|
-
try {
|
|
715
|
-
return new Error(JSON.stringify(error));
|
|
716
|
-
} catch (_e) {
|
|
717
|
-
return new Error(String(error));
|
|
718
|
-
}
|
|
719
|
-
}
|
|
720
|
-
|
|
721
|
-
/**
|
|
722
|
-
* Normalize an error info object to a Record<string, any>
|
|
723
|
-
* @param errorInfo - the error info to normalize
|
|
724
|
-
* @returns the normalized error info
|
|
725
|
-
*/
|
|
726
|
-
_normalizeErrorInfo(errorInfo) {
|
|
727
|
-
if (!errorInfo) return {};
|
|
728
|
-
try {
|
|
729
|
-
return JSON.parse(JSON.stringify(errorInfo));
|
|
730
|
-
} catch (_e) {
|
|
731
|
-
return {
|
|
732
|
-
errorInfo: String(errorInfo)
|
|
733
|
-
};
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
|
|
737
|
-
/**
|
|
738
|
-
* Get the session name
|
|
739
|
-
* @returns the session name
|
|
740
|
-
*/
|
|
741
|
-
_getSessionName(date = new Date()) {
|
|
742
|
-
const userName = this.sessionAttributes?.userName || this._userAttributes?.userName || this._userAttributes?.name || '';
|
|
743
|
-
return userName ? `${userName}'s session on ${getFormattedDate(date, {
|
|
744
|
-
month: 'short',
|
|
745
|
-
day: 'numeric'
|
|
746
|
-
})}` : `Session on ${getFormattedDate(date)}`;
|
|
747
|
-
}
|
|
748
|
-
}
|
|
749
|
-
export default new SessionRecorder();
|
|
750
|
-
//# sourceMappingURL=session-recorder.js.map
|