Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't get the readme example to work #23

Open
madhums opened this issue Jan 17, 2020 · 1 comment
Open

Can't get the readme example to work #23

madhums opened this issue Jan 17, 2020 · 1 comment

Comments

@madhums
Copy link

madhums commented Jan 17, 2020

Hi, I've tried to get this library to work but it's really not my cup of tea. I've spent a day and I am not getting anywhere. I'd like to share some progress I made, hope it helps others or the author himself to resolve issues.

To get this library partially working, I did the following:

  1. PR add podspec #22
  2. npx react-native link react-native-http-bridge
    cd ios && pod install && cd ..
    expo start -c
    

P.S: I have ejected expo 36.0.0 (which I think uses RN 0.61.4)

Example code:

import HttpBridge from 'react-native-http-bridge'

HttpBridge.start(5555, 'http_service', function(req) {
  console.log(req); // this function gets called 3 times for some reason
  HttpBridge.respond(
    req.requestId,
    200,
    'application/json',
    '{"message": "OK"}' // not able to receive this response
  );
});

fetch('http://127.0.0.1:5555/users')
  .then(console.log) // no response here

iOS Build failures:
There are two locations where xcode build fails

  1. start method. throws "// throws Use of undeclared identifier '_requestResponses'"

    - _requestResponses = [[NSMutableDictionary alloc] init]; 
    + NSMutableDictionary *_requestResponses = [[NSMutableDictionary alloc] init];
  2. respond method. throws "Thread 4: EXC_BAD_ACCESS (code=1, address=0x10)"

    - completionBlock(requestResponse);
    + if (completionBlock) completionBlock(requestResponse);

These changes seem to succeed the build but I am not sure if they have any side affects.

Logs:

Object {
  "requestId": "1579266250521:175873",
  "type": "GET",
  "url": "/users",
}
Object {
  "requestId": "1579266250524:571040",
  "type": "GET",
  "url": "/users",
}
Object {
  "requestId": "1579266250526:557842",
  "type": "GET",
  "url": "/users",
}

Network request failed
- node_modules/whatwg-fetch/dist/fetch.umd.js:473:29 in xhr.onerror
- node_modules/event-target-shim/dist/event-target-shim.js:818:39 in EventTarget.prototype.dispatchEvent
- node_modules/react-native/Libraries/Network/XMLHttpRequest.js:574:29 in setReadyState
- node_modules/react-native/Libraries/Network/XMLHttpRequest.js:388:25 in __didCompleteResponse
- node_modules/react-native/Libraries/vendor/emitter/EventEmitter.js:190:12 in emit
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:436:47 in __callFunction
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:111:26 in __guard$argument_0
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:384:10 in __guard
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:110:17 in __guard$argument_0
* [native code]:null in callFunctionReturnFlushedQueue

On Android I was unable to get the "react-native link" work, so it's unable to recognise start() method and throws

[Unhandled promise rejection: TypeError: null is not an object (evaluating 'Server.start')]
- node_modules/react-native-http-bridge/httpServer.js:13:12 in module.exports.start
- node_modules/regenerator-runtime/runtime.js:45:44 in tryCatch
- node_modules/regenerator-runtime/runtime.js:271:30 in invoke
- node_modules/regenerator-runtime/runtime.js:45:44 in tryCatch
@Alwinator
Copy link

@madhums Feel free to checkout: react-native-http-bridge-refurbished

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants