Open sayaa10 opened 3 days ago
Yes, everything should work. Does the problem only exist in developer mode or always? And have you already looked at the examples? (The examples use slightly older packages, but it should be possible to simply update them without breaking anything)
//CAPACITOR CONFIG: { "appId": "com.beatsy.musicapp", "appName": "Beatsy", "bundledWebRuntime": false, "npmClient": "npm", "webDir": "www", "plugins": { "SplashScreen": { "launchShowDuration": 0 },"CapacitorNodeJS": { "nodeDir": "/nodejs" } }, "server": { "url": "http://192.168.18.10:5173/", "cleartext": true }, "cordova": {} }
//VITE CONFIG import path from 'path'; import react from '@vitejs/plugin-react';
const SRC_DIR = path.resolve(dirname, './src'); const PUBLIC_DIR = path.resolve(__dirname, './static'); const BUILD_DIR = path.resolve(dirname, './www',); export default async () => {
return { plugins: [ react(),
],
root: SRC_DIR,
base: '',
publicDir: PUBLIC_DIR,
build: {
outDir: BUILD_DIR,
assetsInlineLimit: 0,
emptyOutDir: true,
rollupOptions: {
treeshake: false,
},
},
resolve: {
alias: {
'@': SRC_DIR,
},
},
server: {
host: true,
},
}; }
// static/nodejs/main.js const { channel } = require('bridge');
// Listens to "msg-from-capacitor" from the Capacitor layer. channel.addListener('msg-from-capacitor', message => { console.log('[Node.js] Message from Capacitor: ' + message);
// Sends a message back to the Capacitor layer.
channel.send('msg-from-nodejs', Replying to the message '${message}'.
, 'And optionally add more arguments.');
});
//CLIENT import { Page } from "framework7-react" import { NodeJS } from 'capacitor-nodejs'; import { useEffect, useState } from 'react';
const Downloads = () => { const [message, setMessage] = useState('Waiting for message...');
useEffect(() => { // Listen for messages from Node.js NodeJS.addListener('msg-from-nodejs', event => { setMessage(event.args[0]); // Store first argument in state });
// Initialize communication
NodeJS.whenReady().then(() => {
NodeJS.send({
eventName: 'msg-from-capacitor',
args: ['Hello from Downloads component!'],
});
});
return () => NodeJS.removeAllListeners();
}, []);
return (
{message}
) }
export default Downloads;
I just see waiting for message in my android studio app
I want to get live changes while running my app live using 'npm run dev' can I do that?
Can it be used in development mode with vite? I am running into issues where I am not receiving response from my node.js file to my capacitor app while in development mode also I am using capacitor 6