package com.contentsquare.rn.externalbridge import com.contentsquare.android.api.bridge.xpf.ExternalBridgeInterface import com.contentsquare.android.api.bridge.xpf.ExternalBridgeType import com.contentsquare.android.api.bridge.xpf.SDKState import com.contentsquare.android.api.bridge.xpf.SDKStateChangeType import com.contentsquare.rn.eventEmitter.CSEventEmitterModuleImpl import com.contentsquare.rn.utils.ExponentialBackoff import com.contentsquare.rn.utils.ExponentialBackoff.FailureCallback import com.contentsquare.rn.utils.ExponentialBackoff.TaskCompletionCallback class ExternalBridgeInterfaceImpl( private val mCSEventEmitter: CSEventEmitterModuleImpl, override val bridgeType: ExternalBridgeType ) : ExternalBridgeInterface { override fun notifyCsInAppEnabled(enabled: Boolean) { // no-op } override fun notifySDKStateChanges(type: SDKStateChangeType, state: SDKState) { // no-op } override fun notifySessionReplayEnabled(enable: Boolean) { // no-op } override fun notifySessionReplayQualityChanged(jsonData: String) { // no-op } override fun notifyShouldSendInitialInsertion() { // no-op } override fun notifySrMaskingHasChanged(enabled: Boolean) { // no-op } override fun notifySrMaskingIndicatorHasChanged(enabled: Boolean) { // no-op } override fun updateBridgeConfig(bridgeConfig: String) { notifyFeatureFlagChange(bridgeConfig) } private fun notifyFeatureFlagChange(bridgeConfig: String) { val emitEventTask = ExponentialBackoff.Task { completionCallback: TaskCompletionCallback -> val completed: Boolean = mCSEventEmitter.sendFeatureFlags(bridgeConfig) completionCallback.onComplete(completed) } val failureCallback = FailureCallback { println("All retries failed.") } val exponentialBackoff = ExponentialBackoff(10, 0.1, emitEventTask, failureCallback) exponentialBackoff.start() } }