Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.getcapacitor;

public interface IMessageHandler {
/**
* Posts a message to a JavaScript context. It is expected to be a stringified JSON representation
*
* @param message The stringified json to be posted.
*/
void postMessage(String message);

/**
* Sends a response message.
*
* @param call the plugin call, which is attached to the communication
* @param successResult the result of the native execution
* @param errorResult the error, that might have occured
*
*/
void sendResponseMessage(PluginCall call, PluginResult successResult, PluginResult errorResult);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* MessageHandler handles messages from the WebView, dispatching them
* to plugins.
*/
public class MessageHandler {
public class MessageHandler implements IMessageHandler {

private Bridge bridge;
private WebView webView;
Expand Down Expand Up @@ -49,6 +49,7 @@ public MessageHandler(Bridge bridge, WebView webView, PluginManager cordovaPlugi
*/
@JavascriptInterface
@SuppressWarnings("unused")
@Override
public void postMessage(String jsonStr) {
try {
JSObject postData = new JSObject(jsonStr);
Expand Down Expand Up @@ -98,6 +99,7 @@ public void postMessage(String jsonStr) {
}
}

@Override
public void sendResponseMessage(PluginCall call, PluginResult successResult, PluginResult errorResult) {
try {
PluginResult data = new PluginResult();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class PluginCall {
*/
public static final String CALLBACK_ID_DANGLING = "-1";

private final MessageHandler msgHandler;
private final IMessageHandler msgHandler;
private final String pluginId;
private final String callbackId;
private final String methodName;
Expand All @@ -33,7 +33,7 @@ public class PluginCall {
@Deprecated
private boolean isReleased = false;

public PluginCall(MessageHandler msgHandler, String pluginId, String callbackId, String methodName, JSObject data) {
public PluginCall(IMessageHandler msgHandler, String pluginId, String callbackId, String methodName, JSObject data) {
this.msgHandler = msgHandler;
this.pluginId = pluginId;
this.callbackId = callbackId;
Expand Down