mirror of
https://github.com/status-im/realm-js.git
synced 2025-01-27 23:05:19 +00:00
only start webserver in chrome debug mode
This commit is contained in:
parent
a9ef54d65d
commit
b45948eb9a
@ -41,8 +41,11 @@ public class RealmReactAndroid extends ReactContextBaseJavaModule {
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getConstants() {
|
||||
Log.w("RealmReactAndroid", injectRealmJsContext(filesDirPath));
|
||||
startWebServer();
|
||||
long contexts = injectRealmJsContext(filesDirPath);
|
||||
Log.w("RealmReactAndroid", "Initialized " + contexts + " contexts");
|
||||
if (contexts == 0) {
|
||||
startWebServer();
|
||||
}
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
@ -92,7 +95,16 @@ public class RealmReactAndroid extends ReactContextBaseJavaModule {
|
||||
// msg += "<p>Hello, " + parms.get("username") + "!</p>";
|
||||
// }
|
||||
// return newFixedLengthResponse( msg + "</body></html>\n" );
|
||||
String jsonResponse = processChromeDebugCommand(rpcServerPtr, cmdUri);
|
||||
final HashMap<String, String> map = new HashMap<String, String>();
|
||||
try {
|
||||
session.parseBody(map);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ResponseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
final String json = map.get("postData");
|
||||
String jsonResponse = processChromeDebugCommand(rpcServerPtr, cmdUri, json);
|
||||
Response response = newFixedLengthResponse(jsonResponse);
|
||||
response.addHeader("Access-Control-Allow-Origin", "http://localhost:8081");
|
||||
return response;
|
||||
@ -100,9 +112,9 @@ public class RealmReactAndroid extends ReactContextBaseJavaModule {
|
||||
}
|
||||
|
||||
// fileDir: path of the internal storage of the application
|
||||
private native String injectRealmJsContext(String fileDir);
|
||||
private native long injectRealmJsContext(String fileDir);
|
||||
// responsible for creating the rpcServer that will accept thw chrome Websocket command
|
||||
private native long setupChromeDebugModeRealmJsContext();
|
||||
// this receives one command from Chrome debug, & return the processing we should post back
|
||||
private native String processChromeDebugCommand(long rpcServerPointer, String cmd);
|
||||
private native String processChromeDebugCommand(long rpcServerPointer, String cmd, String args);
|
||||
}
|
||||
|
@ -18,13 +18,14 @@
|
||||
* Method: injectRealmJsContext
|
||||
* Signature: ()Ljava/lang/String;
|
||||
*/
|
||||
JNIEXPORT jstring JNICALL Java_com_reacttests_RealmReactAndroid_injectRealmJsContext
|
||||
JNIEXPORT jlong JNICALL Java_com_reacttests_RealmReactAndroid_injectRealmJsContext
|
||||
(JNIEnv *env, jclass, jstring fileDir)
|
||||
{
|
||||
__android_log_print(ANDROID_LOG_ERROR, "JSRealm", "Java_com_reacttests_RealmReactAndroid_injectRealmJsContext");
|
||||
void* handle = dlopen ("libreactnativejni.so", RTLD_LAZY);
|
||||
if (!handle) {
|
||||
return env->NewStringUTF("Cannot open library");
|
||||
return 0;
|
||||
//return env->NewStringUTF("Cannot open library");
|
||||
}
|
||||
|
||||
// Getting the internal storage path for the application
|
||||
@ -40,16 +41,17 @@ JNIEXPORT jstring JNICALL Java_com_reacttests_RealmReactAndroid_injectRealmJsCon
|
||||
get_jsc_context_t get_jsc_context = (get_jsc_context_t) dlsym(handle, "get_jsc_context");
|
||||
|
||||
if (get_jsc_context != NULL) {
|
||||
std::unordered_map<JSContextRef, facebook::react::JSCExecutor*> s_globalContextRefToJSCExecutor = get_jsc_context();
|
||||
std::stringstream msg;
|
||||
msg << "Got the globalContext map, size=" << s_globalContextRefToJSCExecutor.size();
|
||||
|
||||
for (auto pair : s_globalContextRefToJSCExecutor) {
|
||||
RJSInitializeInContext(pair.first);
|
||||
}
|
||||
return env->NewStringUTF(msg.str().c_str());
|
||||
std::unordered_map<JSContextRef, facebook::react::JSCExecutor*> s_globalContextRefToJSCExecutor = get_jsc_context();
|
||||
for (auto pair : s_globalContextRefToJSCExecutor) {
|
||||
RJSInitializeInContext(pair.first);
|
||||
}
|
||||
return s_globalContextRefToJSCExecutor.size();
|
||||
//std::stringstream msg;
|
||||
//msg << "Got the globalContext map, size=" << s_globalContextRefToJSCExecutor.size();
|
||||
//return env->NewStringUTF(msg.str().c_str());
|
||||
} else {
|
||||
return env->NewStringUTF("Cannot find symbol get_jsc_context");
|
||||
return 0;
|
||||
// return env->NewStringUTF("Cannot find symbol get_jsc_context");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ extern "C" {
|
||||
* Method: injectRealmJsContext
|
||||
* Signature: ()Ljava/lang/String;
|
||||
*/
|
||||
JNIEXPORT jstring JNICALL Java_com_reacttests_RealmReactAndroid_injectRealmJsContext
|
||||
JNIEXPORT jlong JNICALL Java_com_reacttests_RealmReactAndroid_injectRealmJsContext
|
||||
(JNIEnv *, jclass, jstring);
|
||||
|
||||
/*
|
||||
|
Loading…
x
Reference in New Issue
Block a user