Skip to content

Commit

Permalink
docs: 馃摑 Minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
hampoelz committed Sep 8, 2023
1 parent fe090bd commit 287551c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
34 changes: 16 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,10 @@ 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.");
channel.send("msg-from-nodejs",
`Replying to the message '${message}'.`,
"And optionally add more arguments."
);
});
```

Expand Down Expand Up @@ -199,7 +202,7 @@ To change this starting point, add a file called `package.json` to the Node.js p
Using the `main` field in this file, a custom starting point for the Node.js project can be specified.
This should be a module relative to the root of the Node.js project directory.

The package.json file could look like the following, if the `main` field is set to `./server.js`:
The package.json file could look like the following, if the `main` field is set to `server.js`:

```javascript
// static/nodejs/package.json
Expand Down Expand Up @@ -395,9 +398,7 @@ NodeJS.start();

// Waits for the Node.js process to initialize.
NodeJS.whenReady().then(() => {

// Communicate with the Node.js process.

});
```

Expand All @@ -420,13 +421,6 @@ const options = {

// Starts the Node.js engine with properties as set by the `options`.
NodeJS.start(options);

// Waits for the Node.js process to initialize.
NodeJS.whenReady().then(() => {

// Communicate with the Node.js process.

});
```

> [!Note]
Expand Down Expand Up @@ -467,6 +461,10 @@ const tmpPath = os.tmpdir();

## Mobile Node.js APIs differences

> [!NOTE]
>
> This section is based on the documentation of the Node.js for Mobile Apps toolkits.
Not every API is supported on mobile devices. Mobile operating systems do not allow applications to call certain APIs that are expected to be available on other operating systems.

### child_process module
Expand Down Expand Up @@ -523,10 +521,10 @@ The following functions are only available on POSIX platforms, so they are unava

These config values are available:

| Prop | Type | Description | Default | Since |
| --------------- | ------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ----- |
| **`nodeDir`** | <code>string</code> | Relative path of the integrated Node.js project based on the Capacitor webdir. | <code>"nodejs"</code> | 1.0.0 |
| **`startMode`** | <code>'auto' \| 'manual'</code> | Startup mode of the Node.js engine. The following values are accepted: `auto`: The Node.js engine starts automatically when the application is launched. `manual`: The Node.js engine is started via the `NodeJS.start()` method. | <code>"auto"</code> | 1.0.0 |
| Prop | Type | Description | Default | Since |
| --------------- | ------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ----- |
| **`nodeDir`** | <code>string</code> | Relative path of the integrated Node.js project based on the Capacitor webdir. | <code>"nodejs"</code> | 1.0.0 |
| **`startMode`** | <code>'auto' \| 'manual'</code> | Startup mode of the Node.js engine. The following values are accepted: **`auto`**: The Node.js engine starts automatically when the application is launched. **`manual`**: The Node.js engine is started via the `NodeJS.start()` method. | <code>"auto"</code> | 1.0.0 |

### Examples

Expand Down Expand Up @@ -572,10 +570,9 @@ The `bridge` module is built-in. It provides an API to communicate between the C

TypeScript declarations for this `bridge` module can be manually installed as dev-dependency. If needed, the types-only package can be found under `node_modules/capacitor-nodejs/assets/types/bridge` in the root of the Capacitor project.


--------------------

* [`getDataPath()`](#getDataPath)
* [`channel`](#channel)


### getDataPath()

Expand All @@ -589,6 +586,7 @@ Returns a path for a per-user application data directory on each platform, where

--------------------

### channel

The `channel` class of the `bridge` module is an [Event Emitter](https://nodejs.org/api/events.html#events_class_eventemitter). It provides a few methods to send messages from the Node.js process to the Capacitor layer, and to receive replies from the Capacitor layer.

Expand Down
1 change: 1 addition & 0 deletions android/src/main/cpp/bridge.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Implements the bridge APIs between the native Java code and the Node.js engine.
* https://github.com/nodejs-mobile/nodejs-mobile-cordova/blob/unstable/src/common/cordova-bridge/cordova-bridge.cpp
*/

#include <map>
Expand Down
1 change: 1 addition & 0 deletions android/src/main/cpp/bridge.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* The bridge APIs between the native Java code and the Node.js engine.
* https://github.com/nodejs-mobile/nodejs-mobile-cordova/blob/unstable/src/common/cordova-bridge/cordova-bridge.h
*/

#ifndef ANDROID_BRIDGE_H
Expand Down
4 changes: 2 additions & 2 deletions src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ declare module '@capacitor/cli' {
* Startup mode of the Node.js engine.
*
* The following values are accepted:
* `auto`: The Node.js engine starts automatically when the application is launched.
* `manual`: The Node.js engine is started via the `NodeJS.start()` method.
* **`auto`**: The Node.js engine starts automatically when the application is launched.
* **`manual`**: The Node.js engine is started via the `NodeJS.start()` method.
*
* @since 1.0.0
* @default "auto"
Expand Down

0 comments on commit 287551c

Please sign in to comment.