Skip to content

IOS not working for me #4

@rayhooker

Description

@rayhooker

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions