55 */
66
77import Foundation
8+ import React
89import DatadogCore
910import DatadogInternal
1011
1112@objc
1213public class DdCoreTestsImplementation : NSObject {
13- private let getCoreProxy : ( ) throws -> DatadogCoreProxy
14+ private let getCoreProxy : ( ) throws -> DatadogCoreProtocol
1415
15- internal init ( _ getCoreProxy: @escaping ( ) throws -> DatadogCoreProxy ) {
16+ internal init ( _ getCoreProxy: @escaping ( ) throws -> DatadogCoreProtocol ) {
1617 self . getCoreProxy = getCoreProxy
1718 }
1819
20+ private var proxy : DatadogCoreObserver ? = nil
21+
1922 @objc
2023 public override convenience init ( ) {
2124 self . init ( {
22- guard let coreProxy = Datadog . sdkInstance ( named: CoreRegistry . defaultInstanceName) as? DatadogCoreProxy else {
23- throw InternalError ( description: " Core is not proxy " )
24- }
25- return coreProxy
25+ return Datadog . sdkInstance ( named: CoreRegistry . defaultInstanceName)
2626 } )
2727 }
28-
28+
2929 @objc
30- public func clearData ( resolve: RCTPromiseResolveBlock , reject: RCTPromiseRejectBlock ) -> Void {
30+ public func startRecording ( resolve: RCTPromiseResolveBlock , reject: RCTPromiseRejectBlock ) -> Void {
3131 do {
32- let coreProxy = try getCoreProxy ( )
33- coreProxy. waitAndDeleteEvents ( ofFeature: " rum " )
34- coreProxy. waitAndDeleteEvents ( ofFeature: " logging " )
35- coreProxy. waitAndDeleteEvents ( ofFeature: " tracing " )
36- coreProxy. waitAndDeleteEvents ( ofFeature: " session-replay " )
37- resolve ( nil )
32+ let core = try getCoreProxy ( )
33+ self . proxy = DatadogCoreObserver ( core: core)
3834 } catch {
3935 reject ( nil , Errors . logSentBeforeSDKInit, nil )
4036 }
4137 return
4238 }
39+
40+ @objc
41+ public func clearData( resolve: RCTPromiseResolveBlock , reject: RCTPromiseRejectBlock ) -> Void {
42+ self . proxy? . waitAndDeleteEvents ( ofFeature: " rum " )
43+ self . proxy? . waitAndDeleteEvents ( ofFeature: " logging " )
44+ self . proxy? . waitAndDeleteEvents ( ofFeature: " tracing " )
45+ self . proxy? . waitAndDeleteEvents ( ofFeature: " session-replay " )
46+
47+ resolve ( nil )
48+ return
49+ }
4350
4451 @objc
4552 public func getAllEvents( feature: String , resolve: RCTPromiseResolveBlock , reject: RCTPromiseRejectBlock ) -> Void {
4653 do {
4754 let coreProxy = try getCoreProxy ( )
48- let events = coreProxy . waitAndReturnEvents ( ofFeature: feature, ofType: AnyEncodable . self)
55+ let events = proxy ? . waitAndReturnEvents ( ofFeature: feature, ofType: AnyEncodable . self)
4956 let data = try JSONSerialization . data ( withJSONObject: events, options: . prettyPrinted)
5057 resolve ( String ( data: data, encoding: String . Encoding. utf8) ?? " " )
5158 } catch {
@@ -58,7 +65,7 @@ public class DdCoreTestsImplementation: NSObject {
5865 public func getAllEventsData( feature: String , resolve: RCTPromiseResolveBlock , reject: RCTPromiseRejectBlock ) -> Void {
5966 do {
6067 let coreProxy = try getCoreProxy ( )
61- let events = coreProxy . waitAndReturnEventsData ( ofFeature: feature)
68+ let events = proxy ? . waitAndReturnEventsData ( ofFeature: feature)
6269 let data = try JSONSerialization . data ( withJSONObject: events, options: . prettyPrinted)
6370 resolve ( String ( data: data, encoding: String . Encoding. utf8) ?? " " )
6471 } catch {
0 commit comments