'How to listen to server side events in React Native?

I am setting up server-sent events on my Expo React Native App via react-native-event-source library .

With the function below, I should have data logged every 10 seconds. But nothing is printed in the console. Am I missing something?

  getTodayMissions() {
    ...
    const options = { headers: { Authorization: `Bearer ${token}` } };
    const eventsurl = `${BASE_URL}/server-events/`;
    const eventSource = new RNEventSource(eventsurl, options);
    const url = `missionstodayapp?userId=${user.id}`;


    console.log('start the watch', eventsurl, url);
    this.eventSource.addEventListener(url, (data) => {
      console.log('started the watch', data);
    });
  }


Solution 1:[1]

If you are using android studio emulator, you should use 10.0.0.2 instead of localhost or 127.0.0.1 for your base URL.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 exaucae