Skip to content
This repository has been archived by the owner on Apr 15, 2023. It is now read-only.

cant connect to server sent events #34

Open
kennethsimon opened this issue Aug 7, 2020 · 3 comments
Open

cant connect to server sent events #34

kennethsimon opened this issue Aug 7, 2020 · 3 comments

Comments

@kennethsimon
Copy link

if i console data from server , it doesnt work , please help my code is as below
const getMessages = () => {
console.log('ken')
const eventSource = new RNEventSource('https://328f2c2d8b21.ngrok.io/sse2');
eventSource.addEventListener("message", (data) => {
console.log(data.data);
});
}

getMessages();

@fkurniaw
Copy link

fkurniaw commented Aug 30, 2020

which platform are you running this on?

i was able to get this library working on iOS, but not android

it seems like the xhr onreadystatechange callback on android isn't invoked when it receives data; it's only triggered when the server-side connection is closed

@TheSalarKhan
Copy link

Yep this does not work on Android unless the connection is closed on the server side. one approach with which this can be made to work is after we have sent the data that we want from the server we close the connection. But for that to happen correctly there needs to be some state management on the server side.

Or, if you can risk using native modules non-javascript based then there are plenty. I'm using: https://github.com/ExpandoPakistan/react-native-eventsource.

But there's a catch! these are not a pure Javascript implementations and may break if the repositories go un maintained.

@thiago7almeida
Copy link

Try to disable Flipper network interceptor. Go to android/app/src/debug/java//ReactNativeFlipper.java and comment next lines of code:

  // try to comment this code
  NetworkingModule.setCustomClientBuilder(
    new NetworkingModule.CustomClientBuilder() {
      @Override
      public void apply(OkHttpClient.Builder builder) {
        builder.addNetworkInterceptor(new     FlipperOkhttpInterceptor(networkFlipperPlugin));
      }
    }
  );

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

No branches or pull requests

4 participants