jacobp100 / react-native-web-worker

MIT License
21 stars 0 forks source link

IOS not working for me #4

Open rayhooker opened 1 year ago

rayhooker commented 1 year ago

I am having trouble getting react-native-webworker to work for me. I am trying to include it in my react native cli project. I am just trying the most basic example. I have installed as per the instructions and pod install. I created a worker.js in the root identical to your example that simply defines the self.onmessage to take a parameter data and to use self.postMessage to send it back to the application. self.onmessage = (data) => { // Message is a string // const message = e.data; self.postMessage(Message from worker: "${data}"!); }; I used the code in the example folder to launch the webworker.
` useEffect(() => { const worker = new WebWorker('./worker.js', // { // enviromnent: 'light', // } ); worker.onmessage = ({ data }) => { console.log("Got a message from worker ", data) setMessages((m) => [...m, data]); }; workerRef.current = worker; // workerRef.current.postMessage("Testing") console.log("Worker loaded", worker, worker.postMessage ) worker.postMessage("Testing") return () => { worker.terminate(); workerRef.current = undefined; }; }, []);

const postMessage = () => {
  workerRef.current.postMessage(`Message ${messages.length + 1}`);
};

....

Messages:{messages.map((message, i) => ( {message} )) ` I can see the log of the postMessage from my app. I even added code to your Javascript code that launches the thread and to the postMessage method in Javascript. I can see the messages from the app going to the thread but no response. I tried reactotron but it does nothing running in the thread. My app is running react native 0.71.6 and react 18.2.0. I have tried running it from npm run ios or launching from XCode but in neither case does to thread code appear to be responding. Any clues or hints as to possible configuration or code issues? Thanks, Ray
jacobp100 commented 1 year ago

Does the example folder work?

rayhooker commented 1 year ago

I tried building/ running it: cd example npm install npx pod-install npx react-native start / npm run ios (two different terminal sessions)

I also set the output to iPhone SE 3rd generation using xcode and assigned a team to the project.

I am getting the error: /Users/rayhooker/Downloads/react-native-webworker-master/ios/RNWWWebWorker.mm:145:44 No member named 'NativeWebWorkerSpecJSI' in namespace 'facebook::react'

I did not see that error in my other project. Any clues?

rayhooker commented 1 year ago

Actually never mind the previous message. I made a change to my app. I had commented out {environment: 'light'} and added it back. It worked but not without the parameter environment: 'light'. Two questions:

Ray

jacobp100 commented 1 year ago

The non-light environment definitely used to work. Can’t guarantee it still does 🤣 it’ll be something minor that’s broken. I’m away for a bit but can take a look when I’m back

tomgreco commented 6 months ago

Did you ever take a look when you got back @jacobp100

jacobp100 commented 6 months ago

No lol. Are you also trying to use the non-light environment?