Skip to content

Commit 1ad7caa

Browse files
author
Capacitor+ Bot
committed
chore: sync upstream PR ionic-team#7709 from @phal0r
2 parents 4c7c126 + 7f664d6 commit 1ad7caa

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.getcapacitor;
2+
3+
public interface IMessageHandler {
4+
/**
5+
* Posts a message to a JavaScript context. It is expected to be a stringified JSON representation
6+
*
7+
* @param message The stringified json to be posted.
8+
*/
9+
void postMessage(String message);
10+
11+
/**
12+
* Sends a response message.
13+
*
14+
* @param call the plugin call, which is attached to the communication
15+
* @param successResult the result of the native execution
16+
* @param errorResult the error, that might have occured
17+
*
18+
*/
19+
void sendResponseMessage(PluginCall call, PluginResult successResult, PluginResult errorResult);
20+
}

android/capacitor/src/main/java/com/getcapacitor/MessageHandler.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* MessageHandler handles messages from the WebView, dispatching them
1212
* to plugins.
1313
*/
14-
public class MessageHandler {
14+
public class MessageHandler implements IMessageHandler {
1515

1616
private Bridge bridge;
1717
private WebView webView;
@@ -49,6 +49,7 @@ public MessageHandler(Bridge bridge, WebView webView, PluginManager cordovaPlugi
4949
*/
5050
@JavascriptInterface
5151
@SuppressWarnings("unused")
52+
@Override
5253
public void postMessage(String jsonStr) {
5354
try {
5455
JSObject postData = new JSObject(jsonStr);
@@ -98,6 +99,7 @@ public void postMessage(String jsonStr) {
9899
}
99100
}
100101

102+
@Override
101103
public void sendResponseMessage(PluginCall call, PluginResult successResult, PluginResult errorResult) {
102104
try {
103105
PluginResult data = new PluginResult();

android/capacitor/src/main/java/com/getcapacitor/PluginCall.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class PluginCall {
1919
*/
2020
public static final String CALLBACK_ID_DANGLING = "-1";
2121

22-
private final MessageHandler msgHandler;
22+
private final IMessageHandler msgHandler;
2323
private final String pluginId;
2424
private final String callbackId;
2525
private final String methodName;
@@ -33,7 +33,7 @@ public class PluginCall {
3333
@Deprecated
3434
private boolean isReleased = false;
3535

36-
public PluginCall(MessageHandler msgHandler, String pluginId, String callbackId, String methodName, JSObject data) {
36+
public PluginCall(IMessageHandler msgHandler, String pluginId, String callbackId, String methodName, JSObject data) {
3737
this.msgHandler = msgHandler;
3838
this.pluginId = pluginId;
3939
this.callbackId = callbackId;

0 commit comments

Comments
 (0)