Closed nhatter closed 3 years ago
UPDATE:
So I spoke to my CTO and apparently we are calling firebase.init()
in two different contexts:
The problem is that main and worker threads have totally different contexts... and there is no easy way (AFAIK) to pass object references between the main thread and worker threads.
We must call firebase.init from the main thread or else we get "missing initialisation".
But when we try to use firebase from the worker thread, it tells us to call firebase.init()
... the problem is, calling init
in the worker thread then gives us the error: Error in firebase.init - Error: Default app has already been configured
My guess is, however, that there is some persistence between the two as far as Google Firebase is concerned, otherwise we wouldn't be getting this error...
Possible solution:
Ideally, @EddyVerbruggen's nativescript-plugin-firebase
would have an argument in .init
which contains a flag like SKIP_CONFIGURE
And then in the firebase init code line 538 in https://github.com/EddyVerbruggen/nativescript-plugin-firebase/blob/master/src/firebase.ios.ts#L538:
if (!firebase._configured) {
firebase._configured = true;
if (typeof (FIRApp) !== "undefined" && !SKIP_CONFIGURE) {
FIRApp.configure();
}
}
This way, FIRApp.configure()
can be optional and hopefully not keep causing the error....
Or, better yet, find a way to make the plugin perhaps more worker-friendly or to have a "callFromWorker" mode...
Multi-threading is always a bit complex anyway :)
So, I semi-jokingly suggested to my CTO that we "hack core" and try to modify the state variables of @EddyVerbruggen's plugin manually... and it actually worked!
Setting firebase.initialized = true
did the trick :) Apparently we are now able to use Firebase from workers now.
Hi @nhatter I'm attempting to do the same thing. I would be really grateful if you are able to elaborate on this. I am also trying to run a call to firebase from a worker.
What were your exact steps to success?
Thanks.
Hey @EddyVerbruggen, we've just switched to {N} from Ionic :) I'm really excited to see how our app will perform and what it can do with truly native rendering rather than hybrid...
Unfortunately, we're having some trouble running Firebase from within a {N} worker.
As a test, we tried this:
This gives us: "
Error: Please run firebase.init() before running firebase
"So we changed it to:
Now we get a different error: "
Error in firebase.init - Error: Default app has already been configured
"My CTO confirmed that onmessage is only being called once...
Is it possible, @EddyVerbruggen, that your plugin may be trying to call
FIRApp.configure()
twice? I see it being called from:NSNotificationCenter.defaultCenter.addObserverForNameObjectQueueUsingBlock
, and.init()
function - see: https://github.com/EddyVerbruggen/nativescript-plugin-firebase/blob/master/src/firebase.ios.ts(Note: we are building for iOS)
HELPFUL DEBUG INFO
package.json:
firebase.nativescript.json
Note: we are trying to build for iOS