Closed sudharsan1988 closed 8 years ago
do you have the same runtime error on the sample app ?
I tried the sample and it worked well. I found what I was missing.
`worker.postMessage("hello from application");
/* get message from worker. String only ! */ worker.onmessage = (message) => {
}`
but I changed it to below as per the example,
componentDidMount() { // create a new worker this.worker = new Worker('App/Containers/worker.js'); // receive messages from worker this.worker.onmessage = (message) => { console.log("Got message from worker", message); } }
From:
const worker = new Worker("./worker.js");
I changed it to,
this.worker = new Worker('App/Containers/worker.js');
I really appreciate your help and sorry for the trouble :)
I also have another question, it works only when the app is active but I thought "worker" would work even the app is killed. Is there anyway we can make it work in the background even after the app is killed or in active?
on iOS there is no way to keep a worker active while in background. on Android it is possible using Service. The lib will be updated to allow Service creation.
@devfd , thanks again for your help. Yes, I am trying to get it done on Android. Very excited to see the updated version with Service creation.
Hi @devfd , many thanks for the updated version :) I ran into some issues when I try to use the latest version,
I am using RN 0.30.0 on a Ubuntu 14.04.4 machine
Issue #1: RNPM link gives build error, so I went with manual and that worked for me
Issue #2: When I try to use "new Worker()", it throws an error saying that
Here is what I am doing,
I created a worker.js file on the same directory of my container and called the worker as follows,
`import { Worker } from 'react-native-workers';
/* start worker */ const worker = new Worker("./worker.js");`
Here is the content in my worker.js
`import { self } from 'react-native-workers';
/* get message from application. String only ! */ self.onmessage = (message) => { }
/* post message to application. String only ! */ self.postMessage("hello from worker");`
Am I missing something here?