Dari

DariInterceptor API

Interface and default implementation for capturing bridge messages

Interface

interface DariInterceptor {
    val tag: String? get() = null

    fun onWebToAppRequest(
        handlerName: String,
        requestId: String?,
        requestData: String?,
        fireAndForget: Boolean? = null,
    )

    fun onWebToAppResponse(
        handlerName: String,
        requestId: String?,
        responseData: String?,
        isSuccess: Boolean,
    )

    fun onAppToWebRequest(
        handlerName: String,
        requestId: String?,
        data: String?,
        fireAndForget: Boolean? = null,
    )

    fun onAppToWebResponse(
        requestId: String?,
        isSuccess: Boolean,
        responseData: String?,
    )
}

DefaultDariInterceptor

DefaultDariInterceptor is the debug implementation. It stores messages in Dari's Room database and posts notifications.

val interceptor = Dari.createInterceptor(tag = "PaymentBridge")

Use Dari.createInterceptor() in app code so release builds compile against dari-noop. The optional tag labels messages by bridge source when multiple interceptors are active in the same app.

Protocol Buffers (optional)

Protobuf inspection has no feature flag and does not replace the string/JSON API. See the Protocol Buffers guide for activation requirements, decoder setup, bridge transport options, and all request/response methods.

Methods

onWebToAppRequest

Called when JavaScript sends a message to the native side.

ParameterTypeDescription
handlerNameStringBridge handler name
requestIdString?Unique ID for pairing with a response. null = standalone
requestDataString?Request payload
fireAndForgetBoolean?null = use global config, true = resolve immediately, false = wait for response

onWebToAppResponse

Called when the native side sends a response back to JavaScript.

ParameterTypeDescription
handlerNameStringMust match the request
requestIdString?Must match the request's requestId
responseDataString?Response payload
isSuccessBooleantrueSUCCESS, falseERROR

onAppToWebRequest

Called when the native side pushes a message to JavaScript.

onAppToWebResponse

Called when JavaScript responds to a native-initiated message.

Fire-and-Forget

One-way calls that never receive a response can be marked so they immediately resolve to SUCCESS:

// Per-call
interceptor?.onWebToAppRequest(
    handlerName = "logEvent",
    requestId = null,
    requestData = """{"event": "button_click"}""",
    fireAndForget = true,
)

// Global setting: all calls
DariConfig(fireAndForget = true)

On this page