@datadog/mobile-react-native 2.8.0 → 2.8.1
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/android/src/main/kotlin/com/datadog/reactnative/DdSdkImplementation.kt +1 -1
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkNativeInitialization.kt +15 -25
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkReactNativePackage.kt +1 -1
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkSessionStartedListener.kt +124 -0
- package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +1 -1
- package/android/src/newarch/kotlin/com/datadog/reactnative/DdSdk.kt +26 -14
- package/android/src/oldarch/kotlin/com/datadog/reactnative/DdSdk.kt +14 -4
- package/android/src/test/kotlin/com/datadog/reactnative/DdSdkNativeInitializationTest.kt +0 -1
- package/android/src/test/kotlin/com/datadog/reactnative/DdSdkSessionStartedListenerTest.kt +140 -0
- package/ios/Sources/DdSdk.h +6 -4
- package/ios/Sources/DdSdk.mm +81 -31
- package/ios/Sources/DdSdkImplementation.swift +2 -2
- package/ios/Sources/DdSdkNativeInitialization.swift +14 -23
- package/ios/Sources/DdSdkSessionStartedListener.swift +105 -0
- package/ios/Sources/SdkVersion.swift +1 -1
- package/jest/mock.js +6 -2
- package/lib/commonjs/DdSdkReactNative.js +9 -7
- package/lib/commonjs/DdSdkReactNative.js.map +1 -1
- package/lib/commonjs/index.js +4 -4
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/rum/DdRum.js +5 -12
- package/lib/commonjs/rum/DdRum.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/distributedTracing.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +2 -2
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
- package/lib/commonjs/rum/sessionId/sessionIdHelper.js +8 -60
- package/lib/commonjs/rum/sessionId/sessionIdHelper.js.map +1 -1
- package/lib/commonjs/sdk/DatadogEventEmitter/DatadogBatchedBridgeEventEmitter.js +48 -0
- package/lib/commonjs/sdk/DatadogEventEmitter/DatadogBatchedBridgeEventEmitter.js.map +1 -0
- package/lib/commonjs/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.js +41 -0
- package/lib/commonjs/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.js.map +1 -0
- package/lib/commonjs/sdk/DatadogEventEmitter/DatadogEventEmitter.js +2 -0
- package/lib/commonjs/sdk/DatadogEventEmitter/DatadogEventEmitter.js.map +1 -0
- package/lib/commonjs/sdk/DatadogEventEmitter/DatadogNativeEventEmitter.js +43 -0
- package/lib/commonjs/sdk/DatadogEventEmitter/DatadogNativeEventEmitter.js.map +1 -0
- package/lib/commonjs/sdk/DatadogInternalBridge/DdSdkInternalNativeBridge.js +61 -0
- package/lib/commonjs/sdk/DatadogInternalBridge/DdSdkInternalNativeBridge.js.map +1 -0
- package/lib/commonjs/sdk/DatadogInternalBridge/DdSdkInternalNativeBridgeEvent.js +29 -0
- package/lib/commonjs/sdk/DatadogInternalBridge/DdSdkInternalNativeBridgeEvent.js.map +1 -0
- package/lib/commonjs/sdk/FileBasedConfiguration/FileBasedConfiguration.js +5 -2
- package/lib/commonjs/sdk/FileBasedConfiguration/FileBasedConfiguration.js.map +1 -1
- package/lib/commonjs/specs/NativeDdSdk.js.map +1 -1
- package/lib/commonjs/version.js +1 -1
- package/lib/module/DdSdkReactNative.js +9 -7
- package/lib/module/DdSdkReactNative.js.map +1 -1
- package/lib/module/index.js +4 -8
- package/lib/module/index.js.map +1 -1
- package/lib/module/rum/DdRum.js +6 -13
- package/lib/module/rum/DdRum.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/distributedTracing.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +2 -2
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
- package/lib/module/rum/sessionId/sessionIdHelper.js +5 -54
- package/lib/module/rum/sessionId/sessionIdHelper.js.map +1 -1
- package/lib/module/sdk/DatadogEventEmitter/DatadogBatchedBridgeEventEmitter.js +41 -0
- package/lib/module/sdk/DatadogEventEmitter/DatadogBatchedBridgeEventEmitter.js.map +1 -0
- package/lib/module/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.js +33 -0
- package/lib/module/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.js.map +1 -0
- package/lib/module/sdk/DatadogEventEmitter/DatadogEventEmitter.js +2 -0
- package/lib/module/sdk/DatadogEventEmitter/DatadogEventEmitter.js.map +1 -0
- package/lib/module/sdk/DatadogEventEmitter/DatadogNativeEventEmitter.js +35 -0
- package/lib/module/sdk/DatadogEventEmitter/DatadogNativeEventEmitter.js.map +1 -0
- package/lib/module/sdk/DatadogInternalBridge/DdSdkInternalNativeBridge.js +51 -0
- package/lib/module/sdk/DatadogInternalBridge/DdSdkInternalNativeBridge.js.map +1 -0
- package/lib/module/sdk/DatadogInternalBridge/DdSdkInternalNativeBridgeEvent.js +21 -0
- package/lib/module/sdk/DatadogInternalBridge/DdSdkInternalNativeBridgeEvent.js.map +1 -0
- package/lib/module/sdk/FileBasedConfiguration/FileBasedConfiguration.js +5 -2
- package/lib/module/sdk/FileBasedConfiguration/FileBasedConfiguration.js.map +1 -1
- package/lib/module/specs/NativeDdSdk.js.map +1 -1
- package/lib/module/version.js +1 -1
- package/lib/typescript/DdSdkReactNative.d.ts +3 -2
- package/lib/typescript/DdSdkReactNative.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +7 -6
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/rum/DdRum.d.ts +0 -2
- package/lib/typescript/rum/DdRum.d.ts.map +1 -1
- package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/distributedTracing.d.ts +3 -3
- package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/distributedTracing.d.ts.map +1 -1
- package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.d.ts +2 -2
- package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.d.ts.map +1 -1
- package/lib/typescript/rum/sessionId/sessionIdHelper.d.ts +2 -25
- package/lib/typescript/rum/sessionId/sessionIdHelper.d.ts.map +1 -1
- package/lib/typescript/sdk/DatadogEventEmitter/DatadogBatchedBridgeEventEmitter.d.ts +11 -0
- package/lib/typescript/sdk/DatadogEventEmitter/DatadogBatchedBridgeEventEmitter.d.ts.map +1 -0
- package/lib/typescript/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.d.ts +10 -0
- package/lib/typescript/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.d.ts.map +1 -0
- package/lib/typescript/sdk/DatadogEventEmitter/DatadogEventEmitter.d.ts +7 -0
- package/lib/typescript/sdk/DatadogEventEmitter/DatadogEventEmitter.d.ts.map +1 -0
- package/lib/typescript/sdk/DatadogEventEmitter/DatadogNativeEventEmitter.d.ts +12 -0
- package/lib/typescript/sdk/DatadogEventEmitter/DatadogNativeEventEmitter.d.ts.map +1 -0
- package/lib/typescript/sdk/DatadogInternalBridge/DdSdkInternalNativeBridge.d.ts +14 -0
- package/lib/typescript/sdk/DatadogInternalBridge/DdSdkInternalNativeBridge.d.ts.map +1 -0
- package/lib/typescript/sdk/DatadogInternalBridge/DdSdkInternalNativeBridgeEvent.d.ts +6 -0
- package/lib/typescript/sdk/DatadogInternalBridge/DdSdkInternalNativeBridgeEvent.d.ts.map +1 -0
- package/lib/typescript/sdk/FileBasedConfiguration/FileBasedConfiguration.d.ts +2 -0
- package/lib/typescript/sdk/FileBasedConfiguration/FileBasedConfiguration.d.ts.map +1 -1
- package/lib/typescript/specs/NativeDdSdk.d.ts.map +1 -1
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +2 -2
- package/src/DdSdkReactNative.tsx +16 -10
- package/src/__tests__/DdSdkReactNative.test.tsx +1 -37
- package/src/__tests__/mock.test.ts +3 -0
- package/src/__tests__/rum/instrumentation/DdEventsInterceptor.test.tsx +1 -1
- package/src/__tests__/rum/instrumentation/DdRumUserInteractionTracking.test.tsx +1 -1
- package/src/index.tsx +10 -13
- package/src/rum/DdRum.ts +7 -17
- package/src/rum/__tests__/DdRum.test.ts +3 -3
- package/src/rum/instrumentation/resourceTracking/distributedTracing/distributedTracing.tsx +3 -3
- package/src/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.ts +2 -2
- package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.ts +2 -2
- package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/__tests__/XHRProxy.test.ts +82 -1
- package/src/rum/sessionId/sessionIdHelper.ts +5 -63
- package/src/sdk/DatadogEventEmitter/DatadogBatchedBridgeEventEmitter.tsx +65 -0
- package/src/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.tsx +46 -0
- package/src/sdk/DatadogEventEmitter/DatadogEventEmitter.tsx +12 -0
- package/src/sdk/DatadogEventEmitter/DatadogNativeEventEmitter.tsx +60 -0
- package/src/sdk/DatadogInternalBridge/DdSdkInternalNativeBridge.tsx +83 -0
- package/src/sdk/DatadogInternalBridge/DdSdkInternalNativeBridgeEvent.tsx +36 -0
- package/src/sdk/DatadogInternalBridge/__tests__/DdSdkNativeBridge.test.tsx +159 -0
- package/src/sdk/DatadogProvider/__tests__/initialization.test.tsx +2 -2
- package/src/sdk/FileBasedConfiguration/FileBasedConfiguration.ts +8 -2
- package/src/sdk/FileBasedConfiguration/__tests__/FileBasedConfiguration.test.ts +6 -3
- package/src/sdk/FileBasedConfiguration/__tests__/__fixtures__/configuration-all-fields.json +6 -1
- package/src/specs/NativeDdSdk.ts +0 -1
- package/src/version.ts +1 -1
- package/lib/commonjs/sdk/EventEmitter/EventEmitter.js +0 -51
- package/lib/commonjs/sdk/EventEmitter/EventEmitter.js.map +0 -1
- package/lib/module/sdk/EventEmitter/EventEmitter.js +0 -43
- package/lib/module/sdk/EventEmitter/EventEmitter.js.map +0 -1
- package/lib/typescript/sdk/EventEmitter/EventEmitter.d.ts +0 -12
- package/lib/typescript/sdk/EventEmitter/EventEmitter.d.ts.map +0 -1
- package/src/rum/sessionId/__tests__/sessionIdHelper.test.ts +0 -162
- package/src/sdk/EventEmitter/EventEmitter.ts +0 -55
- package/src/sdk/EventEmitter/__tests__/EventEmitter.test.ts +0 -181
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
3
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
4
|
+
* Copyright 2016-Present Datadog, Inc.
|
|
5
|
+
*/
|
|
6
|
+
import { InternalLog } from '../../InternalLog';
|
|
7
|
+
import { SdkVerbosity } from '../../SdkVerbosity';
|
|
8
|
+
|
|
9
|
+
export class DdSdkInternalNativeBridgeEvent<DataType> {
|
|
10
|
+
public readonly eventName: string;
|
|
11
|
+
public readonly callback: (data: DataType) => void;
|
|
12
|
+
|
|
13
|
+
constructor(eventName: string, callback: (data: DataType) => void) {
|
|
14
|
+
this.eventName = eventName;
|
|
15
|
+
this.callback = (data: DataType) => {
|
|
16
|
+
if (!data) {
|
|
17
|
+
InternalLog.log(
|
|
18
|
+
`BridgeEvent undefined data for '${eventName}' event: ${
|
|
19
|
+
data ? JSON.stringify(data) : 'undefined'
|
|
20
|
+
}`,
|
|
21
|
+
SdkVerbosity.DEBUG
|
|
22
|
+
);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
InternalLog.log(
|
|
27
|
+
`BridgeEvent received data for '${eventName}' event: ${
|
|
28
|
+
data ? JSON.stringify(data) : 'undefined'
|
|
29
|
+
}`,
|
|
30
|
+
SdkVerbosity.DEBUG
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
callback(data);
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
3
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
4
|
+
* Copyright 2016-Present Datadog, Inc.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
8
|
+
/* eslint-disable global-require */
|
|
9
|
+
|
|
10
|
+
const mockBatchedBridge = {
|
|
11
|
+
registerCallableModule: jest.fn()
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const mockNativeDdSdkSpec = {
|
|
15
|
+
onRUMSessionStarted: jest.fn()
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const mockEventEmitter = {
|
|
19
|
+
initialize: jest.fn(),
|
|
20
|
+
addListener: jest.fn(),
|
|
21
|
+
removeAllListeners: jest.fn()
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const mockErrorHandler = jest.fn();
|
|
25
|
+
|
|
26
|
+
const mockNativeEventEmitter = {
|
|
27
|
+
initialize: jest.fn().mockReturnValue(true),
|
|
28
|
+
addListener: jest.fn(),
|
|
29
|
+
removeAllListeners: jest.fn()
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const mockBatchedBridgeEventEmitter = {
|
|
33
|
+
initialize: jest.fn().mockReturnValue(true),
|
|
34
|
+
addListener: jest.fn(),
|
|
35
|
+
removeAllListeners: jest.fn()
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
describe('DdSdkNativeBridge', () => {
|
|
39
|
+
beforeEach(() => {
|
|
40
|
+
jest.mock('../../DdSdk', () => ({
|
|
41
|
+
DdSdk: {
|
|
42
|
+
initialize: jest.fn()
|
|
43
|
+
}
|
|
44
|
+
}));
|
|
45
|
+
|
|
46
|
+
jest.mock(
|
|
47
|
+
'react-native/Libraries/BatchedBridge/BatchedBridge',
|
|
48
|
+
() => mockBatchedBridge
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
jest.mock(
|
|
52
|
+
'../../DatadogEventEmitter/DatadogNativeEventEmitter',
|
|
53
|
+
() => ({
|
|
54
|
+
DatadogNativeEventEmitter: jest
|
|
55
|
+
.fn()
|
|
56
|
+
.mockImplementation(() => mockNativeEventEmitter)
|
|
57
|
+
})
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
jest.mock(
|
|
61
|
+
'../../DatadogEventEmitter/DatadogBatchedBridgeEventEmitter',
|
|
62
|
+
() => ({
|
|
63
|
+
DatadogBatchedBridgeEventEmitter: jest
|
|
64
|
+
.fn()
|
|
65
|
+
.mockImplementation(() => mockBatchedBridgeEventEmitter)
|
|
66
|
+
})
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
jest.mock('../../../specs/NativeDdSdk', () => mockNativeDdSdkSpec);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
afterEach(() => {
|
|
73
|
+
jest.resetModules();
|
|
74
|
+
jest.resetAllMocks();
|
|
75
|
+
delete global.RN$Bridgeless;
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
describe('new architecture implementation', () => {
|
|
79
|
+
beforeEach(() => {
|
|
80
|
+
(global as any).RN$Bridgeless = true;
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('does not try to register the batched bridge when index is imported', () => {
|
|
84
|
+
const ddBridge = require('../DdSdkInternalNativeBridge');
|
|
85
|
+
const defaultEventEmitter = require('../../DatadogEventEmitter/DatadogDefaultEventEmitter');
|
|
86
|
+
mockNativeEventEmitter.initialize.mockReturnValueOnce(true);
|
|
87
|
+
ddBridge.registerNativeBridge(
|
|
88
|
+
new defaultEventEmitter.DatadogDefaultEventEmitter(
|
|
89
|
+
mockErrorHandler
|
|
90
|
+
)
|
|
91
|
+
);
|
|
92
|
+
expect(
|
|
93
|
+
mockBatchedBridge.registerCallableModule
|
|
94
|
+
).not.toHaveBeenCalled();
|
|
95
|
+
expect(mockErrorHandler).not.toHaveBeenCalled();
|
|
96
|
+
expect(ddBridge.hasNativeBridge()).toBe(true);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('catches errors when native event emitter init fails', () => {
|
|
100
|
+
jest.mock('../../../specs/NativeDdSdk', () => undefined);
|
|
101
|
+
|
|
102
|
+
const ddBridge = require('../DdSdkInternalNativeBridge');
|
|
103
|
+
const defaultEventEmitter = require('../../DatadogEventEmitter/DatadogDefaultEventEmitter');
|
|
104
|
+
mockNativeEventEmitter.initialize.mockReturnValueOnce(false);
|
|
105
|
+
|
|
106
|
+
ddBridge.registerNativeBridge(
|
|
107
|
+
new defaultEventEmitter.DatadogDefaultEventEmitter(
|
|
108
|
+
mockErrorHandler
|
|
109
|
+
),
|
|
110
|
+
mockErrorHandler
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
expect(mockErrorHandler).toHaveBeenCalledWith(
|
|
114
|
+
'ERROR: Native Bridge initialization failed.'
|
|
115
|
+
);
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
describe('old architecture implementation', () => {
|
|
120
|
+
beforeEach(() => {
|
|
121
|
+
(global as any).RN$Bridgeless = false;
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('does not try to register the event listener when index is imported', () => {
|
|
125
|
+
const ddBridge = require('../DdSdkInternalNativeBridge');
|
|
126
|
+
const defaultEventEmitter = require('../../DatadogEventEmitter/DatadogDefaultEventEmitter');
|
|
127
|
+
mockBatchedBridgeEventEmitter.initialize.mockReturnValueOnce(true);
|
|
128
|
+
|
|
129
|
+
ddBridge.registerNativeBridge(
|
|
130
|
+
new defaultEventEmitter.DatadogDefaultEventEmitter(
|
|
131
|
+
mockErrorHandler
|
|
132
|
+
)
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
expect(mockNativeEventEmitter.initialize).not.toHaveBeenCalled();
|
|
136
|
+
expect(mockBatchedBridgeEventEmitter.initialize).toHaveBeenCalled();
|
|
137
|
+
expect(mockErrorHandler).not.toHaveBeenCalled();
|
|
138
|
+
expect(ddBridge.hasNativeBridge()).toBe(true);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('hasBatchedBridge is false when batched bridge init fails', () => {
|
|
142
|
+
const ddBridge = require('../DdSdkInternalNativeBridge');
|
|
143
|
+
const defaultEventEmitter = require('../../DatadogEventEmitter/DatadogDefaultEventEmitter');
|
|
144
|
+
mockBatchedBridgeEventEmitter.initialize.mockReturnValueOnce(false);
|
|
145
|
+
|
|
146
|
+
ddBridge.registerNativeBridge(
|
|
147
|
+
new defaultEventEmitter.DatadogDefaultEventEmitter(
|
|
148
|
+
mockErrorHandler
|
|
149
|
+
),
|
|
150
|
+
mockErrorHandler
|
|
151
|
+
);
|
|
152
|
+
ddBridge.registerNativeBridge(mockEventEmitter);
|
|
153
|
+
expect(ddBridge.hasNativeBridge()).toBe(false);
|
|
154
|
+
expect(mockErrorHandler).toHaveBeenCalledWith(
|
|
155
|
+
'ERROR: Native Bridge initialization failed.'
|
|
156
|
+
);
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
});
|
|
@@ -77,8 +77,8 @@ describe('DatadogProvider', () => {
|
|
|
77
77
|
"clientToken": "fakeToken",
|
|
78
78
|
"configurationForTelemetry": {
|
|
79
79
|
"initializationType": "SYNC",
|
|
80
|
-
"reactNativeVersion": "0.
|
|
81
|
-
"reactVersion": "18.
|
|
80
|
+
"reactNativeVersion": "0.76.9",
|
|
81
|
+
"reactVersion": "18.3.1",
|
|
82
82
|
"trackErrors": true,
|
|
83
83
|
"trackInteractions": true,
|
|
84
84
|
"trackNetworkRequests": false,
|
|
@@ -31,12 +31,14 @@ export class FileBasedConfiguration extends DatadogProviderConfiguration {
|
|
|
31
31
|
configuration.trackInteractions,
|
|
32
32
|
configuration.trackResources,
|
|
33
33
|
configuration.trackErrors,
|
|
34
|
-
configuration.trackingConsent
|
|
34
|
+
configuration.trackingConsent,
|
|
35
|
+
configuration.useAccessibilityLabel
|
|
35
36
|
);
|
|
36
37
|
this.longTaskThresholdMs =
|
|
37
38
|
configuration.longTaskThresholdMs || DEFAULTS.longTaskThresholdMs;
|
|
38
39
|
this.verbosity = configuration.verbosity;
|
|
39
40
|
this.actionNameAttribute = configuration.actionNameAttribute;
|
|
41
|
+
this.site = configuration.site || DEFAULTS.site;
|
|
40
42
|
this.resourceTracingSamplingRate =
|
|
41
43
|
configuration.resourceTracingSamplingRate ||
|
|
42
44
|
DEFAULTS.resourceTracingSamplingRate;
|
|
@@ -123,6 +125,8 @@ export const getJSONConfiguration = (
|
|
|
123
125
|
actionNameAttribute: string | undefined;
|
|
124
126
|
resourceTracingSamplingRate: number | undefined;
|
|
125
127
|
firstPartyHosts: FirstPartyHostsConfiguration | undefined;
|
|
128
|
+
site: string | undefined;
|
|
129
|
+
useAccessibilityLabel: boolean | undefined;
|
|
126
130
|
} => {
|
|
127
131
|
const configuration = resolveJSONConfiguration(userSpecifiedConfiguration);
|
|
128
132
|
|
|
@@ -138,7 +142,9 @@ export const getJSONConfiguration = (
|
|
|
138
142
|
verbosity: buildSdkVerbosity(configuration.verbosity),
|
|
139
143
|
actionNameAttribute: configuration.actionNameAttribute,
|
|
140
144
|
resourceTracingSamplingRate: configuration.resourceTracingSamplingRate,
|
|
141
|
-
firstPartyHosts: buildFirstPartyHosts(configuration.firstPartyHosts)
|
|
145
|
+
firstPartyHosts: buildFirstPartyHosts(configuration.firstPartyHosts),
|
|
146
|
+
site: configuration.site,
|
|
147
|
+
useAccessibilityLabel: configuration.useAccessibilityLabel
|
|
142
148
|
};
|
|
143
149
|
};
|
|
144
150
|
|
|
@@ -28,9 +28,10 @@ describe('FileBasedConfiguration', () => {
|
|
|
28
28
|
trackErrors: true,
|
|
29
29
|
trackingConsent: 'NOT_GRANTED',
|
|
30
30
|
longTaskThresholdMs: 44,
|
|
31
|
+
site: 'US5',
|
|
31
32
|
verbosity: 'WARN',
|
|
32
33
|
actionNameAttribute: 'action-name-attr',
|
|
33
|
-
useAccessibilityLabel:
|
|
34
|
+
useAccessibilityLabel: false,
|
|
34
35
|
resourceTracingSamplingRate: 33,
|
|
35
36
|
firstPartyHosts: [
|
|
36
37
|
{
|
|
@@ -83,7 +84,7 @@ describe('FileBasedConfiguration', () => {
|
|
|
83
84
|
"resourceTracingSamplingRate": 33,
|
|
84
85
|
"serviceName": undefined,
|
|
85
86
|
"sessionSamplingRate": 100,
|
|
86
|
-
"site": "
|
|
87
|
+
"site": "US5",
|
|
87
88
|
"telemetrySampleRate": 20,
|
|
88
89
|
"trackBackgroundEvents": false,
|
|
89
90
|
"trackErrors": true,
|
|
@@ -93,7 +94,7 @@ describe('FileBasedConfiguration', () => {
|
|
|
93
94
|
"trackWatchdogTerminations": false,
|
|
94
95
|
"trackingConsent": "not_granted",
|
|
95
96
|
"uploadFrequency": "AVERAGE",
|
|
96
|
-
"useAccessibilityLabel":
|
|
97
|
+
"useAccessibilityLabel": false,
|
|
97
98
|
"verbosity": "warn",
|
|
98
99
|
"vitalsUpdateFrequency": "AVERAGE",
|
|
99
100
|
}
|
|
@@ -224,10 +225,12 @@ describe('FileBasedConfiguration', () => {
|
|
|
224
225
|
],
|
|
225
226
|
"longTaskThresholdMs": 44,
|
|
226
227
|
"resourceTracingSamplingRate": 33,
|
|
228
|
+
"site": "US5",
|
|
227
229
|
"trackErrors": true,
|
|
228
230
|
"trackInteractions": true,
|
|
229
231
|
"trackResources": true,
|
|
230
232
|
"trackingConsent": "not_granted",
|
|
233
|
+
"useAccessibilityLabel": false,
|
|
231
234
|
"verbosity": "warn",
|
|
232
235
|
}
|
|
233
236
|
`);
|
|
@@ -11,11 +11,16 @@
|
|
|
11
11
|
"longTaskThresholdMs": 44,
|
|
12
12
|
"verbosity": "WARN",
|
|
13
13
|
"actionNameAttribute": "action-name-attr",
|
|
14
|
+
"useAccessibilityLabel": false,
|
|
14
15
|
"resourceTracingSamplingRate": 33,
|
|
16
|
+
"site": "US5",
|
|
15
17
|
"firstPartyHosts": [
|
|
16
18
|
{
|
|
17
19
|
"match": "example.com",
|
|
18
|
-
"propagatorTypes": [
|
|
20
|
+
"propagatorTypes": [
|
|
21
|
+
"B3MULTI",
|
|
22
|
+
"TRACECONTEXT"
|
|
23
|
+
]
|
|
19
24
|
}
|
|
20
25
|
]
|
|
21
26
|
}
|
package/src/specs/NativeDdSdk.ts
CHANGED
|
@@ -86,7 +86,6 @@ export interface Spec extends TurboModule {
|
|
|
86
86
|
* https://github.com/react-native-community/RNNewArchitectureLibraries/tree/feat/swift-event-emitter?tab=readme-ov-file#codegen-update-codegen-specs)
|
|
87
87
|
*/
|
|
88
88
|
addListener: (eventType: string) => void;
|
|
89
|
-
|
|
90
89
|
removeListeners: (count: number) => void;
|
|
91
90
|
}
|
|
92
91
|
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// generated by genversion
|
|
2
|
-
export const version = '2.8.
|
|
2
|
+
export const version = '2.8.1';
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.createNativeEventEmitterForModule = void 0;
|
|
7
|
-
var _reactNative = require("react-native");
|
|
8
|
-
/*
|
|
9
|
-
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
10
|
-
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
11
|
-
* Copyright 2016-Present Datadog, Inc.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
const EMPTY_NATIVE_MODULE = {
|
|
15
|
-
addListener(_) {
|
|
16
|
-
/* empty */
|
|
17
|
-
},
|
|
18
|
-
removeListeners(_) {
|
|
19
|
-
/* empty */
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
const nativeEventEmitters = new Map();
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Default implementation for creating a NativeEventEmitter.
|
|
26
|
-
* @param nativeModule The NativeModule for which the NativeEventEmitter is created for.
|
|
27
|
-
* @returns The NativeEventEmitter.
|
|
28
|
-
*/
|
|
29
|
-
const createDefaultNativeEventEmitter = nativeModule => {
|
|
30
|
-
return new _reactNative.NativeEventEmitter(nativeModule);
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* [INTERNAL API]
|
|
35
|
-
* Creates a {@link NativeEventEmitter} from the given {@link NativeModule}.
|
|
36
|
-
* @param nativeModule The {@link NativeModule} to create the {@link NativeEventEmitter} for.
|
|
37
|
-
* @param createNativeEventEmitter Custom implementation for creating a {@link NativeEventEmitter}.
|
|
38
|
-
* Defaults to {@link createDefaultNativeEventEmitter} (USEFUL FOR TESTING)
|
|
39
|
-
* @returns The created {@link NativeEventEmitter}.
|
|
40
|
-
*/
|
|
41
|
-
const createNativeEventEmitterForModule = (nativeModule, createNativeEventEmitter = createDefaultNativeEventEmitter) => {
|
|
42
|
-
const eventEmitter = nativeEventEmitters.get(nativeModule);
|
|
43
|
-
if (!eventEmitter) {
|
|
44
|
-
const newEventEmitter = _reactNative.Platform.OS === 'android' ? createNativeEventEmitter() : createNativeEventEmitter(nativeModule ?? EMPTY_NATIVE_MODULE);
|
|
45
|
-
nativeEventEmitters.set(nativeModule, newEventEmitter);
|
|
46
|
-
return newEventEmitter;
|
|
47
|
-
}
|
|
48
|
-
return eventEmitter;
|
|
49
|
-
};
|
|
50
|
-
exports.createNativeEventEmitterForModule = createNativeEventEmitterForModule;
|
|
51
|
-
//# sourceMappingURL=EventEmitter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","EMPTY_NATIVE_MODULE","addListener","_","removeListeners","nativeEventEmitters","Map","createDefaultNativeEventEmitter","nativeModule","NativeEventEmitter","createNativeEventEmitterForModule","createNativeEventEmitter","eventEmitter","get","newEventEmitter","Platform","OS","set","exports"],"sourceRoot":"../../../../src","sources":["sdk/EventEmitter/EventEmitter.ts"],"mappings":";;;;;;AAKA,IAAAA,YAAA,GAAAC,OAAA;AALA;AACA;AACA;AACA;AACA;;AAIA,MAAMC,mBAAiC,GAAG;EACtCC,WAAWA,CAACC,CAAS,EAAQ;IACzB;EAAA,CACH;EACDC,eAAeA,CAACD,CAAS,EAAQ;IAC7B;EAAA;AAER,CAAC;AAED,MAAME,mBAAmB,GAAG,IAAIC,GAAG,CAAmC,CAAC;;AAEvE;AACA;AACA;AACA;AACA;AACA,MAAMC,+BAA+B,GACjCC,YAA2B,IACN;EACrB,OAAO,IAAIC,+BAAkB,CAACD,YAAY,CAAC;AAC/C,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAME,iCAAiC,GAAGA,CAC7CF,YAA0B,EAC1BG,wBAEuB,GAAGJ,+BAA+B,KACpC;EACrB,MAAMK,YAAY,GAAGP,mBAAmB,CAACQ,GAAG,CAACL,YAAY,CAAC;EAC1D,IAAI,CAACI,YAAY,EAAE;IACf,MAAME,eAAe,GACjBC,qBAAQ,CAACC,EAAE,KAAK,SAAS,GACnBL,wBAAwB,CAAC,CAAC,GAC1BA,wBAAwB,CAACH,YAAY,IAAIP,mBAAmB,CAAC;IACvEI,mBAAmB,CAACY,GAAG,CAACT,YAAY,EAAEM,eAAe,CAAC;IACtD,OAAOA,eAAe;EAC1B;EACA,OAAOF,YAAY;AACvB,CAAC;AAACM,OAAA,CAAAR,iCAAA,GAAAA,iCAAA","ignoreList":[]}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
3
|
-
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
4
|
-
* Copyright 2016-Present Datadog, Inc.
|
|
5
|
-
*/
|
|
6
|
-
import { NativeEventEmitter, Platform } from 'react-native';
|
|
7
|
-
const EMPTY_NATIVE_MODULE = {
|
|
8
|
-
addListener(_) {
|
|
9
|
-
/* empty */
|
|
10
|
-
},
|
|
11
|
-
removeListeners(_) {
|
|
12
|
-
/* empty */
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
const nativeEventEmitters = new Map();
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Default implementation for creating a NativeEventEmitter.
|
|
19
|
-
* @param nativeModule The NativeModule for which the NativeEventEmitter is created for.
|
|
20
|
-
* @returns The NativeEventEmitter.
|
|
21
|
-
*/
|
|
22
|
-
const createDefaultNativeEventEmitter = nativeModule => {
|
|
23
|
-
return new NativeEventEmitter(nativeModule);
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* [INTERNAL API]
|
|
28
|
-
* Creates a {@link NativeEventEmitter} from the given {@link NativeModule}.
|
|
29
|
-
* @param nativeModule The {@link NativeModule} to create the {@link NativeEventEmitter} for.
|
|
30
|
-
* @param createNativeEventEmitter Custom implementation for creating a {@link NativeEventEmitter}.
|
|
31
|
-
* Defaults to {@link createDefaultNativeEventEmitter} (USEFUL FOR TESTING)
|
|
32
|
-
* @returns The created {@link NativeEventEmitter}.
|
|
33
|
-
*/
|
|
34
|
-
export const createNativeEventEmitterForModule = (nativeModule, createNativeEventEmitter = createDefaultNativeEventEmitter) => {
|
|
35
|
-
const eventEmitter = nativeEventEmitters.get(nativeModule);
|
|
36
|
-
if (!eventEmitter) {
|
|
37
|
-
const newEventEmitter = Platform.OS === 'android' ? createNativeEventEmitter() : createNativeEventEmitter(nativeModule ?? EMPTY_NATIVE_MODULE);
|
|
38
|
-
nativeEventEmitters.set(nativeModule, newEventEmitter);
|
|
39
|
-
return newEventEmitter;
|
|
40
|
-
}
|
|
41
|
-
return eventEmitter;
|
|
42
|
-
};
|
|
43
|
-
//# sourceMappingURL=EventEmitter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["NativeEventEmitter","Platform","EMPTY_NATIVE_MODULE","addListener","_","removeListeners","nativeEventEmitters","Map","createDefaultNativeEventEmitter","nativeModule","createNativeEventEmitterForModule","createNativeEventEmitter","eventEmitter","get","newEventEmitter","OS","set"],"sourceRoot":"../../../../src","sources":["sdk/EventEmitter/EventEmitter.ts"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA,SAASA,kBAAkB,EAAEC,QAAQ,QAAQ,cAAc;AAG3D,MAAMC,mBAAiC,GAAG;EACtCC,WAAWA,CAACC,CAAS,EAAQ;IACzB;EAAA,CACH;EACDC,eAAeA,CAACD,CAAS,EAAQ;IAC7B;EAAA;AAER,CAAC;AAED,MAAME,mBAAmB,GAAG,IAAIC,GAAG,CAAmC,CAAC;;AAEvE;AACA;AACA;AACA;AACA;AACA,MAAMC,+BAA+B,GACjCC,YAA2B,IACN;EACrB,OAAO,IAAIT,kBAAkB,CAACS,YAAY,CAAC;AAC/C,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,iCAAiC,GAAGA,CAC7CD,YAA0B,EAC1BE,wBAEuB,GAAGH,+BAA+B,KACpC;EACrB,MAAMI,YAAY,GAAGN,mBAAmB,CAACO,GAAG,CAACJ,YAAY,CAAC;EAC1D,IAAI,CAACG,YAAY,EAAE;IACf,MAAME,eAAe,GACjBb,QAAQ,CAACc,EAAE,KAAK,SAAS,GACnBJ,wBAAwB,CAAC,CAAC,GAC1BA,wBAAwB,CAACF,YAAY,IAAIP,mBAAmB,CAAC;IACvEI,mBAAmB,CAACU,GAAG,CAACP,YAAY,EAAEK,eAAe,CAAC;IACtD,OAAOA,eAAe;EAC1B;EACA,OAAOF,YAAY;AACvB,CAAC","ignoreList":[]}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { NativeEventEmitter } from 'react-native';
|
|
2
|
-
import type { NativeModule } from 'react-native';
|
|
3
|
-
/**
|
|
4
|
-
* [INTERNAL API]
|
|
5
|
-
* Creates a {@link NativeEventEmitter} from the given {@link NativeModule}.
|
|
6
|
-
* @param nativeModule The {@link NativeModule} to create the {@link NativeEventEmitter} for.
|
|
7
|
-
* @param createNativeEventEmitter Custom implementation for creating a {@link NativeEventEmitter}.
|
|
8
|
-
* Defaults to {@link createDefaultNativeEventEmitter} (USEFUL FOR TESTING)
|
|
9
|
-
* @returns The created {@link NativeEventEmitter}.
|
|
10
|
-
*/
|
|
11
|
-
export declare const createNativeEventEmitterForModule: (nativeModule: NativeModule, createNativeEventEmitter?: (nativeEventModule?: NativeModule) => NativeEventEmitter) => NativeEventEmitter;
|
|
12
|
-
//# sourceMappingURL=EventEmitter.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EventEmitter.d.ts","sourceRoot":"","sources":["../../../../src/sdk/EventEmitter/EventEmitter.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,kBAAkB,EAAY,MAAM,cAAc,CAAC;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAwBjD;;;;;;;GAOG;AACH,eAAO,MAAM,iCAAiC,iBAC5B,YAAY,kDAEF,YAAY,KAC/B,kBAAkB,KACxB,kBAWF,CAAC"}
|
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
3
|
-
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
4
|
-
* Copyright 2016-Present Datadog, Inc.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
8
|
-
/* eslint-disable global-require */
|
|
9
|
-
import { createNativeEventEmitterForModule } from '../../../sdk/EventEmitter/EventEmitter';
|
|
10
|
-
|
|
11
|
-
describe('sessionIdHelper', () => {
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
jest.resetModules();
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('M registerRumSessionIdListener correctly registers a listener for RumSessionStarted', () => {
|
|
17
|
-
// GIVEN
|
|
18
|
-
const { registerRumSessionIdListener } = require('../sessionIdHelper');
|
|
19
|
-
const nativeModuleMock = {
|
|
20
|
-
addListener: jest.fn(),
|
|
21
|
-
removeListeners: jest.fn()
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const eventEmitter = createNativeEventEmitterForModule(
|
|
25
|
-
nativeModuleMock
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
// WHEN
|
|
29
|
-
registerRumSessionIdListener();
|
|
30
|
-
|
|
31
|
-
// THEN
|
|
32
|
-
expect(eventEmitter.listenerCount('RumSessionStarted')).toBe(1);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('M registerRumSessionIdListener does not register more than one listener for RumSessionStarted', () => {
|
|
36
|
-
// GIVEN
|
|
37
|
-
const { registerRumSessionIdListener } = require('../sessionIdHelper');
|
|
38
|
-
|
|
39
|
-
const nativeModuleMock = {
|
|
40
|
-
addListener: jest.fn(),
|
|
41
|
-
removeListeners: jest.fn()
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const eventEmitter = createNativeEventEmitterForModule(
|
|
45
|
-
nativeModuleMock
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
// WHEN
|
|
49
|
-
registerRumSessionIdListener();
|
|
50
|
-
registerRumSessionIdListener();
|
|
51
|
-
registerRumSessionIdListener();
|
|
52
|
-
|
|
53
|
-
// THEN
|
|
54
|
-
expect(eventEmitter.listenerCount('RumSessionStarted')).toBe(1);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('M removeRumSessionIdListeners should remove RumSessionStarted listener', () => {
|
|
58
|
-
// GIVEN
|
|
59
|
-
const {
|
|
60
|
-
registerRumSessionIdListener,
|
|
61
|
-
removeRumSessionIdListeners
|
|
62
|
-
} = require('../sessionIdHelper');
|
|
63
|
-
|
|
64
|
-
const nativeModuleMock = {
|
|
65
|
-
addListener: jest.fn(),
|
|
66
|
-
removeListeners: jest.fn()
|
|
67
|
-
};
|
|
68
|
-
const eventEmitter = createNativeEventEmitterForModule(
|
|
69
|
-
nativeModuleMock
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
registerRumSessionIdListener();
|
|
73
|
-
expect(eventEmitter.listenerCount('RumSessionStarted')).toBe(1);
|
|
74
|
-
|
|
75
|
-
// WHEN
|
|
76
|
-
removeRumSessionIdListeners();
|
|
77
|
-
|
|
78
|
-
// THEN
|
|
79
|
-
expect(eventEmitter.listenerCount('RumSessionStarted')).toBe(0);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it('M getCachedRumSessionId should return null W { cachedRumSessionId has not been set }', () => {
|
|
83
|
-
// GIVEN
|
|
84
|
-
const { getCachedRumSessionId } = require('../sessionIdHelper');
|
|
85
|
-
|
|
86
|
-
// WHEN
|
|
87
|
-
const sessionId = getCachedRumSessionId();
|
|
88
|
-
|
|
89
|
-
// THEN
|
|
90
|
-
expect(sessionId).toBeNull();
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it('M getCachedRumSessionId should return cached RUM Session ID W { cachedRumSessionId has been set }', () => {
|
|
94
|
-
// GIVEN
|
|
95
|
-
const {
|
|
96
|
-
setCachedRumSessionId,
|
|
97
|
-
getCachedRumSessionId
|
|
98
|
-
} = require('../sessionIdHelper');
|
|
99
|
-
|
|
100
|
-
setCachedRumSessionId('TEST_SESSION_ID');
|
|
101
|
-
|
|
102
|
-
// WHEN
|
|
103
|
-
const sessionId = getCachedRumSessionId();
|
|
104
|
-
|
|
105
|
-
// THEN
|
|
106
|
-
expect(sessionId).toBe('TEST_SESSION_ID');
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it('M getCachedRumSessionId should return sessionID W { registered listener is called }', () => {
|
|
110
|
-
// GIVEN
|
|
111
|
-
const {
|
|
112
|
-
registerRumSessionIdListener,
|
|
113
|
-
getCachedRumSessionId
|
|
114
|
-
} = require('../sessionIdHelper');
|
|
115
|
-
|
|
116
|
-
const nativeModuleMock = {
|
|
117
|
-
addListener: jest.fn(),
|
|
118
|
-
removeListeners: jest.fn()
|
|
119
|
-
};
|
|
120
|
-
const eventEmitter = createNativeEventEmitterForModule(
|
|
121
|
-
nativeModuleMock
|
|
122
|
-
);
|
|
123
|
-
|
|
124
|
-
registerRumSessionIdListener();
|
|
125
|
-
|
|
126
|
-
// WHEN
|
|
127
|
-
const event = {
|
|
128
|
-
sessionId: 'LISTENER_TEST_SESSION_ID'
|
|
129
|
-
};
|
|
130
|
-
eventEmitter.emit('RumSessionStarted', event);
|
|
131
|
-
|
|
132
|
-
// THEN
|
|
133
|
-
expect(getCachedRumSessionId()).toBe('LISTENER_TEST_SESSION_ID');
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
it('M getCachedRumSessionId should be null W { registered listener is called with undefined value }', () => {
|
|
137
|
-
// GIVEN
|
|
138
|
-
const {
|
|
139
|
-
registerRumSessionIdListener,
|
|
140
|
-
getCachedRumSessionId
|
|
141
|
-
} = require('../sessionIdHelper');
|
|
142
|
-
|
|
143
|
-
const nativeModuleMock = {
|
|
144
|
-
addListener: jest.fn(),
|
|
145
|
-
removeListeners: jest.fn()
|
|
146
|
-
};
|
|
147
|
-
const eventEmitter = createNativeEventEmitterForModule(
|
|
148
|
-
nativeModuleMock
|
|
149
|
-
);
|
|
150
|
-
|
|
151
|
-
registerRumSessionIdListener();
|
|
152
|
-
|
|
153
|
-
// WHEN
|
|
154
|
-
const event = {
|
|
155
|
-
sessionId: undefined
|
|
156
|
-
};
|
|
157
|
-
eventEmitter.emit('RumSessionStarted', event);
|
|
158
|
-
|
|
159
|
-
// THEN
|
|
160
|
-
expect(getCachedRumSessionId()).toBeNull();
|
|
161
|
-
});
|
|
162
|
-
});
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
3
|
-
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
4
|
-
* Copyright 2016-Present Datadog, Inc.
|
|
5
|
-
*/
|
|
6
|
-
import { NativeEventEmitter, Platform } from 'react-native';
|
|
7
|
-
import type { NativeModule } from 'react-native';
|
|
8
|
-
|
|
9
|
-
const EMPTY_NATIVE_MODULE: NativeModule = {
|
|
10
|
-
addListener(_: string): void {
|
|
11
|
-
/* empty */
|
|
12
|
-
},
|
|
13
|
-
removeListeners(_: number): void {
|
|
14
|
-
/* empty */
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const nativeEventEmitters = new Map<NativeModule, NativeEventEmitter>();
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Default implementation for creating a NativeEventEmitter.
|
|
22
|
-
* @param nativeModule The NativeModule for which the NativeEventEmitter is created for.
|
|
23
|
-
* @returns The NativeEventEmitter.
|
|
24
|
-
*/
|
|
25
|
-
const createDefaultNativeEventEmitter = (
|
|
26
|
-
nativeModule?: NativeModule
|
|
27
|
-
): NativeEventEmitter => {
|
|
28
|
-
return new NativeEventEmitter(nativeModule);
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* [INTERNAL API]
|
|
33
|
-
* Creates a {@link NativeEventEmitter} from the given {@link NativeModule}.
|
|
34
|
-
* @param nativeModule The {@link NativeModule} to create the {@link NativeEventEmitter} for.
|
|
35
|
-
* @param createNativeEventEmitter Custom implementation for creating a {@link NativeEventEmitter}.
|
|
36
|
-
* Defaults to {@link createDefaultNativeEventEmitter} (USEFUL FOR TESTING)
|
|
37
|
-
* @returns The created {@link NativeEventEmitter}.
|
|
38
|
-
*/
|
|
39
|
-
export const createNativeEventEmitterForModule = (
|
|
40
|
-
nativeModule: NativeModule,
|
|
41
|
-
createNativeEventEmitter: (
|
|
42
|
-
nativeEventModule?: NativeModule
|
|
43
|
-
) => NativeEventEmitter = createDefaultNativeEventEmitter
|
|
44
|
-
): NativeEventEmitter => {
|
|
45
|
-
const eventEmitter = nativeEventEmitters.get(nativeModule);
|
|
46
|
-
if (!eventEmitter) {
|
|
47
|
-
const newEventEmitter =
|
|
48
|
-
Platform.OS === 'android'
|
|
49
|
-
? createNativeEventEmitter()
|
|
50
|
-
: createNativeEventEmitter(nativeModule ?? EMPTY_NATIVE_MODULE);
|
|
51
|
-
nativeEventEmitters.set(nativeModule, newEventEmitter);
|
|
52
|
-
return newEventEmitter;
|
|
53
|
-
}
|
|
54
|
-
return eventEmitter;
|
|
55
|
-
};
|