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

[React Native]: Can't find variable: EventSource #135

Closed
anhtuank7c opened this issue Jan 24, 2023 · 3 comments
Closed

[React Native]: Can't find variable: EventSource #135

anhtuank7c opened this issue Jan 24, 2023 · 3 comments

Comments

@anhtuank7c
Copy link

React Native doesn't seem to support EventSource.

image

Should we do something like this https://www.npmjs.com/package/react-native-event-source to be able to support Server-Sent Events on React Native?

this.eventSource = new EventSource(this.client.buildUrl('/api/realtime'))

@anhtuank7c
Copy link
Author

EventSource/eventsource#132
The linked lib from your README file doesn't seem usable for React Native.
Do we have an alternative solution such as socket-io or WebSocket?

@anhtuank7c
Copy link
Author

anhtuank7c commented Jan 24, 2023

I've tried to use this lib to make a connection to PocketBase realtime endpoint, and set view rules to be open for anyone but seem just able to get skipped response.

https://github.com/jordanbyron/react-native-event-source

const eventSource = new RNEventSource(`${endpoint}/api/realtime`);
      eventSource.addEventListener(`COLLECTION_NAME/RECORD_ID`, (e) => {
        console.tron.log('sse', e);
      });

Screenshot 2023-01-24 at 12 06 50

@ganigeorgiev
Copy link
Member

You can check pocketbase/pocketbase#1176 (comment).

import EventSource from "react-native-sse";

// or globalThis depending which is available
global.EventSource = EventSource;

I'll consider updating the README with a note for React Native sometime later today.

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