Skip to content

Commit

Permalink
Pass configuration to native code
Browse files Browse the repository at this point in the history
  • Loading branch information
louiszawadzki committed Oct 25, 2023
1 parent d3d5276 commit 690fe7a
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ import com.facebook.react.bridge.Promise
* The entry point to use Datadog's Session Replay feature.
*/
class DdSessionReplayImplementation() {
fun enable(promise: Promise) {
/**
* Enable session replay and start recording session.
* @param replaySampleRate The sample rate applied for session replay.
* @param defaultPrivacyLevel The privacy level used for replay.
*/
fun enable(replaySampleRate: Double, defaultPrivacyLevel: String, promise: Promise) {
promise.resolve(null)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ class DdSessionReplay(
private val implementation = DdSessionReplayImplementation()

override fun getName(): String = DdSessionReplayImplementation.NAME


/**
* Enable session replay and start recording session.
* @param replaySampleRate The sample rate applied for session replay.
* @param defaultPrivacyLevel The privacy level used for replay.
*/
@ReactMethod
override fun enable(promise: Promise) {
implementation.enable(promise)
override fun enable(replaySampleRate: Double, defaultPrivacyLevel: String, promise: Promise) {
implementation.enable(replaySampleRate, defaultPrivacyLevel, promise)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@ class DdSessionReplay(

override fun getName(): String = DdSessionReplayImplementation.NAME

/**
* Enable session replay and start recording session.
* @param replaySampleRate The sample rate applied for session replay.
* @param defaultPrivacyLevel The privacy level used for replay.
*/
@ReactMethod
fun enable(promise: Promise) {
implementation.enable(promise)
fun enable(replaySampleRate: Double, defaultPrivacyLevel: String, promise: Promise) {
implementation.enable(replaySampleRate, defaultPrivacyLevel, promise)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ internal class DdSessionReplayTest {
@Test
fun `M do nothing W enable()`() {
// When
testedSessionReplay.enable(mockPromise)
testedSessionReplay.enable(100.0, "MASK", mockPromise)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ @implementation DdSessionReplay

RCT_EXPORT_MODULE()

RCT_REMAP_METHOD(enable, withEnableResolve:(RCTPromiseResolveBlock)resolve
RCT_REMAP_METHOD(enable, withEnableReplaySampleRate:(double)replaySampleRate
withDefaultPrivacyLevel:(NSString*)defaultPrivacyLevel
withResolver:(RCTPromiseResolveBlock)resolve
withRejecter:(RCTPromiseRejectBlock)reject)
{
[self enable:resolve reject:reject];
[self enable:replaySampleRate defaultPrivacyLevel:defaultPrivacyLevel resolve:resolve reject:reject];
}

// Thanks to this guard, we won't compile this code when we build for the old architecture.
Expand All @@ -43,8 +45,8 @@ + (BOOL)requiresMainQueueSetup {
return NO;
}

- (void)enable:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
[self.ddSessionReplayImplementation enableWithResolve:resolve reject:reject];
- (void)enable:(double)replaySampleRate defaultPrivacyLevel:(NSString *)defaultPrivacyLevel resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
[self.ddSessionReplayImplementation enableWithReplaySampleRate:replaySampleRate defaultPrivacyLevel:defaultPrivacyLevel resolve:resolve reject:reject];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation
@objc
public class DdSessionReplayImplementation: NSObject {
@objc
public func enable(resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
public func enable(replaySampleRate: Double, defaultPrivacyLevel: String, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
resolve(nil)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ internal class DdSessionReplayTests: XCTestCase {
private func mockReject(args: String?, arg: String?, err: Error?) {}

func testDoesNothing() {
sessionReplay.enable(resolve: mockResolve, reject: mockReject)
sessionReplay.enable(replaySampleRate: 100, defaultPrivacyLevel: "MASK", resolve: mockResolve, reject: mockReject)
}
}

0 comments on commit 690fe7a

Please sign in to comment.