noibu-react-native 0.2.16 → 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 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.16" ;
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
- let parsedMessage = JSON.parse(event.message);
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
  }
@@ -1,33 +1,5 @@
1
- #import "IOSPocEmitter.h"
2
- @import NoibuSDK;
3
- @implementation IOSPocEmitter
1
+ #import <React/RCTBridgeModule.h>
4
2
 
5
- // Module registration
6
- RCT_EXPORT_MODULE();
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.public_header_files = "ios/**/*.{h}" # Expose public headers
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.2'
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "noibu-react-native",
3
- "version": "0.2.16",
3
+ "version": "0.2.17",
4
4
  "targetNjsVersion": "1.0.104",
5
5
  "description": "React-Native SDK for NoibuJS to collect errors in React-Native applications",
6
6
  "main": "dist/entry/index.js",
@@ -1,7 +0,0 @@
1
- #import <React/RCTEventEmitter.h>
2
- #import <React/RCTBridgeModule.h>
3
-
4
- @interface IOSPocEmitter : RCTEventEmitter <RCTBridgeModule>
5
-
6
- - (void)initialize;
7
- @end