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

make sure it works with react-native #516

Open
threepointone opened this issue Oct 23, 2023 · 13 comments
Open

make sure it works with react-native #516

threepointone opened this issue Oct 23, 2023 · 13 comments

Comments

@threepointone
Copy link
Contributor

  • we have reports that the react native bundler isn't picking up partysocket
  • we should be able to bind to an IP so devices can read from localhost
  • (add more)
@bndkt
Copy link

bndkt commented Nov 2, 2023

I'm using partysocket in React Native and run into the "ReferenceError: Property 'Event' doesn't exist, js engine: hermes" error, since Event is not available in RN.

When using the polyfill import "event-target-polyfill";, it works but the following error is still thrown: [TypeError: Failed to execute 'dispatchEvent' on 'EventTarget': parameter 1 is not of type 'Event'.]

@jonatansberg
Copy link

I had the same problem with event-target-polyfill. I managed to get everything to work (at least in Expo Go on iOS) using event-target-shim like this:

import { EventTarget, Event } from "event-target-shim";
globalThis.EventTarget = EventTarget;
globalThis.Event = Event;

@OnurKlc
Copy link

OnurKlc commented Nov 16, 2023

I had the same problem with event-target-polyfill. I managed to get everything to work (at least in Expo Go on iOS) using event-target-shim like this:

import { EventTarget, Event } from "event-target-shim";
globalThis.EventTarget = EventTarget;
globalThis.Event = Event;

this does not work for me

@anirudhsama
Copy link

Same, it's not working for me with event-target-shim. I'm using expo dev client.

@ayoubqrt
Copy link
Contributor

so I assume it solved by #636 🫡 ?

@threepointone
Copy link
Contributor Author

Ok, try this with the latest version of partysocket:

import "partysocket/event-target-polyfill";
import {usePartySocket} from "partysocket/dist/react";

// ... and use usePartySocket in your components 

Could any of you try this and lemme know if this works? I'm especially curious about production/release builds.

@threepointone
Copy link
Contributor Author

Here's a solution that definitely works: Use https://www.npmjs.com/package/react-native-use-websocket, and connect to url ${host}/parties/:name/:room (:name is "main" if you're using the default party)

I'm going to investigate more and fix partysocket for react native, but this should unblock you folks for now.

@dabit3
Copy link

dabit3 commented Jan 13, 2024

@threepointone I can confirm this works fine for me in React Native

import "partysocket/event-target-polyfill";
import {usePartySocket} from "partysocket/dist/react";

// ... and use usePartySocket in your components 

@ahanusek
Copy link

@threepointone I can confirm this works fine for me in React Native

import "partysocket/event-target-polyfill";
import {usePartySocket} from "partysocket/dist/react";

// ... and use usePartySocket in your components 

@dabit3

Did you tested in release mode on Android/iOS? In my case on dev mode works fine, but wasn't able to connect in release mode.

@ScreamZ
Copy link

ScreamZ commented Jan 30, 2024

I'm using partysocket in React Native and run into the "ReferenceError: Property 'Event' doesn't exist, js engine: hermes" error, since Event is not available in RN.

When using the polyfill import "event-target-polyfill";, it works but the following error is still thrown: [TypeError: Failed to execute 'dispatchEvent' on 'EventTarget': parameter 1 is not of type 'Event'.]

Same as you in Expo@50 but no issue with Expo@49.

Probably the same issue as react-native-webrtc/react-native-webrtc#1503 (i link them so maybe they can solve it too)

@feychenie
Copy link

FWIW In Expo@50, with import "partysocket/event-target-polyfill"; i ended up with the error "Super Expression must either be null of a function" in ws.ts, on the line with export class ErrorEvent extends Event {.

In the polyfill, Event and EventTarget imported in the first line were undefined. I guess some weird thing with metro or hermes and the module export that it used.

Changing explicitely the import form import { Event, EventTarget } from "event-target-shim" to import { Event, EventTarget } from "event-target-shim/index" fixed the issue.

@moishinetzer
Copy link

Can confirm the above works for partysocket but partysocket/react's usePartySocket still fails to run.

@moishinetzer
Copy link

Update: Even partysocket does not run in production on a real device. @threepointone do you have any thoughts on how to approach this? Happy to submit a PR to help.

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