Git Product home page Git Product logo

Comments (8)

hampoelz avatar hampoelz commented on August 9, 2024 1

Not yet, but you are right, a minimal example would be helpful to get started with this plugin. I will add some example projects in the following weeks.

from capacitor-nodejs.

hampoelz avatar hampoelz commented on August 9, 2024 1

Two example projects are now available. One without additional framework, which is located in the branch example/vanilla. And a second one, which uses the vitejs framework, is located in example/vite.

from capacitor-nodejs.

 avatar commented on August 9, 2024

@lucaengelhard what problem did you actually have though?

I just added this line https://github.com/hampoelz/Capacitor-NodeJS/blob/main/assets/builtin_modules/bridge/main.js#L3 ) and the import of the appChannel to a basic node project and it worked.

I did have problem with cross compiling native dependencies for a much larger project, but i did eventually figure that part out.

from capacitor-nodejs.

lucaengelhard avatar lucaengelhard commented on August 9, 2024

My problem was that after just creating a basic file structure and wanting to test out the functionality, it seemed like there was no connection to the nodejs backend.

What exactly does your code change/fix?

from capacitor-nodejs.

 avatar commented on August 9, 2024

There's the side that you use with capacitor (and perhaps ionic) where you

have something like

await NodeJS.addListener('msg-from-nodejs', cb);
await NodeJS.whenReady();

The thing about whenReady though, is that starts what seems to be a permanent timer (I'm no java expert) in the capacitor plugin code to wait for isNodeEngineReady to equal true. It will never equal true UNTIL it gets a message over the APP_CHANNEL of ready. That's what that line does. That line goes in your nodejs application code.

You can see the ready check here: https://github.com/hampoelz/Capacitor-NodeJS/blob/main/android/src/main/java/net/hampoelz/capacitor/nodejs/NodeJS.java#L115

I don't know java at all really, but it's not too hard to work out what's going on there. I'd suggest you browse around if you have trouble with it actually starting your application.

from capacitor-nodejs.

hampoelz avatar hampoelz commented on August 9, 2024

I just added this line https://github.com/hampoelz/Capacitor-NodeJS/blob/main/assets/builtin_modules/bridge/main.js#L3 ) and the import of the appChannel to a basic node project and it worked.

@jrobeson Yeah, it is required that the appChannel sends the ready command so the implementation knows that the NodeJS part is completely started. However, this should all happen automatically once the bridge module is loaded. (the code you referenced is actually a part of the bridge module).

The thing about whenReady though, is that starts what seems to be a permanent timer (I'm no java expert) in the capacitor plugin code to wait for isNodeEngineReady to equal true. It will never equal true UNTIL it gets a message over the APP_CHANNEL of ready. That's what that line does. That line goes in your nodejs application code.

This is also correct. Since the NodeJS part needs more time to start on some devices than the CapacitorJS part (see issue #4), there is the whenReady method. Thereby an interval is executed, which checks if the NodeJS part is started and then resolves the method. So the bridge module has to be loaded for this to work.

In general, the communication between NodeJS and CapacitorJS is "blocked" until the ready command is received from the NodeJS part. I didn't mention anywhere in the documentation that the bridge module is that important for communication to work, I should add that.

My problem was that after just creating a basic file structure and wanting to test out the functionality, it seemed like there was no connection to the nodejs backend.

@lucaengelhard Hmm so did I understand correctly, you imported the bridge module, waited for the nodejs part to be ready loaded and it still doesn't work? Could you check if the whenReady method resolves and if there are error messages?

Anyway, on Monday is my last exam for now, after that I will add the sample projects.

from capacitor-nodejs.

hampoelz avatar hampoelz commented on August 9, 2024

The examples currently still use CapacitorJS v4, but in a short test the plugin also worked with v5. When I migrate the plugin to v5 I'll also update the example projects.

from capacitor-nodejs.

hampoelz avatar hampoelz commented on August 9, 2024

@lucaengelhard In fact, I found a bug that prevented the bridge module from loading (see issue #12). With v1.0.0-beta.4 it should be fixed now.

from capacitor-nodejs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.