handleWebViewMessage static method

Future<String> handleWebViewMessage(
  1. String? jsMessage
)

Handles a Hackle command delivered through the WebView message channel.

Unlike handleWebInterfaceCommand, this waits until the command has been fully processed before returning.

jsMessage - The command message received from the message channel.

Returns: the response string to pass back to the WebView.

This method never throws; on failure it returns a default error response so the WebView always receives a reply.

Implementation

static Future<String> handleWebViewMessage(String? jsMessage) async {
  if (jsMessage == null) {
    return BridgeResponse.defaultJsonString("command is not valid");
  }
  try {
    return await HacklePlatform.instance.invokeHackleBridgeAsync(jsMessage);
  } catch (_) {
    return BridgeResponse.defaultJsonString("failed to handle message");
  }
}