Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Jaime Bernardo
    @jaimecbernardo
    Hi @arminsal1 , It depends on what's taking time. If it's the native modules compilation, some users have been able to build the native modules, copy the resulting binaries back into the nodejs-assets and disabling the build of the native modules: https://github.com/JaneaSystems/nodejs-mobile-react-native/tree/71c401d0fe7aa6e7b0c5a330bed3645c7a1ea036#native-modules
    Hi @rafaelgfx . According to Expo's FAQ, modules that contain native code aren't usable without detaching the project, so the likely answer is No.
    arminsal1
    @arminsal1
    @jaimecbernardo Thanks! How do I build a native module of a library on a Mac? Sorry if this is obvious or if I missed this in the Readme
    vedant-dobby
    @vedant-dobby
    Hi I'm trying to use nodejs-mobile for react native. I have installed it. installed the dependencies using package.json (npm install) . I have checked that all of my dependencies are present. My application still crashes. Can anyone of you guys help me how to install dependencies in the node project?
    Jaime Bernardo
    @jaimecbernardo
    Hi @arminsal1, Were the native modules the cause of your slowness? are you on react-native or cordova?
    Hi @vedant-dobby , I've answered in the issue: JaneaSystems/nodejs-mobile#223
    arminsal1
    @arminsal1
    @jaimecbernardo I still don't know how to convert the native modules so I don't know yet. And I'm using react-native
    Jaime Bernardo
    @jaimecbernardo
    nodejs-mobile-react-native adds a build phase to your XCode project in order to detect and build native modules: https://github.com/JaneaSystems/nodejs-mobile-react-native/blob/71c401d0fe7aa6e7b0c5a330bed3645c7a1ea036/scripts/module-postlink.js#L197-L249
    You can look into the Xcode build logs while you're building the Application to see if it's spending a lot of time in the 'Build NodeJS Mobile Native Modules' build phase.
    André Staltz
    @staltz
    Has anyone experimented with profiling nodejs-mobile projects? I'm scratching my head how I'm going to get profiling data out of this
    Jaime Bernardo
    @jaimecbernardo
    Hi @staltz , Haven't been aware of users profiling their scripts in nodejs-mobile yet. Are you having issues with some method?
    FrankFundel
    @FrankFundel
    Hey,
    how can i read a local file with fs from the file system
    the file is in a folder in the nodejs-project folder
    i want to read it with fs.readFileSync('sslcert/key.pem', 'utf8')
    but the app crashes and i read "Functions that can take relative paths apply that relative path to the current working directory where the node process was started in server/desktop environments. On mobile environments, nodejs-mobile is started in the context of an application, for which the current working environment is the root of the filesystem on iOS and Android. This can lead to unexpected behavior for code that assumes the current working directory is set to the directory of the starting Node.js script (which also might not be true in a server/desktop environment)."
    So how can i do it then?
    André Staltz
    @staltz
    @jaimecbernardo so far the way I've found (a few days after posting that question) was to profile my nodejs-mobile project on desktop instead, and hope that the bottlenecks on x86_64 (desktop) are proportional to the bottlenecks on arm64 (mobile)
    Jaime Bernardo
    @jaimecbernardo
    Hi @FrankFundel , if it's a file inside nodejs-project you can use __dirname__ to get the runtime folder where your nodejs-project is running.
    Hi @staltz , Thanks for the tip. What are you using on desktop? I suppose it's something you can't run on mobile, then.
    DiegoNegri
    @DiegoNegri
    Hi @jaimecbernardo any plan to support ReactNative 0.60 ?
    Jaime Bernardo
    @jaimecbernardo
    Hi, @DiegoNegri , Yes, it's in the plans. No ETA yet, though.
    Alejandro Reimondo
    @aleReimondo
    I am trying to implement a native module embedded in app (Native Gradle Sample with minimal changes).
    The sample app runs as expected, but I can´t require my built-in module from javascript side.
    The code I added follows. I see that the call for registration is evaluated (long before node::start).
    Is there any documentation (or sample code) about the place and conditions to success in registering a built-in module?
    // Implementation of the registration of my module
    namespace node {
    namespace myBridge {
    void Initialize(
    v8::Local<v8::Object> exports,
    v8::Local<v8::Value> module,
    v8::Local<v8::Context> context) {
    LOGD("InitContextAware myBridge...");
    v8::Local<v8::Object> target = context->Global();
    MyBridge::Init(target);
    }
    }
    }
    NODE_MODULE_CONTEXT_AWARE_BUILTIN(mybridge_bindings, node::myBridge::Initialize);
    // Fail when evaluating in javascript
    // require("mybridge_bindings")
    // require("mybridge_bindings.node")
    Any information or guides on how to success with module registration will be really appreciated.
    cheers,
    Ale
    Jaime Bernardo
    @jaimecbernardo
    Hi @aleReimondo ,
    We're using a native module embedded for implementing the bridge in the nodejs-mobile-react-native and nodejs-mobile-cordova plugins: Here are the sources in case you want to take a look: Header file, C++ Source.
    To access modules that are built-in in the process, you'd do as in node outside the mobile, with process.binding, Here's how it's done for our case: https://github.com/JaneaSystems/nodejs-mobile-cordova/blob/823fe002e8312e3abba76f9b8aa358a490f76eac/install/nodejs-mobile-cordova-assets/builtin_modules/cordova-bridge/index.js#L4
    Hope this is helpful.
    Please consider sharing your implementation in native Android as a sample ;)
    Alejandro Reimondo
    @aleReimondo
    @jaimecbernardo thank you for the help!
    IMO the error was to use the macro with non-napi arguments. Changing arguments and using direct call to napi_module_register() solved the issue and the registration function is called as expected.
    arminsal1
    @arminsal1

    Anyone know how to tackle this type of error?

    Error: Cannot find module '../build/Release/nodessl.node'
       at Module._resolveFilename (internal/modules/cjs/loader.js:582:5)
       at Module._load (internal/modules/cjs/loader.js:506:3)
       at Module.prototype.require (internal/modules/cjs/loader.js:636:3)
       at require (internal/modules/cjs/helpers.js:20:7)
       at Anonymous function (/private/var/containers/Bundle/Application/C0423769-DD9B-4B38-A482-A82B0E3BD6B5/NAME.app/nodejs-project/libsignal-node/node_modules/node-webcrypto-ossl/buildjs/native.js:3:1)
       at Module.prototype._compile (internal/modules/cjs/loader.js:688:5)
       at Module._extensions[.js] (internal/modules/cjs/loader.js:699:3)
       at Module.prototype.load (internal/modules/cjs/loader.js:598:3)
       at tryModuleLoad (internal/modules/cjs/loader.js:537:5)
       at Module._load (internal/modules/cjs/loader.js:529:3)

    I think I need to make a native prebuild for node-webcrypto-ossl (like https://github.com/jimpick/sodium-native-prebuilds-nodejs-mobile) But, if that is the solution, I have no idea how to make such a prebuild.

    Felix Schlitter
    @felixSchl
    @aleReimondo @jaimecbernardo i think this information would be nice to find it's way into the documentation somewhere, especially since it requires the use of the undocumented NAPI_MODULE_Xwith undocumented flag 0x1. I think liquidcore has an interesting approach to this problem, but they have a lot more higher-level abstractions making this possible: https://github.com/LiquidPlayer/LiquidCore/blob/master/LiquidCoreAndroid/src/main/java/org/liquidplayer/service/MicroService.java#L708-L710.
    Alejandro Reimondo
    @aleReimondo

    @felixSchl
    // Here it is an example of registering a myBridge

    include "node_api.h"

    namespace myBridge {
    napi_value Init( napi_env env, napi_value exports) {
    LOGD("Init myBridge...");
    v8::Isolate* isolate = v8::Isolate::GetCurrent();
    v8::Handle<v8::Object> target = isolate->GetCurrentContext()->Global();
    // add here your code to inject your module in current context... (e.g. using napi or nan)
    return exports;
    }
    }
    extern "C" {
    static napi_module _module =
    { 1, 1, FILE,
    myBridge::Init,
    "mybridge_bindings",
    0, {0},
    };
    static void _register_mybridge_bindings(void) attribute((constructor));
    static void _register_mybridge_bindings(void) {
    napi_module_register(&_module);
    }
    }
    // used in node as:
    // process.binding("mybridge_bindings")

    Jaime Bernardo
    @jaimecbernardo
    Hi @arminsal1 , The way to tackle it would be to try building the native modules you are using for ios. Looking at the way the nodejs-mobile-react-native and nodejs-mobile-cordova do it would be a first step in understanding how to build it. In the case of iOS, some scripts are added to the XCode project to build the native modules for iOS. Here's an example of the code for such a phase: https://github.com/JaneaSystems/nodejs-mobile-cordova/blob/823fe002e8312e3abba76f9b8aa358a490f76eac/install/hooks/ios/after-plugin-install.js#L19-L87
    Jaime Bernardo
    @jaimecbernardo
    Hi @felixSchl ,
    This would be general Node information when building a module that's built-in in the application when using embedded Node. It'd make its way into instructions on how to build a built-in module for the native lib scenario. Thank you for the input and additional reference.
    Charles Dusek
    @cgdusek
    Does anyone know the best way to implement websocket server in Node.js Mobile with React Native?
    Charles Dusek
    @cgdusek
    Just going to try npm install websocket first :clapper:
    Charles Dusek
    @cgdusek
    How do I console log the NodeJS side using React Native? Do I have manually send a message across?
    Charles Dusek
    @cgdusek
    Not very active group :)
    Okay, got the websocket talking to the react-native side. Is there a way to use a WASM?
    Charles Dusek
    @cgdusek
    Found the issue stating Chakracore doesn't support WASM yet on iOS
    Looks like I will trying to solve the Rust toolchain issue
    Charles Dusek
    @cgdusek
    I am guessing that I have to do something similar to this post
    But for Node.JS
    Jaime Bernardo
    @jaimecbernardo
    Hi @cgdusek , indeed using a npm module would be the way to go. express-ws has been used before successfully for this purpose too.
    Regarding console log, you should be able to get the messages in XCode or adb.
    Charles Dusek
    @cgdusek
    Thanks, today I am going to study the build process for the native side. It would be helpful to know the files that Node.JS is expecting. I guess I could get those from node-gyp output and then try to mimic that for Rust
    Jaime Bernardo
    @jaimecbernardo
    React-native has some code to build native modules already, using nodejs-mobile-gyp. The way that would integrate with Rust code is not clear though.
    Charles Dusek
    @cgdusek
    Okay, cool. That helps
    Jaime Bernardo
    @jaimecbernardo
    Jaime Bernardo
    @jaimecbernardo
    Hi @/all ,
    We've just released a version update for the nodejs-mobile-cordova and nodejs-mobile-react-native plugins:
    https://www.npmjs.com/package/nodejs-mobile-cordova/v/0.3.4
    This update contains a fix to allow using the plugin with Cordova CLI 9.
    https://www.npmjs.com/package/nodejs-mobile-react-native/v/0.5.0
    This update contains a fix to allow using the plugin with react-native 0.60+, breaking compatibility with previous versions, due to the breaking changes in linking plugins with native code on iOS.
    Charles Dusek
    @cgdusek
    Thinking I can pre-gyp the Rust
    Charles Dusek
    @cgdusek
    I see there is a modified node-gyp
    Charles Dusek
    @cgdusek
    Is this android-ndk-r18b listed in the prerequisites outdated?
    Jaime Bernardo
    @jaimecbernardo
    Hi @cgdusek , It's not outdated. Newer versions might work as well, and might even be necessary depending on what module you are trying to build.
    Charles Dusek
    @cgdusek
    Thanks for the answer. Currently on NDK 20. Currently working on a neon bindings Native nodejs module. Critical that I get that working for my project so going through Neon with a fine tooth comb right now.