Skip to content

Commit

Permalink
changed text and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
AtibQur committed Dec 18, 2024
1 parent 1345312 commit 292a421
Showing 1 changed file with 38 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,16 @@ authKey?: string;

The `authKey` is an optional string used for authentication and should be passed directly in the `create` call.

**Example of usage:**
**Example:**

```js

const cx = await CheerpX.Linux.create({
mounts: mountPoints,
networkInterface: { authKey: "YOUR KEY" },
});
```

**Explanation**
In this example, the `authKey` is included in the `networkInterface` object to enable authentication for the CheerpX instance.

### `controlUrl`

Expand All @@ -102,60 +105,79 @@ controlUrl?: string;

The `controlUrl` is an optional string used to specify the URL of a self-hosted server.

**Example of usage:**
**Example**

```js

const cx = await CheerpX.Linux.create({
mounts: mountPoints,
networkInterface: { controlUrl: "YOUR URL" },
});
```
Here, the `controlUrl` is used to point the CheerpX instance to a custom self-hosted server.

**Explanation**

### `loginUrlCb`
<!-- ### `loginUrlCb`
```ts
loginUrlCb?: (url: string) => void;
```
The `loginUrlCb` is a callback function designed to handle login URLs during the authentication process. It plays a critical role in the connection flow by setting the application's state to indicate readiness for login and resolving the URL required for the login process.
**Example of usage:**
**Example**
```js
```
**Explanation**
**Explanation** -->

### StateUpdateCb

```ts
stateUpdateCb?: (state: number) => void;
```

This callback function is invoked whenever the connection state changes, enabling you to react dynamically to transitions such as connecting, disconnecting, or successfully establishing a connection. The `state` parameter is an integer representing the current state.
The `stateUpdateCb` is a callback that runs when the connection state changes. The `state` parameter represents the connection status.

**Example of usage:**
**Example**

```js
const cx = await CheerpX.Linux.create({
mounts: mountPoints,
networkInterface: { stateUpdateCb },
});

function stateUpdateCb(state) {
if (state === 6) {
console.log("Connected");
}
}
```

**Explanation**
This example checks if the state indicates a "connected" status (state = 6) and logs "Connected" when the connection is established.

### NetmapUpdateCb

```ts
netmapUpdateCb?: (map: any) => void;
```

This callback is triggered whenever the network map is updated. The `map` parameter contains the full network configuration, including information about the current IP address and peers.
The `netmapUpdateCb` is a callback triggered whenever the network configuration updates. It gives you information about the current IP.

**Example of usage:**
**Example**

```ts
const cx = await CheerpX.Linux.create({
mounts: mountPoints,
networkInterface: { netmapUpdateCb },
});

function netmapUpdateCb(map) {
const currentIp = map.self.addresses[0];
console.log(`Current IP: ${currentIp}`);
}
```

**Explanation**
In this example, the `netmapUpdateCb` logs the current IP address whenever the network configuration changes.

[Promise]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise

0 comments on commit 292a421

Please sign in to comment.