bugfix and move gcd out of rpc
This commit is contained in:
parent
8b5a8a731c
commit
28e21041bc
|
@ -106,9 +106,14 @@ JSGlobalContextRef RealmReactGetJSGlobalContextForExecutor(id executor, bool cre
|
||||||
processBlock:^GCDWebServerResponse *(GCDWebServerRequest* request) {
|
processBlock:^GCDWebServerResponse *(GCDWebServerRequest* request) {
|
||||||
GCDWebServerResponse *response;
|
GCDWebServerResponse *response;
|
||||||
try {
|
try {
|
||||||
realm_js::json args = realm_js::json::parse([[(GCDWebServerDataRequest *)request text] UTF8String]);
|
// perform all realm ops on the main thread
|
||||||
std::string response_text = rpcServer->perform_request(request.path.UTF8String, args).dump();
|
__block NSData *responseData;
|
||||||
response = [[GCDWebServerDataResponse alloc] initWithData:[NSData dataWithBytes:response_text.c_str() length:response_text.length()] contentType:@"application/json"];
|
dispatch_sync(dispatch_get_main_queue(), ^{
|
||||||
|
realm_js::json args = realm_js::json::parse([[(GCDWebServerDataRequest *)request text] UTF8String]);
|
||||||
|
std::string responseText = rpcServer->perform_request(request.path.UTF8String, args).dump();
|
||||||
|
responseData = [NSData dataWithBytes:responseText.c_str() length:responseText.length()];
|
||||||
|
});
|
||||||
|
response = [[GCDWebServerDataResponse alloc] initWithData:responseData contentType:@"application/json"];
|
||||||
}
|
}
|
||||||
catch(std::exception &ex) {
|
catch(std::exception &ex) {
|
||||||
NSLog(@"Invalid RPC request - %@", [(GCDWebServerDataRequest *)request text]);
|
NSLog(@"Invalid RPC request - %@", [(GCDWebServerDataRequest *)request text]);
|
||||||
|
|
|
@ -146,8 +146,9 @@ RPCServer::RPCServer() {
|
||||||
JSObjectSetPropertyAtIndex(m_context, m_objects[oid], name.get<unsigned int>(), value, &exception);
|
JSObjectSetPropertyAtIndex(m_context, m_objects[oid], name.get<unsigned int>(), value, &exception);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
static JSStringRef prop_string = RJSStringForString(name.get<std::string>());
|
JSStringRef prop_string = RJSStringForString(name.get<std::string>());
|
||||||
JSObjectSetProperty(m_context, m_objects[oid], prop_string, value, 0, &exception);
|
JSObjectSetProperty(m_context, m_objects[oid], prop_string, value, 0, &exception);
|
||||||
|
JSStringRelease(prop_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (exception) {
|
if (exception) {
|
||||||
|
@ -186,25 +187,19 @@ RPCServer::~RPCServer() {
|
||||||
}
|
}
|
||||||
|
|
||||||
json RPCServer::perform_request(std::string name, json &args) {
|
json RPCServer::perform_request(std::string name, json &args) {
|
||||||
// perform all realm ops on the main thread
|
try {
|
||||||
__block json response;
|
RPCRequest action = m_requests[name];
|
||||||
dispatch_sync(dispatch_get_main_queue(), ^{
|
assert(action);
|
||||||
try {
|
|
||||||
RPCRequest action = m_requests[name];
|
|
||||||
assert(action);
|
|
||||||
|
|
||||||
if (name == "/create_session" || m_session_id == args["sessionId"].get<RPCObjectID>()) {
|
if (name == "/create_session" || m_session_id == args["sessionId"].get<RPCObjectID>()) {
|
||||||
response = action(args);
|
return action(args);
|
||||||
assert(response.is_object());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
response = {{"error", "Invalid session ID"}};
|
|
||||||
}
|
|
||||||
} catch (std::exception &exception) {
|
|
||||||
response = {{"error", (std::string)"exception thrown: " + exception.what()}};
|
|
||||||
}
|
}
|
||||||
});
|
else {
|
||||||
return response;
|
return {{"error", "Invalid session ID"}};
|
||||||
|
}
|
||||||
|
} catch (std::exception &exception) {
|
||||||
|
return {{"error", (std::string)"exception thrown: " + exception.what()}};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RPCObjectID RPCServer::store_object(JSObjectRef object) {
|
RPCObjectID RPCServer::store_object(JSObjectRef object) {
|
||||||
|
|
Loading…
Reference in New Issue