Skip to main content

Add to wishlist

Wishlist integration connects the Bambuser player's wishlist UI to your app's native wishlist. Handle the five wishlist events in your BambuserVideoPlayerDelegate.

1. Provide Wishlist Status

When the player loads, it fires provide-wishlist-status to learn which products are already wishlisted. Respond by calling viewAction.invoke("updateWishlistStatus", ...) with a JSON map of sku → Bool.

"provide-wishlist-status" -> {
val products = event.data["products"] as? List<Map<*, *>> ?: return

val statusMap = products.mapNotNull { product ->
val sku = product["ref"] as? String ?: return@mapNotNull null
sku to YourWishlistService.isInWishlist(sku)
}.toMap()

val payload = mapOf("statuses" to statusMap)
val jsonString = Gson().toJson(payload)

lifecycleScope.launch {
viewAction.invoke("updateWishlistStatus", jsonString)
}
}

2. Add to Wishlist

Fires when a user taps the wishlist button on a product not yet wishlisted.

"add-to-wishlist" -> {
val callbackKey = event.callbackKey ?: return
val sku = event.data["ref"] as? String ?: return

lifecycleScope.launch {
YourWishlistService.add(sku)
viewAction.notifyView(callbackKey, "{success: true, sku:'$sku'}")
}
}

3. Remove from Wishlist

Fires when a user taps the wishlist button on an already-wishlisted product.

"remove-from-wishlist" -> {
val callbackKey = event.callbackKey ?: return
val sku = event.data["ref"] as? String ?: return

lifecycleScope.launch {
YourWishlistService.remove(sku)
viewAction.notifyView(callbackKey, "{success: true, sku:'$sku'}")
}
}

4. Open Wishlist

Fires when a user taps View Wishlist. Navigate to your app's native wishlist screen. No callback response is required.

"open-wishlist" -> {
withContext(Dispatchers.Main) {
navigateToWishlist()
}
}

5. Open Wishlist Login

Fires when an unauthenticated user attempts to wishlist a product. Show a login prompt and notifyView with the result.

"open-wishlist-login" -> {
val callbackKey = event.callbackKey ?: return

withContext(Dispatchers.Main) {
showLoginPrompt {
lifecycleScope.launch {
viewAction.notifyView(callbackKey, "{ success: true }")
}
}
}
}

Complete Handler

val videoPlayerDelegate = object : BambuserVideoPlayerDelegate {
override fun onNewEventReceived(
playerId: String,
event: BambuserEventPayload,
viewAction: ViewActions
) {
when (event.event) {

"provide-wishlist-status" -> {
val products = event.data["products"] as? List<Map<*, *>> ?: return
val statusMap = products.mapNotNull { product ->
val sku = product["ref"] as? String ?: return@mapNotNull null
sku to YourWishlistService.isInWishlist(sku)
}.toMap()
lifecycleScope.launch {
viewAction.invoke("updateWishlistStatus", Gson().toJson(mapOf("statuses" to statusMap)))
}
}

"add-to-wishlist" -> {
val callbackKey = event.callbackKey ?: return
val sku = event.data["ref"] as? String ?: return
lifecycleScope.launch {
YourWishlistService.add(sku)
viewAction.notifyView(callbackKey, "{success: true, sku:'$sku'}")
}
}

"remove-from-wishlist" -> {
val callbackKey = event.callbackKey ?: return
val sku = event.data["ref"] as? String ?: return
lifecycleScope.launch {
YourWishlistService.remove(sku)
viewAction.notifyView(callbackKey, "{success: true, sku:'$sku'}")
}
}

"open-wishlist" -> {
withContext(Dispatchers.Main) { navigateToWishlist() }
}

"open-wishlist-login" -> {
val callbackKey = event.callbackKey ?: return
withContext(Dispatchers.Main) {
showLoginPrompt {
lifecycleScope.launch {
viewAction.notifyView(callbackKey, "{ success: true }")
}
}
}
}
}
}

override fun onErrorOccurred(playerId: String, error: Exception) { }
}

Event Summary

EventHas callbackKeyResponse
provide-wishlist-statusNoviewAction.invoke("updateWishlistStatus", jsonString)
add-to-wishlistYesviewAction.notifyView(callbackKey, "{success: true, sku:'...'}")
remove-from-wishlistYesviewAction.notifyView(callbackKey, "{success: true, sku:'...'}")
open-wishlistNoNavigate to wishlist screen
open-wishlist-loginYesShow login → viewAction.notifyView(callbackKey, "{ success: true }")

ℹ️ On Android, callbackKey is accessed as event.callbackKey (top-level field), not from event.data. See Delegate Protocol for the full payload structure.