Git Product home page Git Product logo

Comments (6)

hampoelz avatar hampoelz commented on September 14, 2024

When you add your forked bridge to the dependencies, it will overwrite the built-in bridge module.

However, you could also load your custom bridge module as a "built-in" module. When you run your project with Capacitor, it would use the bridge module from the plugin. When you run the project in your local environment, it would use your custom bridge module.

To archive this, create a directory for your local built-in modules and start Node.js with the NODE_PATH environment variable pointing to that directory. For example, NODE_PATH="/path/to/your/builtin_modules/" node app.js.

You can read more in the corresponding documentation:
https://nodejs.org/api/modules.html#loading-from-the-global-folders

from capacitor-nodejs.

 avatar commented on September 14, 2024

i'm not sure what you mean by "to my dependencies" I just have it in a my application source atm, since i thought a separate npm package was going to be published, and it works fine.

This new bridge however says throw new Error('No IPC channel has been established between the Node.js process and the Capacitor layer.'); Although there is no such throw in NativeMobileBridge only NativeDesktopBridge.

from capacitor-nodejs.

 avatar commented on September 14, 2024

Oh, when i actually try to use this project with my copy of your new bridge I get

TypeError: Cannot read properties of undefined (reading 'addListener')
for eventChannel.addListener('msg-from-capacitor', (args: CapacitorMsg) => {

from capacitor-nodejs.

 avatar commented on September 14, 2024

Ah ignore hte last comment. when i copied the entire bridge and ChannelPayloadData from definitions it started to work again. The previous question still stands though.

from capacitor-nodejs.

hampoelz avatar hampoelz commented on September 14, 2024

i'm not sure what you mean by "to my dependencies" I just have it in a my application source atm, since i thought a separate npm package was going to be published, and it works fine.

Oh, I assumed you packaged your custom bridge module as a local npm package.

This new bridge however says throw new Error('No IPC channel has been established between the Node.js process and the Capacitor layer.'); Although there is no such throw in NativeMobileBridge only NativeDesktopBridge.

When the bridge module is used on a desktop platform (if process.platform is not android or ios), the NativeDesktopBridge is used, which tries to establish a channel with electron. By using the module in a standalone project (on the desktop), the electron backend is missing and therefore no channel can be established.

Wouldn't it be easiest to create some kind of wrapper around the included bridge module? Depending on whether the built-in bridge is available, the bridge module should be used, otherwise your own bridge should be used. Maybe something like this:

// your_custom_bridge.js:
const EventEmitter = require('events');

let nativeBridge;
try {
    nativeBridge = require('bridge');
} catch (ex) { }

const nativeChannel = nativeBridge?.channel;
const customChannel = new EventEmitter();

// do something with customChannel

exports.customBridge = nativeChannel ?? customChannel;

Note that I haven't tested this code.

Alternatively, you could package your bridge module as a local npm module and set the NODE_PATH variable as mentioned above.

from capacitor-nodejs.

 avatar commented on September 14, 2024

yeah it seems I will have to make a bridge module. I was just surprised that it worked fine before, but doesn't now. Thanks for the response. I'll just close this bug.

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.