|
1 |
| -# Fluence JS |
| 1 | +# Fluence JS Client |
2 | 2 |
|
3 |
| -[](https://www.npmjs.com/package/@fluencelabs/fluence) |
| 3 | +[](https://www.npmjs.com/package/@fluencelabs/js-client.api) |
| 4 | +[](https://www.npmjs.com/package/@fluencelabs/js-client.web.standalone) |
4 | 5 |
|
5 |
| -Official TypeScript implementation of the Fluence Peer. |
| 6 | +This is the Javascript client for the [Fluence](https://fluence.network) network. |
6 | 7 |
|
7 |
| -## Getting started |
8 | 8 |
|
9 |
| -To start developing applications with Fluence JS refer to the official [documentation](https://fluence.dev/docs/build/fluence-js/) |
| 9 | +## Get Started |
10 | 10 |
|
11 |
| -## Contributing |
| 11 | +Adding the Fluence JS client for your web application is very easy: |
| 12 | + |
| 13 | +1. Add a script tag with the JS Client bundle to your `index.html`. The easiest way to do this is using a CDN (like [JSDELIVR](https://www.jsdelivr.com/) or [UNPKG](https://unpkg.com/)). The script is large, thus we highly recommend to use the `async` attribute. |
| 14 | + |
| 15 | + Here is an example using the JSDELIVR CDN: |
| 16 | + |
| 17 | + ```html |
| 18 | + <head> |
| 19 | + <title>Cool App</title> |
| 20 | + < script src= 'https://cdn.jsdelivr.net/npm/@fluencelabs/[email protected]/dist/js-client.min.js' |
| 21 | + async></script> |
| 22 | + </head> |
| 23 | + ``` |
| 24 | + |
| 25 | + If you cannot or don't want to use a CDN, feel free to get the script directly from the `npm` package and host in yourself: `https://www.npmjs.com/package/@fluencelabs/js-client.web.standalone`. You can find the script in the `/dist` directory of the package. (Note: this option means that developers understand what they are doing and know how to serve this file from their own web server.) |
| 26 | + |
| 27 | +2. Install the following packages: |
| 28 | + |
| 29 | + ``` |
| 30 | + npm i @fluencelabs/js-client.api @fluencelabs/fluence-network-environment |
| 31 | + ``` |
| 32 | + |
| 33 | +3. Add the following lines at the beginning of your code: |
| 34 | + |
| 35 | + ``` |
| 36 | + import { Fluence } from "@fluencelabs/js-client.api"; |
| 37 | + import { krasnodar } from "@fluencelabs/fluence-network-environment"; |
| 38 | + |
| 39 | + Fluence.start({ |
| 40 | + relay: krasnodar[3], |
| 41 | + }); |
| 42 | + ``` |
| 43 | + |
| 44 | +## Use Aqua in a Web Application |
12 | 45 |
|
13 |
| -While the project is still in the early stages of development, you are welcome to track progress and contribute. As the project is undergoing rapid changes, interested contributors should contact the team before embarking on larger pieces of work. All contributors should consult with and agree to our [basic contributing rules](CONTRIBUTING.md). |
| 46 | +Once you've added the client, you can compile [Aqua](https://github.com/fluencelabs/aqua) and run it in your application. To compile Aqua, use [Fluence CLI](https://github.com/fluencelabs/fluence-cli). |
14 | 47 |
|
15 |
| -### Setting up dev environment |
| 48 | +1. Install the package: |
16 | 49 |
|
17 |
| -Fluence JS uses pnpm to manage monorepo packages. See [pnpm.io](https://pnpm.io/installation) for installation instructions. |
| 50 | + ``` |
| 51 | + npm i -D "@fluencelabs/fluence-cli" |
| 52 | + ``` |
18 | 53 |
|
19 |
| -Install dependencies |
| 54 | +2. Add a directory in your project for Aqua code, e.g., `_aqua`. |
20 | 55 |
|
21 |
| -```bash |
22 |
| -pnpm install |
23 |
| -``` |
| 56 | +3. Put `*.aqua` files in that directory. |
24 | 57 |
|
25 |
| -Build all packages |
| 58 | +4. Add a directory for compiled Aqua files inside you sources. For example, if your app source is located in the `src` directory, you can create `src/_aqua`. |
26 | 59 |
|
27 |
| -``` |
28 |
| -pnpm -r build |
29 |
| -``` |
| 60 | +5. To compile Aqua code once, run `npx fluence aqua -i ./_aqua -o ./src/_aqua/`. To watch the changes and to recompile on the fly, add the `-w` flag: `npx fluence aqua -w -i ./_aqua -o ./src/_aqua/`. |
30 | 61 |
|
31 |
| -### Running tests |
| 62 | + **A hint**: it might be a good idea to add these scripts to your `package.json` file. |
| 63 | + For example, you project structure could look like this: |
32 | 64 |
|
33 |
| -Tests are split into unit and integration categories. By default integration tests require a locally running Fluence node with 4310 port open for ws connections. The dependency can be started with docker |
| 65 | + ``` |
| 66 | + ┣ _aqua |
| 67 | + ┃ ┗ demo.aqua |
| 68 | + ┣ src |
| 69 | + ┃ ┣ _aqua |
| 70 | + ┃ ┃ ┗ demo.ts |
| 71 | + ┃ ┗ index.ts |
| 72 | + ┣ package-lock.json |
| 73 | + ┣ package.json |
| 74 | + ┗ tsconfig.json |
| 75 | + ``` |
34 | 76 |
|
35 |
| -```bash |
36 |
| - docker run --rm -e RUST_LOG="info" -p 1210:1210 -p 4310:4310 fluencelabs/fluence -t 1210 -w 4310 -k gKdiCSUr1TFGFEgu2t8Ch1XEUsrN5A2UfBLjSZvfci9SPR3NvZpACfcpPGC3eY4zma1pk7UvYv5zb1VjvPHwCjj |
37 |
| -``` |
| 77 | + Then, your `package.json` file should include the following lines: |
38 | 78 |
|
39 |
| -To run all tests |
| 79 | + ``` |
| 80 | + { |
| 81 | + ... |
| 82 | + "scripts": { |
| 83 | + ... |
| 84 | + "aqua:compile": "fluence aqua -i ./aqua/ -o ./src/_aqua", |
| 85 | + "aqua:watch": "fluence aqua -w -i ./aqua/ -o ./src/_aqua" |
| 86 | + }, |
| 87 | + ... |
| 88 | + } |
| 89 | + ``` |
40 | 90 |
|
41 |
| -```bash |
42 |
| -pnpm -r test |
43 |
| -``` |
| 91 | +6. Now you can import and call Aqua code from your application like |
| 92 | + this: |
44 | 93 |
|
45 |
| -To run only unit tests |
| 94 | + ``` |
| 95 | + import { getRelayTime } from "./_aqua/demo"; |
46 | 96 |
|
47 |
| -```bash |
48 |
| -pnpm -r test:unit |
49 |
| -``` |
| 97 | + async function buttonClick() { |
| 98 | + const time = await getRelayTime(); |
| 99 | + alert("relay time: " + time); |
| 100 | + } |
| 101 | + ``` |
50 | 102 |
|
51 |
| -To run only integration tests |
| 103 | +**Warning**: Fluence JS client for Node.js is currently broken. We will fix this shortly. |
| 104 | + |
| 105 | + |
| 106 | +## Development |
| 107 | + |
| 108 | +To hack on the Fluence JS Client itself, please refer to the [development page](./DEVELOPING.md). |
| 109 | + |
| 110 | + |
| 111 | +## Documentation |
| 112 | + |
| 113 | +The starting point for all documentation related to Fluence is |
| 114 | +[fluence.dev](https://fluence.dev/). We also have an active [YouTube channel](https://www.youtube.com/@fluencelabs). |
| 115 | + |
| 116 | + |
| 117 | +## Support |
| 118 | + |
| 119 | +Please, file an [issue](https://github.com/fluencelabs/fluence-js/issues) if you find a bug. You can also contact us at [Discord](https://discord.com/invite/5qSnPZKh7u) or [Telegram](https://t.me/fluence_project). We will do our best to resolve the issue ASAP. |
| 120 | + |
| 121 | +## Contributing |
52 | 122 |
|
53 |
| -```bash |
54 |
| -pnpm -r test:integration |
55 |
| -``` |
| 123 | +Any interested person is welcome to contribute to the project. Please, make sure you read and follow some basic [rules](./CONTRIBUTING.md). |
56 | 124 |
|
57 | 125 | ## License
|
58 | 126 |
|
59 |
| -[Apache 2.0](LICENSE) |
| 127 | +All software code is copyright (c) Fluence Labs, Inc. under the [Apache-2.0](./LICENSE) license. |
0 commit comments