Comments (6)
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.
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.
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.
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.
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 inNativeMobileBridge
onlyNativeDesktopBridge
.
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.
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)
- Separate example projects in a new repo HOT 2
- npm install failed HOT 2
- Cannot find module 'bridge' on Android HOT 1
- Upgrade to CapacitorJS v5
- Rewrite the Bridge package in TypeScript
- Start the node.js runtime as child process on ElectronJS
- support for native node modules build HOT 5
- Did you rebase the main branch? HOT 1
- Add a method to stop nodejs HOT 1
- How to use manual mode start? HOT 4
- iOS support? HOT 13
- How do I use this plugin in Quasar's capacitor. HOT 3
- Any way of debugging the nodejs code? HOT 5
- Execution failed for task ':capacitor-nodejs:compileDebugJavaWithJavac'. > error: invalid source release: 17 HOT 4
- Could not run on device only in debug mode HOT 5
- node.js upgrade HOT 10
- Add TypeScript Declaration File for Bridge Package HOT 1
- Example Project HOT 8
- Allow manual startup of the node.js runtime and pass environment variables HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from capacitor-nodejs.