mirror of
https://github.com/fluencelabs/gitbook-docs
synced 2025-04-25 16:02:17 +00:00
various fixes
This commit is contained in:
parent
7d828fb228
commit
6be60a21eb
@ -15,7 +15,7 @@
|
|||||||
* [Marine Rust SDK](knowledge_aquamarine/marine/marine-rs-sdk.md)
|
* [Marine Rust SDK](knowledge_aquamarine/marine/marine-rs-sdk.md)
|
||||||
* [Tools](knowledge_tools.md)
|
* [Tools](knowledge_tools.md)
|
||||||
* [Node](node.md)
|
* [Node](node.md)
|
||||||
* [JS SDK](js-sdk/README.md)
|
* [Fluence JS](js-sdk/README.md)
|
||||||
* [Concepts](js-sdk/1_concepts.md)
|
* [Concepts](js-sdk/1_concepts.md)
|
||||||
* [Basics](js-sdk/2_basics.md)
|
* [Basics](js-sdk/2_basics.md)
|
||||||
* [In-depth](js-sdk/3_in_depth.md)
|
* [In-depth](js-sdk/3_in_depth.md)
|
||||||
|
@ -1,27 +1,5 @@
|
|||||||
# Concepts
|
# Concepts
|
||||||
|
|
||||||
##
|
|
||||||
|
|
||||||
## Fluence peer in JS
|
|
||||||
|
|
||||||
`@fluencelabs/fluence` package export the `FluencePeer` class. This class implements the Fluence protocol for javascript-based environments. It provides all the necessary features to communicate with Fluence network namely:
|
|
||||||
|
|
||||||
1. Connectivity with one or many Fluence Node which allows sending particles to and receiving from other Peers
|
|
||||||
2. The Peer Id identifying the node in the network
|
|
||||||
3. Aqua VM which allows the execution of air scripts inside particles
|
|
||||||
4. A set of builtin functions required by Fluence protocol
|
|
||||||
5. Support for the typescript code which is generated by Aqua compiler
|
|
||||||
|
|
||||||
Even though the js-based implementation closely resembles [node](https://github.com/fluencelabs/gitbook-docs/js-sdk/node.md) there are some considerable differences to the latter.
|
|
||||||
|
|
||||||
`FluencePeer` does not host services composed of wasm modules. Instead it allows to register service call handlers directly in javascript. The Aqua language compiler creates a typed helpers for that task. Using Aqua compiler is strongly advised when working with JS SDK.
|
|
||||||
|
|
||||||
Due to the limitations of browser-based environment `FluencePeer` cannot be discovered by it's Peer Id on it's own. To overcome this `FluencePeer` must use an existing node which will act as a `relay`. When a peer is connected through a relay it is considered to be `client`. The `FluencePeer` routes all it's particle through it's relay thus taking advantage of the peer discovery implemented on the node. A particle sent to the connected client must be routed through it's relay.
|
|
||||||
|
|
||||||
The js-based peer does not implement the full set of builtin functions due the limitations described previously. E.g there is no built-ins implementation for _kad_ or _srv_ services. However _op_ service is fully implemented. For the full descriptions of implemented built-ins refer to [Api reference](https://github.com/fluencelabs/gitbook-docs/js-sdk/js-sdk/6_reference/modules.md)
|
|
||||||
|
|
||||||
In contrast with the node implementation `FluencePeer` can initiate new particles execution. Aqua compiler generates executable functions from `func` definitions in aqua code.
|
|
||||||
|
|
||||||
## Creating applications with Aqua language
|
## Creating applications with Aqua language
|
||||||
|
|
||||||
The official way to write applications for Fluence is using Aqua programming language. Aqua compiler emits TypeScript or JavaScript which in turn can be called from a js-based environment. The compiler outputs code for the following entities:
|
The official way to write applications for Fluence is using Aqua programming language. Aqua compiler emits TypeScript or JavaScript which in turn can be called from a js-based environment. The compiler outputs code for the following entities:
|
||||||
@ -39,3 +17,27 @@ The building block of the application are:
|
|||||||
- Application specific code \(java\)typescript in the framework of your choice
|
- Application specific code \(java\)typescript in the framework of your choice
|
||||||
|
|
||||||
In the next section we see it in action
|
In the next section we see it in action
|
||||||
|
|
||||||
|
## Facade API
|
||||||
|
|
||||||
|
The main entry point `@fluencelabs/fluence` is `Fluence` facade. It provides easy way to start and stop the Fluence Peer. The facade API is enough for the most of the uses cases.
|
||||||
|
|
||||||
|
## Fluence peer in JS
|
||||||
|
|
||||||
|
`@fluencelabs/fluence` package also exports the `FluencePeer` class. This class implements the Fluence protocol for javascript-based environments. It provides all the necessary features to communicate with Fluence network namely:
|
||||||
|
|
||||||
|
1. Connectivity with one or many Fluence Node which allows sending particles to and receiving from other Peers
|
||||||
|
2. The Peer Id identifying the node in the network
|
||||||
|
3. Aqua VM which allows the execution of air scripts inside particles
|
||||||
|
4. A set of builtin functions required by Fluence protocol
|
||||||
|
5. Support for the typescript code which is generated by Aqua compiler
|
||||||
|
|
||||||
|
Even though the js-based implementation closely resembles [node](https://github.com/fluencelabs/gitbook-docs/js-sdk/node.md) there are some considerable differences to the latter.
|
||||||
|
|
||||||
|
`FluencePeer` does not host services composed of wasm modules. Instead it allows to register service call handlers directly in javascript. The Aqua language compiler creates a typed helpers for that task. Using Aqua compiler is strongly advised when working with JS SDK.
|
||||||
|
|
||||||
|
Due to the limitations of browser-based environment `FluencePeer` cannot be discovered by it's Peer Id on it's own. To overcome this `FluencePeer` must use an existing node which will act as a `relay`. When a peer is connected through a relay it is considered to be `client`. The `FluencePeer` routes all it's particle through it's relay thus taking advantage of the peer discovery implemented on the node. A particle sent to the connected client must be routed through it's relay.
|
||||||
|
|
||||||
|
The js-based peer does not implement the full set of builtin functions due the limitations described previously. E.g there is no built-ins implementation for _kad_ or _srv_ services. However _op_ service is fully implemented. For the full descriptions of implemented built-ins refer to [Api reference](https://github.com/fluencelabs/gitbook-docs/js-sdk/js-sdk/6_reference/modules.md)
|
||||||
|
|
||||||
|
In contrast with the node implementation `FluencePeer` can initiate new particles execution. Aqua compiler generates executable functions from `func` definitions in aqua code.
|
||||||
|
@ -110,7 +110,7 @@ We recommend to store this logic inside a script in `packages.json` file:
|
|||||||
|
|
||||||
`compile-aqua` \(1\) runs the compilation once, producing `src/_aqua/hello-world.ts` in our case `watch-aqua` \(2\) starts watching for any changes in .aqua files recompiling them on the fly
|
`compile-aqua` \(1\) runs the compilation once, producing `src/_aqua/hello-world.ts` in our case `watch-aqua` \(2\) starts watching for any changes in .aqua files recompiling them on the fly
|
||||||
|
|
||||||
## Using the compiled code in our application
|
## Using the compiled code in typescript application
|
||||||
|
|
||||||
Using the code generated by the compiler is as easy as calling a function. The compiler generates all the boilerplate needed to send a particle into the network and wraps it into a single call. It also generate a function for service callback registration. Note that all the type information and therefore type checking and code completion facilities are there!
|
Using the code generated by the compiler is as easy as calling a function. The compiler generates all the boilerplate needed to send a particle into the network and wraps it into a single call. It also generate a function for service callback registration. Note that all the type information and therefore type checking and code completion facilities are there!
|
||||||
|
|
||||||
@ -169,4 +169,4 @@ If everything has been done correctly yuo should see `Hello, world!` in the cons
|
|||||||
|
|
||||||
The next section will cover in-depth and advanced usage JS SDK
|
The next section will cover in-depth and advanced usage JS SDK
|
||||||
|
|
||||||
The code from this section is available in on \(github\)\[[https://github.com/fluencelabs/examples/tree/main/js-sdk-examples/hello-world](https://github.com/fluencelabs/examples/tree/main/js-sdk-examples/hello-world)\]
|
The code from this section is available in on [github](https://github.com/fluencelabs/examples/tree/main/js-sdk-examples/hello-world)
|
||||||
|
@ -44,11 +44,11 @@ connects the first node of the Krasnodar network. You can find the officially ma
|
|||||||
await peer.stop();
|
await peer.stop();
|
||||||
```
|
```
|
||||||
|
|
||||||
## Using multiple peers in one applicaton
|
## Using multiple peers in one application
|
||||||
|
|
||||||
The peer by itself does not do any useful work. You should take advantage of functions generated by the Aqua compiler.
|
The peer by itself does not do any useful work. You should take advantage of functions generated by the Aqua compiler.
|
||||||
|
|
||||||
If your application needs several peers, you should create a separate `FluncePeer` instance for each of them. The generated functions accept the peer as the first argument. For example:
|
If your application needs several peers, you should create a separate `FluencePeer` instance for each of them. The generated functions accept the peer as the first argument. For example:
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
import { FluencePeer } from "@fluencelabs/fluence";
|
import { FluencePeer } from "@fluencelabs/fluence";
|
||||||
@ -71,7 +71,7 @@ async function main() {
|
|||||||
|
|
||||||
// ... more application logic
|
// ... more application logic
|
||||||
|
|
||||||
// Pass the peer as the first agument
|
// Pass the peer as the first argument
|
||||||
// ||
|
// ||
|
||||||
// \/
|
// \/
|
||||||
registerSomeService(peer1, {
|
registerSomeService(peer1, {
|
||||||
@ -80,7 +80,7 @@ async function main() {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Pass the peer as the first agument
|
// Pass the peer as the first argument
|
||||||
// ||
|
// ||
|
||||||
// \/
|
// \/
|
||||||
registerSomeService(peer2, {
|
registerSomeService(peer2, {
|
||||||
@ -89,7 +89,7 @@ async function main() {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Pass the peer as the first agument
|
// Pass the peer as the first argument
|
||||||
// ||
|
// ||
|
||||||
// \/
|
// \/
|
||||||
await someCallableFunction(peer1, arg1, arg2, arg3);
|
await someCallableFunction(peer1, arg1, arg2, arg3);
|
||||||
@ -105,17 +105,17 @@ async function main() {
|
|||||||
It is possible to combine usage of the default peer with another one. Pay close attention to which peer you are calling the functions against.
|
It is possible to combine usage of the default peer with another one. Pay close attention to which peer you are calling the functions against.
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
// Registering handler for the default peer
|
// Registering handler for the default peerS
|
||||||
registerSomeService({
|
registerSomeService({
|
||||||
handler: async (str) => {
|
handler: async (str) => {
|
||||||
console.log("Called agains the default peer: " str);
|
console.log("Called against the default peer: " str);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Pay close attention to this
|
// Pay close attention to this
|
||||||
// ||
|
// ||
|
||||||
// \/
|
// \/
|
||||||
registerSomeService(someOthePeer, {
|
registerSomeService(someOtherPeer, {
|
||||||
handler: async (str) => {
|
handler: async (str) => {
|
||||||
console.log("Called against the peer named someOtherPeer: " str);
|
console.log("Called against the peer named someOtherPeer: " str);
|
||||||
},
|
},
|
||||||
|
@ -2,6 +2,6 @@
|
|||||||
|
|
||||||
You can use the JS SDK with any framework \(or even without it\). The "fluence" part of the application is a collection of pure typescript\javascript functions which can be called withing any framework of your choosing.
|
You can use the JS SDK with any framework \(or even without it\). The "fluence" part of the application is a collection of pure typescript\javascript functions which can be called withing any framework of your choosing.
|
||||||
|
|
||||||
See the browser-example which demonstrate integrating Fluence with React: \(github\)\[[https://github.com/fluencelabs/examples/tree/main/js-sdk-examples/browser-example](https://github.com/fluencelabs/examples/tree/main/js-sdk-examples/browser-example)\]
|
See the browser-example which demonstrate integrating Fluence with React: [github](https://github.com/fluencelabs/examples/tree/main/js-sdk-examples/browser-example)
|
||||||
|
|
||||||
Also take a look at FluentPad. It is an example application written in React: [https://github.com/fluencelabs/fluent-pad](https://github.com/fluencelabs/fluent-pad)
|
Also take a look at FluentPad. It is an example application written in React: [https://github.com/fluencelabs/fluent-pad](https://github.com/fluencelabs/fluent-pad)
|
||||||
|
@ -1,5 +1,14 @@
|
|||||||
# JS SDK
|
# Fluence JS
|
||||||
|
|
||||||
JS SDK provides the implementation of the Fluence Protocol which can be hosted in js-based environment. Currently node.js 14+ and majority of the modern browsers are tested.
|
Fluence JS is the implementation of a Fluence protocol for JS-based environments. It can be used to connect browsers, Node.js applications and so on to the Fluence p2p network.
|
||||||
|
|
||||||
The JS SDK is just a library which can be used with any framework of your choice \(or even without frameworks\).
|
Similar to reference node implementation it provides:
|
||||||
|
|
||||||
|
- Peer-to-peer communication layer
|
||||||
|
- Marine interpreter
|
||||||
|
- Aqua VM
|
||||||
|
- Builtin services
|
||||||
|
|
||||||
|
Unlike reference implementation Fluence JS does not allow to run Marine services. Instead it can expose APIs directly from Typescript and Javascript by taking advantage of functions generated with Aqua compiler.
|
||||||
|
|
||||||
|
Fluence JS can be used with any framework of your choice \(or even without frameworks\).
|
||||||
|
Loading…
x
Reference in New Issue
Block a user