Listen for events

Most native features return their result on an event. Use bdk.on(event, listener) to subscribe.

Subscribe to an event

Register a listener for a native event. The payload is typed from the event name (see BdkNativeEvents). Subscribe right after createBdkNative() so you don't miss a result. bdk.on returns an unsubscribe function — call it on unmount.

import { createBdkNative } from "@bdk/native/browser";

const bdk = createBdkNative();

const off = bdk.on("deviceInfo", (info) =>
  console.log(info.deviceOS, info.bdkRelease, info.playerId)
);

off(); // stop listening

Get the result of a call

Subscribe before you call the method. Awaiting the call confirms it was dispatched, not that it succeeded — the result arrives on the event. Some events fire quickly (photos, barcode, location, pickers, popups, contacts, screenshots); others may resolve much later or never (purchases, receipts, biometrics, Smart Login).

iap.purchaseIos / purchaseAndroid take { id, type }, where type is "product" or "subscription". Match these key names exactly — they are the native contract.

bdk.on("barcodeScanned", (code) => console.log("scanned", code));
bdk.on("location", (loc) => console.log("location", loc));

await bdk.media.scanBarcode();
await bdk.location.getCurrentPosition();

All events and payloads

Every event and the payload its listener receives. The field-level shape of each object is in Objects.

EventListener receives
deviceInfoBdkDeviceInfo
photoSelected / photoCapturedMediaResult
audioRecordedMediaResult
screenshotthe captured screenshot image (a data URI you can preview or upload)
barcodeScannedthe scanned code: its type and decoded content
contactsthe device address book: each contact's name, phone numbers, and emails
locationthe device location: latitude, longitude, address
backgroundLocationEnabled{ enabled, alreadyRunning, reason }
backgroundLocationDisabled{ enabled }
deviceVariable{ name, data }
menuClickedthe menu item the user tapped
popupClosedwhich button dismissed the popup
datePickedthe date/time the user selected
optionPickedthe option the user chose
backButtonPressedundefined
biometricResult{ data, status, platform }
smartLoginCredentials{ email, password }
purchaseSuccess / purchaseFailed{ platform, data }
receiptReceived{ platform, data }
errorBdkError
// The payload type is inferred from the event name.
bdk.on("deviceInfo", (info) => info.playerId);          // BdkDeviceInfo
bdk.on("photoCaptured", (photo) => photo.fileUrl);       // MediaResult
bdk.on("biometricResult", ({ status, platform }) => {}); // { data, status, platform }
bdk.on("error", (err) => err.code);                      // BdkError

Handle errors

A throwing listener doesn't break the others. Catch errors centrally via the error event or the onError config callback — both receive a BdkError.

bdk.on("error", (err) => console.error(err.code, err.message, err.details));

// or at init:
const bdk = createBdkNative({
  onError: (err) => reportToSentry(err)
});