binaryminds / react-native-sse

Event Source implementation for React Native. Server-Sent Events (SSE) for iOS and Android 🚀
https://www.npmjs.com/package/react-native-sse
MIT License
175 stars 27 forks source link

Not Working in android #3

Closed tmirun closed 2 years ago

tmirun commented 3 years ago

in iOS work fine but in android it's not working I use android 10 with react native version 0.64.0

wojciechkrol commented 3 years ago

Hello @tmirun,

We have project in React Native 0.64.2 and we haven't noticed any issues on Android 10. Please, show us your code, console output if has errors etc. Without more details we can't help you.

tmirun commented 3 years ago

I simply copied the code in the readme, using my SSE URL with basic auth

it happens in debug mode

const url = new URL('xxxxxxxxxxxx');

    const es = new EventSource(url, {
      headers: {
        Authorization: "Basic xxxxxxxx";
      },
    });

    const listener: EventSourceListener = (event) => {
      if (event.type === "open") {
        console.log("Open SSE connection.");
      } else if (event.type === "message") {
        console.log(`Received book ${event.data}`);
      } else if (event.type === "error") {
        console.error("Connection error:", event.message);
      } else if (event.type === "exception") {
        console.error("Error:", event.message, event.error);
      }
    };

    es.addEventListener("open", listener);
    es.addEventListener("message", listener);
    es.addEventListener("error", listener);

    return () => {
      es.removeAllEventListeners();
      es.close();
    };
  }, []);
tmirun commented 3 years ago

I have discoverd where is the bug: https://github.com/facebook/flipper/issues/2495

wojciechkrol commented 3 years ago

Thank you for finding the cause of the problem. We will follow your issue. Please let me know: Do you use URL with react-native-url-polyfill?

From our README:

import "react-native-url-polyfill/auto"; // Use URL polyfill in React Native
tmirun commented 3 years ago

yes, i used "react-native-url-polyfill/auto",

the library in iOS work perfectlly

forster007 commented 2 years ago

Still not working on Android. Any news about it?

Lenny4 commented 2 years ago

@forster007 https://stackoverflow.com/questions/69235694/react-native-cant-connect-to-sse-in-android/69235695#answer-69235695

wojciechkrol commented 2 years ago

Since this issue is connected with Flipper (in debug mode) and no possible fix on our side I'm closing this issue.

Just disable debugger/debug mode, or follow instructions above to disable Flipper network plugin.