在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):JaneaSystems/nodejs-mobile-react-native开源软件地址(OpenSource Url):https://github.com/JaneaSystems/nodejs-mobile-react-native开源编程语言(OpenSource Language):C 84.9%开源软件介绍(OpenSource Introduction):
The Node.js for Mobile Apps React Native pluginReporting IssuesWe have a central repo where we manage all the issues related to Node.js for Mobile Apps, including issues specific to this plugin. Please, report your issue there. Installation
For iOS, run
iOSUniversal binaries are included in the plugin, so you can run in both iOS simulators and devices.
AndroidYou may need to open your app's You can also set the environment variable export ANDROID_NDK_HOME=/Users/username/Library/Android/sdk/ndk-bundle Usage
|
Param | Type |
---|---|
scriptFileName | string |
options | StartupOptions |
Starts the nodejs-mobile runtime thread with a file inside the nodejs-project
directory.
Param | Type |
---|---|
scriptBody | string |
options | StartupOptions |
Starts the nodejs-mobile runtime thread with a script body.
Param | Type |
---|---|
event | string |
callback | function |
Registers a callback for user-defined events raised from the nodejs-mobile side.
Param | Type |
---|---|
event | string |
...message | any JS type that can be serialized with JSON.stringify and deserialized with JSON.parse |
Raises a user-defined event on the nodejs-mobile side.
Param | Type |
---|---|
...message | any JS type that can be serialized with JSON.stringify and deserialized with JSON.parse |
Raises a 'message' event on the nodejs-mobile side.
It is an alias for nodejs.channel.post('message', ...message);
.
object
Name | Type | Default | Description |
---|---|---|---|
redirectOutputToLogcat | boolean |
true |
Allows to disable the redirection of the Node stdout/stderr to the Android logcat |
The following methods can be called from the Node javascript code through the rn-bridge
module:
const rn_bridge = require('rn-bridge');
rn_bridge.channel.on
rn_bridge.channel.post
rn_bridge.channel.send
rn_bridge.app.on
rn_bridge.app.datadir
rn_bridge.channel.send(...msg)
is equivalent torn_bridge.channel.post('message', ...msg)
. It is maintained for backward compatibility purposes.
The
rn_bridge.channel
object inherits from Node'sEventEmitter
class, withemit
removed andpost
andsend
added.
Param | Type |
---|---|
event | string |
callback | function |
Registers a callback for user-defined events raised from the React Native side.
To receive messages from
nodejs.channel.send
, use:rn_bridge.channel.on('message', listenerCallback);
Param | Type |
---|---|
event | string |
...message | any JS type that can be serialized with JSON.stringify and deserialized with JSON.parse |
Raises a user-defined event on the React Native side.
Param | Type |
---|---|
...message | any JS type that can be serialized with JSON.stringify and deserialized with JSON.parse |
Raises a 'message' event on the React Native side.
It is an alias for rn_bridge.channel.post('message', ...message);
.
Param | Type |
---|---|
event | string |
callback | function |
Registers callbacks for App events. Currently supports the 'pause' and 'resume' events, which are raised automatically when the app switches to the background/foreground.
rn_bridge.app.on('pause', (pauseLock) => {
console.log('[node] app paused.');
pauseLock.release();
});
rn_bridge.app.on('resume', () => {
console.log('[node] app resumed.');
});
The 'pause' event is raised when the application switches to the background. On iOS, the system will wait for the 'pause' event handlers to return before finally suspending the application. For the purpose of letting the iOS application know when it can safely suspend after going to the background, a pauseLock
argument is passed to each 'pause' listener, so that release()
can be called on it to signal that listener has finished doing all the work it needed to do. The application will only suspend after all the locks have been released (or iOS forces it to).
rn_bridge.app.on('pause', (pauseLock) => {
server.close( () => {
// App will only suspend after the server stops listening for connections and current connections are closed.
pauseLock.release();
});
});
Warning : On iOS, the application will eventually be suspended, so the pause event should be used to run the clean up operations as quickly as possible and let the application suspend after that. Make sure to call pauseLock.release()
in each 'pause' event listener, or your Application will keep running in the background for as long as iOS will allow it.
Returns a writable path used for persistent data storage in the application. Its value corresponds to NSDocumentDirectory
on iOS and FilesDir
on Android.
function(arg)
Name | Type |
---|---|
arg | any JS type that can be serialized with JSON.stringify and deserialized with JSON.parse |
The messages sent through the channel can be of any type that can be correctly serialized with JSON.stringify
on one side and deserialized with JSON.parse
on the other side, as it is what the channel does internally. This means that passing JS dates through the channel will convert them to strings and functions will be removed from their containing objects. In line with The JSON Data Interchange Syntax Standard, the channel supports sending messages that are composed of these JS types: Boolean
, Number
, String
, Object
, Array
.
On iOS, os.tmpdir()
returns a temporary directory, since iOS sets the TMPDIR
environment variable of the application to the equivalent of calling NSTemporaryDirectory
.
The Android OS doesn't define a temporary directory for the system or application, so the plugin sets the TMPDIR
environment variable to the value of the application context's CacheDir
value.
On Android applications, the react-native
build process is sometimes unable to rebuild assets.
If you are getting errors while building the application using react-native run-android
, the following commands can help you do a clean rebuild of the project, when run in your project's folder.
On Windows:
cd android
gradlew clean
cd ..
react-native run-android
On Linux/macOS:
cd android
./gradlew clean
cd ..
react-native run-android
During the react-native
application's build process, the nodejs-project
gets copied to the application's assets, where they'll be used by nodejs-mobile
.
The react-native
packager monitors the project's folder for javascript packages and may throw a "jest-haste-map: Haste module naming collision
" error.
To avoid this error, instruct the react-native
packager to ignore the nodejs-project
and the platform folders where it is copied to. Edit the metro.config.js
file in your react-native
project's root path with the following contents if you're using recent versions of react-native
(>= v0.60
) and add the blacklist
require and the following resolver
to the module exports:
const blacklist = require('metro-config/src/defaults/blacklist');
module.exports = {
resolver: {
blacklistRE: blacklist([
/\/nodejs-assets\/.*/,
/\/android\/.*/,
/\/ios\/.*/
])
},
...
};
Releases are documented in CHANGELOG.md
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论