noibu-react-native 0.2.15 → 0.2.17
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/dist/constants.js +1 -1
- package/dist/sessionRecorder/nativeSessionRecorderSubscription.d.ts +0 -15
- package/dist/sessionRecorder/nativeSessionRecorderSubscription.js +11 -7
- package/dist/utils/log.js +5 -3
- package/ios/IOSPocEmitter.m +4 -32
- package/ios/IOSPocEmitter.swift +61 -0
- package/noibu-react-native.podspec +2 -2
- package/package.json +1 -1
- package/ios/IOSPocEmitter.h +0 -7
package/dist/constants.js
CHANGED
|
@@ -24,7 +24,7 @@ const CONTENT_TYPE = 'content-type';
|
|
|
24
24
|
* Gets the script id from the cookie object, returns default if cannot be found
|
|
25
25
|
*/
|
|
26
26
|
function GET_SCRIPT_ID() {
|
|
27
|
-
return "1.0.104-rn-sdk-0.2.
|
|
27
|
+
return "1.0.104-rn-sdk-0.2.17" ;
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
30
|
* Gets the max metro recon number
|
|
@@ -59,19 +59,4 @@ export declare function setCustomUserId(customUserId: string): void;
|
|
|
59
59
|
export declare function setCustomSessionId(customSessionId: string): void;
|
|
60
60
|
export type RecorderEvent = import('./types').RecorderEvent;
|
|
61
61
|
export type UnsubscribeFn = import('./types').UnsubscribeFn;
|
|
62
|
-
/**
|
|
63
|
-
* Subscribes to a native event emitted by the Noibu Session Recorder.
|
|
64
|
-
*
|
|
65
|
-
* This function listens for the `noibuRecordingEvent` emitted from the native layer (only on Android)
|
|
66
|
-
* and invokes the provided callback whenever the event occurs. If the platform is not Android,
|
|
67
|
-
* the function will do nothing and return a no-op unsubscribe function.
|
|
68
|
-
*
|
|
69
|
-
* @param {function(RecorderEvent): void} callback - Target callback function that will be invoked with
|
|
70
|
-
* the event data whenever the `noibuRecordingEvent` is emitted.
|
|
71
|
-
*
|
|
72
|
-
* @returns {UnsubscribeFn} Target function to unsubscribe from the event. On Android, this will remove
|
|
73
|
-
* the event listener. On other platforms, it will be a no-op.
|
|
74
|
-
*
|
|
75
|
-
* @throws {Error} If the Noibu Session Recorder is not initialized before calling this function.
|
|
76
|
-
*/
|
|
77
62
|
export declare function subscribeToNativeEvent(callback: (event: RecorderEvent) => void): UnsubscribeFn;
|
|
@@ -27,8 +27,6 @@ var LogLevel;
|
|
|
27
27
|
*/
|
|
28
28
|
function initialize(projectId, config) {
|
|
29
29
|
if (Platform.OS === 'ios') {
|
|
30
|
-
nativeModuleEmitter = new NativeEventEmitter(IOSPocEmitter);
|
|
31
|
-
IOSPocEmitter.initialize();
|
|
32
30
|
return;
|
|
33
31
|
}
|
|
34
32
|
if (!(typeof config === 'object' || typeof config === 'undefined')) {
|
|
@@ -65,6 +63,7 @@ function initialize(projectId, config) {
|
|
|
65
63
|
*
|
|
66
64
|
* @throws {Error} If the Noibu Session Recorder is not initialized before calling this function.
|
|
67
65
|
*/
|
|
66
|
+
let isIOSInitialized = false;
|
|
68
67
|
function subscribeToNativeEvent(callback) {
|
|
69
68
|
if (Platform.OS === 'android') {
|
|
70
69
|
if (!nativeModuleEmitter) {
|
|
@@ -75,18 +74,23 @@ function subscribeToNativeEvent(callback) {
|
|
|
75
74
|
// return () => subscription.remove();
|
|
76
75
|
}
|
|
77
76
|
if (Platform.OS === 'ios') {
|
|
77
|
+
if (!nativeModuleEmitter) {
|
|
78
|
+
nativeModuleEmitter = new NativeEventEmitter(IOSPocEmitter);
|
|
79
|
+
noibuLog('nativeModuleEmitter', nativeModuleEmitter);
|
|
80
|
+
}
|
|
78
81
|
nativeModuleEmitter.addListener('iosPOCRecordingEvent', event => {
|
|
79
82
|
try {
|
|
80
|
-
|
|
81
|
-
if (Array.isArray(parsedMessage)) {
|
|
82
|
-
parsedMessage = parsedMessage[0];
|
|
83
|
-
}
|
|
84
|
-
const transformedEvent = transformEventToWeb(parsedMessage);
|
|
83
|
+
const transformedEvent = transformEventToWeb(event.message);
|
|
85
84
|
callback({ message: transformedEvent });
|
|
86
85
|
}
|
|
87
86
|
catch (e) {
|
|
87
|
+
noibuLog(`[Error] transformEventToWeb failed: ${e.message}`);
|
|
88
88
|
}
|
|
89
89
|
});
|
|
90
|
+
if (!isIOSInitialized) {
|
|
91
|
+
IOSPocEmitter.startIOS();
|
|
92
|
+
isIOSInitialized = true;
|
|
93
|
+
}
|
|
90
94
|
}
|
|
91
95
|
return () => { };
|
|
92
96
|
}
|
package/dist/utils/log.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
/* eslint-disable no-console,@typescript-eslint/no-empty-function */
|
|
2
2
|
/** no operation */
|
|
3
|
+
const noop = () => { };
|
|
3
4
|
/**
|
|
4
5
|
* checks if was overridden and calls original console function
|
|
5
6
|
*/
|
|
6
7
|
const getConsoleMethod = (ogProp) => {
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
{
|
|
9
|
+
return noop;
|
|
10
|
+
}
|
|
9
11
|
};
|
|
10
12
|
/**log with level = info */
|
|
11
|
-
const noibuLog = (...msgs) => getConsoleMethod(
|
|
13
|
+
const noibuLog = (...msgs) => getConsoleMethod()('Noibu', ...msgs);
|
|
12
14
|
|
|
13
15
|
export { noibuLog };
|
package/ios/IOSPocEmitter.m
CHANGED
|
@@ -1,33 +1,5 @@
|
|
|
1
|
-
#import
|
|
2
|
-
@import NoibuSDK;
|
|
3
|
-
@implementation IOSPocEmitter
|
|
1
|
+
#import <React/RCTBridgeModule.h>
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
// Supported events for React Native
|
|
9
|
-
- (NSArray<NSString *> *)supportedEvents {
|
|
10
|
-
return @[@"iosPOCRecordingEvent"];
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
RCT_EXPORT_METHOD(initialize) {
|
|
14
|
-
NSString *NOIBU_API_KEY = @"NOIBU_API_KEY";
|
|
15
|
-
NSString *NOIBU_HOST = @"https://noibu.com/";
|
|
16
|
-
// Create and configure the NoibuConfig object
|
|
17
|
-
NoibuConfig *config = [[NoibuConfig alloc] apiKey:NOIBU_API_KEY host:NOIBU_HOST];
|
|
18
|
-
// config.debug = YES; // Enable debug logging to see transformed events
|
|
19
|
-
// Define the callback for transformed events
|
|
20
|
-
config.onMobileEventTransformed = ^(NSString *transformedData) {
|
|
21
|
-
if ([self bridge]) { // Ensure the bridge is initialized
|
|
22
|
-
[self sendEventWithName:@"iosPOCRecordingEvent" body:@{@"message": transformedData}];
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
[[NoibuSDKManager shared] setup:config];
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// React Native requires this to indicate if the module needs to be initialized on the main thread
|
|
29
|
-
+ (BOOL)requiresMainQueueSetup {
|
|
30
|
-
return YES;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
@end
|
|
3
|
+
@interface RCT_EXTERN_MODULE(IOSPocEmitter, NSObject)
|
|
4
|
+
RCT_EXTERN_METHOD(startIOS)
|
|
5
|
+
@end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import React
|
|
3
|
+
import NoibuSDK
|
|
4
|
+
|
|
5
|
+
@objc(IOSPocEmitter)
|
|
6
|
+
class IOSPocEmitter: RCTEventEmitter {
|
|
7
|
+
|
|
8
|
+
private var hasListeners = false
|
|
9
|
+
|
|
10
|
+
override init() {
|
|
11
|
+
super.init()
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
override class func requiresMainQueueSetup() -> Bool {
|
|
15
|
+
return true
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
override func supportedEvents() -> [String]! {
|
|
19
|
+
return ["iosPOCRecordingEvent"]
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
override func startObserving() {
|
|
23
|
+
hasListeners = true
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
override func stopObserving() {
|
|
27
|
+
hasListeners = false
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@objc func startIOS() {
|
|
31
|
+
let NOIBU_API_KEY = "NOIBU_API_KEY"
|
|
32
|
+
let NOIBU_HOST = "https://noibu.com/"
|
|
33
|
+
|
|
34
|
+
let config = NoibuConfig(apiKey: NOIBU_API_KEY, host: NOIBU_HOST)
|
|
35
|
+
// config.debug = true // Enable debug logging to see transformed events
|
|
36
|
+
|
|
37
|
+
config.onMobileEventTransformed = { [weak self] transformedData in
|
|
38
|
+
guard let self = self, self.bridge != nil else { return }
|
|
39
|
+
|
|
40
|
+
let start = CFAbsoluteTimeGetCurrent()
|
|
41
|
+
|
|
42
|
+
guard let jsonData = transformedData.data(using: .utf8) else {
|
|
43
|
+
NSLog("❌ Failed to encode transformedData as UTF-8")
|
|
44
|
+
return
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
do {
|
|
48
|
+
let jsonObject = try JSONSerialization.jsonObject(with: jsonData, options: [])
|
|
49
|
+
var finalMessage = jsonObject
|
|
50
|
+
if let array = jsonObject as? [Any], let first = array.first {
|
|
51
|
+
finalMessage = first
|
|
52
|
+
}
|
|
53
|
+
self.sendEvent(withName: "iosPOCRecordingEvent", body: ["message": finalMessage])
|
|
54
|
+
} catch {
|
|
55
|
+
NSLog("❌ Failed to parse transformedData JSON: %@", error.localizedDescription)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
NoibuSDKManager.shared.setup(config)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -18,12 +18,12 @@ Pod::Spec.new do |s|
|
|
|
18
18
|
# Include source files
|
|
19
19
|
|
|
20
20
|
s.source_files = "ios/**/*.{h,m,mm,swift}"
|
|
21
|
-
s.
|
|
21
|
+
s.swift_version = '5.0'
|
|
22
22
|
|
|
23
23
|
#s.vendored_frameworks = "ios/SessionRecorder.xcframework"
|
|
24
24
|
#s.vendored_frameworks = "ios/Noibu.xcframework"
|
|
25
25
|
|
|
26
|
-
s.dependency 'NoibuSDK', '0.0.
|
|
26
|
+
s.dependency 'NoibuSDK', '0.0.5'
|
|
27
27
|
s.pod_target_xcconfig = {
|
|
28
28
|
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/noibu-react-native/ios/**\""
|
|
29
29
|
}
|
package/package.json
CHANGED