Skip to content

InteropCall

Calls a JavaScript function through the JS Interop API, providing the best performance for C++ to JavaScript communication. This method is optimized for high-frequency calls and accepts a string argument to pass data to the JavaScript function.

void InteropCall(
PrismaView view,
const char* functionName,
const char* argument
);
  • Type: PrismaView
  • Description: The PrismaView instance in which the function will be called
  • Type: const char*
  • Description: The name of the JavaScript function to call
  • Note: The function must be globally accessible (e.g., attached to window)
  • Type: const char*
  • Description: A string argument to pass to the JavaScript function
  • Note: Only accepts string data - use JSON for complex data structures

This method returns void. Unlike Invoke, InteropCall does not support return value callbacks for maximum performance.

// Simple function call with string argument
PrismaUI->InteropCall(view, "updatePlayerName", "Dragonborn");
// JavaScript function to receive the call
window.updatePlayerName = (playerName) => {
document.getElementById('player-name').textContent = playerName;
};
MethodPerformanceReturn ValuesUse Case
InteropCallHighestNoFrequent updates, real-time data
InvokeStandardYesComplex operations, one-time calls
  • Performance Critical: Use for high-frequency calls and real-time updates
  • String Arguments: Always pass data as strings - use JSON for complex structures
  • No Return Values: Don’t expect return values - use RegisterJSListener for bidirectional communication
  • Function Availability: Ensure JavaScript functions are globally accessible

If you’re converting from Invoke to InteropCall for performance:

// Before (using Invoke)
PrismaUI->Invoke(view, "updateHealth(100)");
// After (using InteropCall)
PrismaUI->InteropCall(view, "updateHealth", "100");
// JavaScript function needs to accept argument
// Before
window.updateHealth = () => {
// Function was called with embedded argument
};
// After
window.updateHealth = (healthValue) => {
// Function receives argument as parameter
};