Skip to content
This repository has been archived by the owner on Dec 3, 2021. It is now read-only.

Commit

Permalink
pass RPC host to webview bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
rasom committed Mar 8, 2017
1 parent 05a5ff9 commit 1efc97e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

class StatusBridge {
public static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
public static final String URL = "http://localhost:8545";

private WebView webView;
private ThemedReactContext context;
Expand All @@ -33,13 +32,13 @@ public StatusBridge(ThemedReactContext context, WebView webView) {
}

@JavascriptInterface
public void sendRequest(final String callbackId, final String json) {
public void sendRequest(final String host, final String callbackId, final String json) {
Thread thread = new Thread() {
@Override
public void run() {
RequestBody body = RequestBody.create(JSON, json);
Request request = new Request.Builder()
.url(URL)
.url(host)
.post(body)
.build();

Expand All @@ -63,11 +62,11 @@ public void run() {
}

@JavascriptInterface
public String sendRequestSync(final String json) {
public String sendRequestSync(final String host, final String json) {

RequestBody body = RequestBody.create(JSON, json);
Request request = new Request.Builder()
.url(URL)
.url(host)
.post(body)
.build();

Expand Down
3 changes: 2 additions & 1 deletion ios/RCTWKWebView.m
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,15 @@ - (void)sendIt:(NSString *)body
NSData *data = [body dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *responseDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
NSString *callbackId = [responseDic objectForKey:@"callbackId"];
NSString *host = [responseDic objectForKey:@"host"];
NSString *payload = [responseDic objectForKey:@"payload"];

NSData *postData = [payload dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];

NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:@"http://localhost:8545"]];
[request setURL:[NSURL URLWithString:host]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
Expand Down

0 comments on commit 1efc97e

Please sign in to comment.