binaryminds/react-native-sse

Not Working in android

Closed this issue · 8 comments

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

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.

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();
    };
  }, []);

I have discoverd where is the bug:
facebook/flipper#2495

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

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

the library in iOS work perfectlly

Still not working on Android. Any news about it?

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.