Fastboard is built on top of Whiteboard SDK, which uses DSBridge for bidirectional communication between Native and JavaScript. By accessing WhiteBoardView, you can implement custom JavaScript interaction features.
FastRoom provides direct access to WhiteBoardView:
let fastRoom = Fastboard.createFastRoom(withFastRoomConfig: config)
let whiteboardView = fastRoom.view.whiteboardViewWhiteBoardView inherits from DWKWebView, providing complete JavaScript bridging capabilities.
fastRoom.view.whiteboardView.callHandler("methodName", arguments: ["arg1", "arg2"])fastRoom.view.whiteboardView.callHandler("methodName",
arguments: ["arg1", "arg2"]) { result in
if let data = result {
print("JS returned: \(data)")
}
}@objc class CustomJSBridge: NSObject {
@objc func showMessage(_ message: String) -> String {
print("Message from JS: \(message)")
// Show alert or handle message
return ""
}
@objc func getValue(_ args: Any, handler: JSCallback) {
handler("success", true)
}
}let customBridge = CustomJSBridge()
fastRoom.view.whiteboardView.addJavascriptObject(customBridge, namespace: "custom")After registration, you can call from JavaScript like this:
// Synchronous call
bridge.call("custom.showMessage", "Whiteboard Bridge Room registered");
// Asynchronous call
const result = await bridge.asyncCall("custom.getValue", [1, 2]);- Thread Safety: All JavaScript-related calls should be executed on the main thread
- Memory Management: Be careful to avoid retain cycles, especially use
weak selfin closures - Type Conversion: Data between JavaScript and Native is automatically converted. Supported types include:
- Number (NSNumber)
- String (NSString)
- Boolean (NSNumber)
- Array (NSArray)
- Object (NSDictionary)
- null/undefined (nil)
- Method Naming: Native method names are automatically converted to camelCase for JavaScript
- Return Values: Asynchronous methods need to use
JSCallbackto return results