use RCTDeviceEventEmitter to send events to javascript; implements #195
This commit is contained in:
parent
22332e0781
commit
82bc347735
|
@ -139,7 +139,7 @@ dependencies {
|
|||
compile project(':react-native-image-crop-picker')
|
||||
compile project(':react-native-webview-bridge')
|
||||
//compile(name:'statusgo-android-16', ext:'aar')
|
||||
compile(group: 'status-im', name: 'status-go', version: '0.1.0-574f67', ext: 'aar')
|
||||
compile(group: 'status-im', name: 'status-go', version: '0.1.0-574f68-service', ext: 'aar')
|
||||
|
||||
compile fileTree(dir: "node_modules/realm/android/libs", include: ["*.jar"])
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.os.Bundle;
|
|||
import android.os.Message;
|
||||
import android.os.RemoteException;
|
||||
import com.facebook.react.bridge.*;
|
||||
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
||||
import com.statusim.geth.service.ConnectorHandler;
|
||||
import com.statusim.geth.service.GethConnector;
|
||||
import com.statusim.geth.service.GethMessages;
|
||||
|
@ -113,6 +114,11 @@ class GethModule extends ReactContextBaseJavaModule implements LifecycleEventLis
|
|||
callback.invoke(result);
|
||||
}
|
||||
break;
|
||||
case GethMessages.MSG_GETH_EVENT:
|
||||
String event = data.getString("event");
|
||||
WritableMap params = Arguments.createMap();
|
||||
params.putString("jsonEvent", event);
|
||||
getReactApplicationContext().getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit("gethEvent", params);
|
||||
default:
|
||||
isClaimed = false;
|
||||
}
|
||||
|
@ -233,21 +239,4 @@ class GethModule extends ReactContextBaseJavaModule implements LifecycleEventLis
|
|||
|
||||
geth.completeTransaction(callbackIdentifier, hash, password);
|
||||
}
|
||||
|
||||
private static Callback signalEventCallback;
|
||||
|
||||
//todo: move this method to GethService
|
||||
public static void signalEvent(String jsonEvent) {
|
||||
Log.d(TAG, "Signal event: " + jsonEvent);
|
||||
if(signalEventCallback != null) {
|
||||
signalEventCallback.invoke(jsonEvent);
|
||||
}
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void registerSignalEventCallback(Callback callback) {
|
||||
Log.d(TAG, "registerSignalEventCallback");
|
||||
signalEventCallback = callback;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -63,4 +63,8 @@ public class GethMessages {
|
|||
*/
|
||||
public static final int MSG_TRANSACTION_COMPLETED = 11;
|
||||
|
||||
/**
|
||||
* Geth event
|
||||
*/
|
||||
public static final int MSG_GETH_EVENT = 12;
|
||||
}
|
||||
|
|
|
@ -21,6 +21,8 @@ public class GethService extends Service {
|
|||
|
||||
private static String dataFolder;
|
||||
|
||||
private static Messenger applicationMessenger = null;
|
||||
|
||||
private static class IncomingHandler extends Handler {
|
||||
|
||||
private final WeakReference<GethService> service;
|
||||
|
@ -49,7 +51,10 @@ public class GethService extends Service {
|
|||
Log.d(TAG, "Signal event: " + jsonEvent);
|
||||
Bundle replyData = new Bundle();
|
||||
replyData.putString("event", jsonEvent);
|
||||
//createAndSendReply(message, GethMessages.MSG_SIGNAL_EVENT, replyData);
|
||||
|
||||
Message replyMessage = Message.obtain(null, GethMessages.MSG_GETH_EVENT, 0, 0, null);
|
||||
replyMessage.setData(replyData);
|
||||
sendReply(applicationMessenger, replyMessage);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -221,6 +226,7 @@ public class GethService extends Service {
|
|||
}
|
||||
|
||||
private void login(Message message) {
|
||||
applicationMessenger = message.replyTo;
|
||||
Bundle data = message.getData();
|
||||
String address = data.getString("address");
|
||||
String password = data.getString("password");
|
||||
|
@ -230,6 +236,9 @@ public class GethService extends Service {
|
|||
Bundle replyData = new Bundle();
|
||||
replyData.putString("result", result);
|
||||
createAndSendReply(message, GethMessages.MSG_LOGGED_IN, replyData);
|
||||
|
||||
// Test signalEvent
|
||||
//signalEvent("{ \"type\": \"test\", \"event\": \"test event\" }");
|
||||
}
|
||||
|
||||
private void completeTransaction(Message message){
|
||||
|
@ -271,9 +280,7 @@ public class GethService extends Service {
|
|||
private static void sendReply(Messenger messenger, Message message) {
|
||||
try {
|
||||
messenger.send(message);
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
Log.e(TAG, "Exception sending message id: " + message.what, e);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,14 +6,8 @@
|
|||
(when (exists? (.-NativeModules r/react-native))
|
||||
(.-Geth (.-NativeModules r/react-native))))
|
||||
|
||||
(defn register-signal-callback []
|
||||
(when geth
|
||||
(.registerSignalEventCallback
|
||||
geth
|
||||
#(do (dispatch [:signal-event %])
|
||||
(register-signal-callback)))))
|
||||
|
||||
(register-signal-callback)
|
||||
(.addListener r/device-event-emitter "gethEvent"
|
||||
#(dispatch [:signal-event (.-jsonEvent %)]))
|
||||
|
||||
(defn start-node [on-result on-already-running]
|
||||
(when geth
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
(def react-native (u/require "react-native"))
|
||||
(def native-modules (.-NativeModules react-native))
|
||||
(def device-event-emitter (.-DeviceEventEmitter react-native))
|
||||
(def geth (.-Geth native-modules))
|
||||
(def react-native-dialogs (u/require "react-native-dialogs"))
|
||||
|
||||
|
|
Loading…
Reference in New Issue