Architecture
The iOS Calls-shopper SDK is a thin native shell around the same web-based video-call widget that runs in the browser. All video, WebRTC, agent tooling, and UI rendering happens inside a single WKWebView. The Swift side provides:
- a stable native API surface (
BambuserCallController,BambuserCallHandlers,BambuserCallDelegate) - a JS bridge that translates between native calls and the widget's JS event stream
- platform surfaces (SwiftUI overlay, UIKit host view, passthrough UIWindow) so the WebView can be embedded in any host app without leaking WebView details
Layer overview
┌───────────────────────────────────────────────────────────────┐
│ Your app (SwiftUI or UIKit) │
│ ├─ BambuserCallOverlay(controller:) (SwiftUI) │
│ ├─ BambuserCallHostView(controller:) (UIKit inline) │
│ └─ BambuserCallWindowPresenter.attach(to:) (UIKit window) │
└──────────────────────────────┬────────────────────────────────┘
│
┌──────────────────────────────▼───────────────────────────── ───┐
│ BambuserCallViewController (single WebView owner) │
│ ├─ WKWebView + WKUserContentController + WKUIDelegate │
│ ├─ Full-screen ↔ PiP transitions (UIView.animate) │
│ ├─ PiP drag (UIPanGestureRecognizer) │
│ └─ Safe-area propagation into WKWebView │
└──────────────────────────────┬────────────────────────────────┘
│ JS ↔ native message bridge
┌──────────────────────────────▼────────────────────────────────┐
│ BambuserCallController │
│ ├─ Public API: show(), close(), enterPiP(), notify*(), │
│ │ updateData(), updateElement(), destroy(), setQueue()… │
│ ├─ Observable state (@Published isVisible / isPiP / │
│ │ callState / connectId / queue / environment) │
│ └─ Delegate + Handlers wiring │
└──────────────────────────────┬────────────────────────────────┘
│
┌──────────────────────────────▼────────────────────────────────┐
│ EmbedHTMLBuilder + EmbedEventRouter (internal) │
│ ├─ HTML template with document-start shim │
│ ├─ oneToOneEmbed(…) constructor call │
│ ├─ Conditional .on(...) subscriptions │
│ └─ Bidirectional message routing │
└──────────────────────────────┬────────────────────────────────┘
│ loads
┌──────────────────────────────▼────────────────────────────────┐
│ Bambuser Video Call Widget (Web, WebRTC, LiveKit, …) │
└───────────────────────────────────────────────────────────────┘
Why WebView-as-core
Bambuser's video-call widget already exists as a mature web application. Rather than reimplementing WebRTC, queue management, agent tooling, chat, tracking, PiP transitions, and every future embed feature on top of AVFoundation, the SDK treats the widget as the source of truth and provides:
- A native controller with observable state, so a SwiftUI app can bind to it or a UIKit app can react to
@Publishedvalues via Combine. - Native handlers (
provideProductData,provideSearchData,shouldAddToCart,shouldUpdateCart) for data merchants need to keep on-device (personalisation, region-locked catalogues, live pricing). - A native delegate for fire-and-forget events (checkout, navigate-to, tracking, queue status).
- Native presentation control (full-screen ↔ PiP with a draggable mini-player).
Merchants get every widget improvement automatically, without a new SDK release, and the SDK stays small and stable.
The single WebView
There is exactly one WKWebView created by the SDK, in BambuserCallViewController.mountWebViewIfNeeded(). Both mount surfaces route to it:
- SwiftUI —
BambuserCallOverlayis aUIViewControllerRepresentablethat hostsBambuserCallViewController. - UIKit (inline) —
BambuserCallHostViewembedsBambuserCallViewControlleras a child VC with pass-through hit-testing. - UIKit (window) —
BambuserCallWindowPresentermountsBambuserCallViewControlleras the root VC of aPassthroughWindowthat sits above the app's main window.
One JS bridge, one script-message handler, one shim, one presentation stack.
JS bridge
The bridge uses WKWebView's native WKScriptMessageHandler under the name nativeBridge. The document-start user script forwards two kinds of things into it:
- Events from the embed's
.on(...)subscriptions (queue open, agents online, checkout, navigate-to, tracking, cart intents, product / search data requests). - Cross-frame
postMessageevents from the widget's own iframe (viewport-mode changes for PiP).
Native calls go the other direction via WKWebView.evaluateJavaScript(...) — BambuserCallController.notify(...) for callback replies, .invoke(...) for methods on the oneToOneEmbed instance, .notifyProductNavigation(...) for co-browse echoes, and so on.
Data-source handlers
Anything the widget needs a value back from goes through BambuserCallHandlers. Four closures, all async:
provideProductData— return aBambuserFactorySpecfor a specific product reference (SKU, URL, or barcode).provideSearchData— return aBambuserFactorySpecwith paginated search results.shouldAddToCart— accept or reject an add-to-cart intent.shouldUpdateCart— accept or reject a cart-quantity update.
The SDK only installs a JS .on(...) subscription for handlers that are non-nil — nothing is sent across the bridge that the host isn't ready to answer.
Fire-and-forget events
The BambuserCallDelegate protocol receives a BambuserCallEvent for every event the SDK does not need a reply to: .close, .callStateChanged, .presentationChanged, .checkout, .chatRequested, .navigateTo, .queueOpened, .queueClosed, .agentsOnlineChanged, .waitingTimeChanged, .trackingEvent, and a catch-all .other.
Native presentation
BambuserCallViewController owns:
- A constraint set for full-screen and PiP, activated / deactivated on
controller.isPiPchanges. - A
UIView.animatespring for the size transition. - A
UIPanGestureRecognizerthat only fires in PiP so it doesn't compete with WebKit's own gesture recognizers in full-screen. - Safe-area propagation so the widget's own
env(safe-area-inset-*)CSS resolves correctly under both hosting modes.
Everything above is built on top of the same one WebView, so a fix in one place fixes SwiftUI and UIKit hosts simultaneously.