Skip to content

Commit fbfc344

Browse files
author
Akim
authored
chore(js-client): Update and restructure examples [fixes DXJ-454] (#464)
* Update examples * Update js-client examples * Add cli to example * Fixes * Update js-client * Update js-client version in js-client examples * PR fixes * Remove marine-js * Update locks * Fix aqua * Remove unused import * Adjust import * Change code comment * Update example structures * Fix quickstart examples * Add aqua command to README * Add marine example * Fix image links * Fixes * Misc fixes
1 parent f2b057b commit fbfc344

File tree

180 files changed

+112609
-235460
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

180 files changed

+112609
-235460
lines changed

.github/workflows/js-projects.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
with:
2727
files: |
2828
quickstart/1-browser-to-browser
29-
quickstart/3-browser-to-service
29+
quickstart/2-browser-parallel-computation
3030
js-client-examples/hello-world
3131
js-client-examples/browser-example
3232
js-client-examples/node-example

js-client-examples/browser-example/.fluence/schemas/fluence.json

Lines changed: 779 additions & 0 deletions
Large diffs are not rendered by default.

js-client-examples/browser-example/README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,26 @@
22

33
This sample project demonstrates how fluence network can be accessed from the browser. As an example it retrieves the timestamp of the current time from the relay node. The project is based on an create-react-app template with slight modifications to integrate Fluence. The primary focus is the integration itself, i.e React could be swapped with a framework of your choice.
44

5+
> To run this example you need `@latest` version of Fluence CLI. You can find installation guide [here](https://github.com/fluencelabs/cli).
6+
57
## Getting started
68

9+
Go to `src/frontend` folder:
10+
11+
```bash
12+
cd ./src/frontend
13+
```
14+
715
Install dependencies:
816

917
```bash
1018
npm i
1119
```
1220

13-
Run aqua compiler in watch mode:
21+
Run aqua compiler:
1422

1523
```bash
16-
npm run watch-aqua
24+
fluence aqua
1725
```
1826

1927
Start the application
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# yaml-language-server: $schema=.fluence/schemas/fluence.json
2+
3+
# Defines Fluence Project, most importantly - what exactly you want to deploy and how. You can use `fluence init` command to generate a template for new Fluence project
4+
5+
# Documentation: https://github.com/fluencelabs/cli/tree/main/docs/configs/fluence.md
6+
7+
version: 5
8+
9+
aquaInputPath: src/aqua
10+
11+
relaysPath: src/frontend/src
12+
13+
aquaOutputTSPath: src/frontend/src/compiled-aqua

js-client-examples/browser-example/.gitignore renamed to js-client-examples/browser-example/src/frontend/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ yarn-error.log*
2424

2525
# fluence
2626

27-
src/_aqua/*
27+
src/compiled-aqua/*
2828

2929
public/*.wasm
3030
public/runnerScript.*

js-client-examples/browser-example/package-lock.json renamed to js-client-examples/browser-example/src/frontend/package-lock.json

Lines changed: 22749 additions & 48230 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

quickstart/1-browser-to-browser/package.json renamed to js-client-examples/browser-example/src/frontend/package.json

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
"version": "0.1.0",
44
"private": true,
55
"dependencies": {
6-
"@fluencelabs/js-client.api": "0.13.1",
7-
"@fluencelabs/fluence-network-environment": "1.1.2",
6+
"@fluencelabs/js-client": "^0.5.4",
87
"@testing-library/jest-dom": "^5.14.1",
98
"@testing-library/react": "^11.2.7",
109
"@testing-library/user-event": "^12.8.3",
@@ -20,15 +19,11 @@
2019
"web-vitals": "^1.1.2"
2120
},
2221
"scripts": {
23-
"prestart": "npm run compile-aqua",
24-
"prebuild": "npm run compile-aqua",
2522
"start": "react-scripts start",
2623
"build": "react-scripts build",
2724
"test": "jest --config=jest.config.js",
2825
"_test": "react-scripts test",
29-
"eject": "react-scripts eject",
30-
"compile-aqua": "fluence aqua -i ./aqua/ -o ./src/_aqua",
31-
"watch-aqua": "fluence aqua -w -i ./aqua/ -o ./src/_aqua"
26+
"eject": "react-scripts eject"
3227
},
3328
"eslintConfig": {
3429
"extends": [
@@ -51,8 +46,6 @@
5146
]
5247
},
5348
"devDependencies": {
54-
"@fluencelabs/cli": "0.9.1",
55-
"@fluencelabs/aqua-lib": "0.7.7",
5649
"@types/jest-environment-puppeteer": "^4.4.1",
5750
"@types/puppeteer": "^5.4.4",
5851
"jest-puppeteer": "^6.0.2",

js-client-examples/browser-example/src/App.tsx renamed to js-client-examples/browser-example/src/frontend/src/App.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
11
import React, { useEffect, useState } from 'react';
22
import logo from './logo.svg';
33
import './App.scss';
4+
import relays from './relays.json';
45

5-
import { Fluence } from '@fluencelabs/js-client.api';
6-
import type { ConnectionState } from '@fluencelabs/js-client.api';
7-
import { krasnodar } from '@fluencelabs/fluence-network-environment';
8-
import { getRelayTime } from './_aqua/getting-started';
6+
import { Fluence, type ConnectionState } from '@fluencelabs/js-client';
7+
import { getRelayTime } from './compiled-aqua/getting-started';
98

10-
const relayNode = krasnodar[0];
9+
const relayNode = relays[0];
1110

1211
function App() {
1312
const [connectionState, setConnectionState] = useState<ConnectionState>('disconnected');
1413
const [relayTime, setRelayTime] = useState<Date | null>(null);
1514

1615
useEffect(() => {
17-
Fluence.onConnectionStateChange((state) => {
18-
setConnectionState(state);
16+
setConnectionState('connecting');
17+
Fluence.connect(relays[0]).then(() => {
18+
setConnectionState('connected');
1919
});
2020
}, []);
2121

2222
const onGetRelayTimeBtnClick = async () => {
2323
if (connectionState !== 'connected') {
2424
return;
2525
}
26-
2726
const time = await getRelayTime(relayNode.peerId);
2827
setRelayTime(new Date(time));
2928
};

js-client-examples/browser-example/src/index.tsx renamed to js-client-examples/browser-example/src/frontend/src/index.tsx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,6 @@ import ReactDOM from 'react-dom';
33
import './index.css';
44
import App from './App';
55

6-
import { Fluence } from '@fluencelabs/js-client.api';
7-
import { randomKras } from '@fluencelabs/fluence-network-environment';
8-
9-
const relayNode = randomKras();
10-
11-
Fluence.connect(relayNode);
12-
136
ReactDOM.render(
147
<React.StrictMode>
158
<App />
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
[
2+
{
3+
"multiaddr": "/dns4/0-kras.fluence.dev/tcp/9000/wss/p2p/12D3KooWSD5PToNiLQwKDXsu8JSysCwUt8BVUJEqCHcDe7P5h45e",
4+
"peerId": "12D3KooWSD5PToNiLQwKDXsu8JSysCwUt8BVUJEqCHcDe7P5h45e"
5+
},
6+
{
7+
"multiaddr": "/dns4/1-kras.fluence.dev/tcp/9000/wss/p2p/12D3KooWR4cv1a8tv7pps4HH6wePNaK6gf1Hww5wcCMzeWxyNw51",
8+
"peerId": "12D3KooWR4cv1a8tv7pps4HH6wePNaK6gf1Hww5wcCMzeWxyNw51"
9+
},
10+
{
11+
"multiaddr": "/dns4/2-kras.fluence.dev/tcp/9000/wss/p2p/12D3KooWKnEqMfYo9zvfHmqTLpLdiHXPe4SVqUWcWHDJdFGrSmcA",
12+
"peerId": "12D3KooWKnEqMfYo9zvfHmqTLpLdiHXPe4SVqUWcWHDJdFGrSmcA"
13+
},
14+
{
15+
"multiaddr": "/dns4/3-kras.fluence.dev/tcp/9000/wss/p2p/12D3KooWHLxVhUQyAuZe6AHMB29P7wkvTNMn7eDMcsqimJYLKREf",
16+
"peerId": "12D3KooWHLxVhUQyAuZe6AHMB29P7wkvTNMn7eDMcsqimJYLKREf"
17+
},
18+
{
19+
"multiaddr": "/dns4/4-kras.fluence.dev/tcp/9000/wss/p2p/12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE",
20+
"peerId": "12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE"
21+
},
22+
{
23+
"multiaddr": "/dns4/5-kras.fluence.dev/tcp/9000/wss/p2p/12D3KooWFEwNWcHqi9rtsmDhsYcDbRUCDXH84RC4FW6UfsFWaoHi",
24+
"peerId": "12D3KooWFEwNWcHqi9rtsmDhsYcDbRUCDXH84RC4FW6UfsFWaoHi"
25+
},
26+
{
27+
"multiaddr": "/dns4/6-kras.fluence.dev/tcp/9000/wss/p2p/12D3KooWCMr9mU894i8JXAFqpgoFtx6qnV1LFPSfVc3Y34N4h4LS",
28+
"peerId": "12D3KooWCMr9mU894i8JXAFqpgoFtx6qnV1LFPSfVc3Y34N4h4LS"
29+
},
30+
{
31+
"multiaddr": "/dns4/7-kras.fluence.dev/tcp/9000/wss/p2p/12D3KooWDUszU2NeWyUVjCXhGEt1MoZrhvdmaQQwtZUriuGN1jTr",
32+
"peerId": "12D3KooWDUszU2NeWyUVjCXhGEt1MoZrhvdmaQQwtZUriuGN1jTr"
33+
},
34+
{
35+
"multiaddr": "/dns4/8-kras.fluence.dev/tcp/9000/wss/p2p/12D3KooWEFFCZnar1cUJQ3rMWjvPQg6yMV2aXWs2DkJNSRbduBWn",
36+
"peerId": "12D3KooWEFFCZnar1cUJQ3rMWjvPQg6yMV2aXWs2DkJNSRbduBWn"
37+
},
38+
{
39+
"multiaddr": "/dns4/9-kras.fluence.dev/tcp/9000/wss/p2p/12D3KooWFtf3rfCDAfWwt6oLZYZbDfn9Vn7bv7g6QjjQxUUEFVBt",
40+
"peerId": "12D3KooWFtf3rfCDAfWwt6oLZYZbDfn9Vn7bv7g6QjjQxUUEFVBt"
41+
},
42+
{
43+
"multiaddr": "/dns4/10-kras.fluence.dev/tcp/9000/wss/p2p/12D3KooWD7CvsYcpF9HE9CCV9aY3SJ317tkXVykjtZnht2EbzDPm",
44+
"peerId": "12D3KooWD7CvsYcpF9HE9CCV9aY3SJ317tkXVykjtZnht2EbzDPm"
45+
}
46+
]

0 commit comments

Comments
 (0)