mirror of
https://github.com/fluencelabs/examples
synced 2025-04-25 02:32:16 +00:00
Fix getting started section
This commit is contained in:
parent
bc1785e463
commit
a88c04bfe1
@ -27,8 +27,6 @@ function App() {
|
||||
};
|
||||
|
||||
|
||||
const isConnected = Fluence.getStatus().isConnected
|
||||
|
||||
return (
|
||||
<div className="App">
|
||||
<header>
|
||||
@ -36,7 +34,7 @@ function App() {
|
||||
</header>
|
||||
|
||||
<div className="content">
|
||||
<h1>Status: {isConnected ? "Connected" : "Disconnected"}</h1>
|
||||
<h1>Status: {Fluence.getStatus().isConnected ? "Connected" : "Disconnected"}</h1>
|
||||
<button className="btn" onClick={onGetRelayTimeBtnClick}>
|
||||
Get relay time
|
||||
</button>
|
||||
|
24249
quickstart/1-browser-to-browser/package-lock.json
generated
24249
quickstart/1-browser-to-browser/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -2,7 +2,7 @@ import React, { useEffect, useState } from "react";
|
||||
import logo from "./logo.svg";
|
||||
import "./App.scss";
|
||||
|
||||
import { FluencePeer } from "@fluencelabs/fluence";
|
||||
import { Fluence } from "@fluencelabs/fluence";
|
||||
import { krasnodar } from "@fluencelabs/fluence-network-environment";
|
||||
import { sayHello, registerHelloPeer } from "./_aqua/getting-started";
|
||||
|
||||
@ -33,7 +33,7 @@ function App() {
|
||||
};
|
||||
|
||||
const helloBtnOnClick = async () => {
|
||||
if (!isConnected) {
|
||||
if (!Fluence.getStatus().isConnected) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -56,11 +56,11 @@ function App() {
|
||||
<tbody>
|
||||
<tr>
|
||||
<td className="bold">Peer id:</td>
|
||||
<td className="mono">{FluencePeer.default.connectionInfo.selfPeerId}</td>
|
||||
<td className="mono">{Fluence.getStatus().peerId!}</td>
|
||||
<td>
|
||||
<button
|
||||
className="btn-clipboard"
|
||||
onClick={() => copyToClipboard(FluencePeer.default.connectionInfo.selfPeerId!)}
|
||||
onClick={() => copyToClipboard(Fluence.getStatus().peerId!)}
|
||||
>
|
||||
<i className="gg-clipboard"></i>
|
||||
</button>
|
||||
@ -68,11 +68,11 @@ function App() {
|
||||
</tr>
|
||||
<tr>
|
||||
<td className="bold">Relay peer id:</td>
|
||||
<td className="mono">{FluencePeer.default.connectionInfo.connectedRelay}</td>
|
||||
<td className="mono">{Fluence.getStatus().relayPeerId}</td>
|
||||
<td>
|
||||
<button
|
||||
className="btn-clipboard"
|
||||
onClick={() => copyToClipboard(FluencePeer.default.connectionInfo.connectedRelay!)}
|
||||
onClick={() => copyToClipboard(Fluence.getStatus().relayPeerId!)}
|
||||
>
|
||||
<i className="gg-clipboard"></i>
|
||||
</button>
|
||||
|
@ -1,122 +1,115 @@
|
||||
/**
|
||||
*
|
||||
* This file is auto-generated. Do not edit manually: changes may be erased.
|
||||
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
|
||||
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
|
||||
* If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues
|
||||
* Aqua version: 0.3.0-224
|
||||
* Aqua version: 0.3.0-226
|
||||
*
|
||||
*/
|
||||
import { FluencePeer } from "@fluencelabs/fluence";
|
||||
import { Fluence, FluencePeer } from '@fluencelabs/fluence';
|
||||
import {
|
||||
ResultCodes,
|
||||
RequestFlow,
|
||||
RequestFlowBuilder,
|
||||
CallParams,
|
||||
} from "@fluencelabs/fluence/dist/internal/compilerSupport/v1";
|
||||
ResultCodes,
|
||||
RequestFlow,
|
||||
RequestFlowBuilder,
|
||||
CallParams,
|
||||
} from '@fluencelabs/fluence/dist/internal/compilerSupport/v1';
|
||||
|
||||
|
||||
// Services
|
||||
|
||||
export interface HelloPeerDef {
|
||||
hello: (from: string, callParams: CallParams<"from">) => string;
|
||||
}
|
||||
export interface HelloPeerDef {
|
||||
hello: (from: string, callParams: CallParams<'from'>) => string;
|
||||
}
|
||||
|
||||
export function registerHelloPeer(service: HelloPeerDef): void;
|
||||
export function registerHelloPeer(
|
||||
serviceId: string,
|
||||
service: HelloPeerDef
|
||||
): void;
|
||||
export function registerHelloPeer(
|
||||
peer: FluencePeer,
|
||||
service: HelloPeerDef
|
||||
): void;
|
||||
export function registerHelloPeer(
|
||||
peer: FluencePeer,
|
||||
serviceId: string,
|
||||
service: HelloPeerDef
|
||||
): void;
|
||||
export function registerHelloPeer(...args: any) {
|
||||
let peer: FluencePeer;
|
||||
let serviceId: any;
|
||||
let service: any;
|
||||
if (args[0] instanceof FluencePeer) {
|
||||
peer = args[0];
|
||||
} else {
|
||||
peer = FluencePeer.default;
|
||||
}
|
||||
|
||||
if (typeof args[0] === "string") {
|
||||
serviceId = args[0];
|
||||
} else if (typeof args[1] === "string") {
|
||||
serviceId = args[1];
|
||||
} else {
|
||||
serviceId = "HelloPeer";
|
||||
}
|
||||
|
||||
if (!(args[0] instanceof FluencePeer) && typeof args[0] === "object") {
|
||||
service = args[0];
|
||||
} else if (typeof args[1] === "object") {
|
||||
service = args[1];
|
||||
} else {
|
||||
service = args[2];
|
||||
}
|
||||
|
||||
peer.internals.callServiceHandler.use((req, resp, next) => {
|
||||
if (req.serviceId !== serviceId) {
|
||||
next();
|
||||
return;
|
||||
export function registerHelloPeer(service: HelloPeerDef): void;
|
||||
export function registerHelloPeer(serviceId: string, service: HelloPeerDef): void;
|
||||
export function registerHelloPeer(peer: FluencePeer, service: HelloPeerDef): void;
|
||||
export function registerHelloPeer(peer: FluencePeer, serviceId: string, service: HelloPeerDef): void;
|
||||
export function registerHelloPeer(...args: any) {
|
||||
let peer: FluencePeer;
|
||||
let serviceId: any;
|
||||
let service: any;
|
||||
if (FluencePeer.isInstance(args[0])) {
|
||||
peer = args[0];
|
||||
} else {
|
||||
peer = Fluence.getPeer();
|
||||
}
|
||||
|
||||
if (req.fnName === "hello") {
|
||||
const callParams = {
|
||||
...req.particleContext,
|
||||
tetraplets: {
|
||||
from: req.tetraplets[0],
|
||||
},
|
||||
};
|
||||
resp.retCode = ResultCodes.success;
|
||||
resp.result = service.hello(req.args[0], callParams);
|
||||
if (typeof args[0] === 'string') {
|
||||
serviceId = args[0];
|
||||
} else if (typeof args[1] === 'string') {
|
||||
serviceId = args[1];
|
||||
}
|
||||
else {
|
||||
serviceId = "HelloPeer"
|
||||
}
|
||||
|
||||
// Figuring out which overload is the service.
|
||||
// If the first argument is not Fluence Peer and it is an object, then it can only be the service def
|
||||
// If the first argument is peer, we are checking further. The second argument might either be
|
||||
// an object, that it must be the service object
|
||||
// or a string, which is the service id. In that case the service is the third argument
|
||||
if (!(FluencePeer.isInstance(args[0])) && typeof args[0] === 'object') {
|
||||
service = args[0];
|
||||
} else if (typeof args[1] === 'object') {
|
||||
service = args[1];
|
||||
} else {
|
||||
service = args[2];
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
}
|
||||
peer.internals.callServiceHandler.use((req, resp, next) => {
|
||||
if (req.serviceId !== serviceId) {
|
||||
next();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (req.fnName === 'hello') {
|
||||
|
||||
const callParams = {
|
||||
...req.particleContext,
|
||||
tetraplets: {
|
||||
from: req.tetraplets[0]
|
||||
},
|
||||
};
|
||||
resp.retCode = ResultCodes.success;
|
||||
resp.result = service.hello(req.args[0], callParams)
|
||||
|
||||
}
|
||||
|
||||
|
||||
next();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// Functions
|
||||
|
||||
export function sayHello(
|
||||
targetPeerId: string,
|
||||
targetRelayPeerId: string,
|
||||
config?: { ttl?: number }
|
||||
): Promise<string>;
|
||||
export function sayHello(
|
||||
peer: FluencePeer,
|
||||
targetPeerId: string,
|
||||
targetRelayPeerId: string,
|
||||
config?: { ttl?: number }
|
||||
): Promise<string>;
|
||||
export function sayHello(...args: any) {
|
||||
let peer: FluencePeer;
|
||||
let targetPeerId: any;
|
||||
let targetRelayPeerId: any;
|
||||
let config: any;
|
||||
if (args[0] instanceof FluencePeer) {
|
||||
peer = args[0];
|
||||
targetPeerId = args[1];
|
||||
targetRelayPeerId = args[2];
|
||||
config = args[3];
|
||||
} else {
|
||||
peer = FluencePeer.default;
|
||||
targetPeerId = args[0];
|
||||
targetRelayPeerId = args[1];
|
||||
config = args[2];
|
||||
}
|
||||
|
||||
let request: RequestFlow;
|
||||
const promise = new Promise<string>((resolve, reject) => {
|
||||
const r = new RequestFlowBuilder()
|
||||
.disableInjections()
|
||||
.withRawScript(
|
||||
`
|
||||
export function sayHello(targetPeerId: string, targetRelayPeerId: string, config?: {ttl?: number}) : Promise<string>;
|
||||
export function sayHello(peer: FluencePeer, targetPeerId: string, targetRelayPeerId: string, config?: {ttl?: number}) : Promise<string>;
|
||||
export function sayHello(...args: any) {
|
||||
let peer: FluencePeer;
|
||||
let targetPeerId: any;
|
||||
let targetRelayPeerId: any;
|
||||
let config: any;
|
||||
if (FluencePeer.isInstance(args[0])) {
|
||||
peer = args[0];
|
||||
targetPeerId = args[1];
|
||||
targetRelayPeerId = args[2];
|
||||
config = args[3];
|
||||
} else {
|
||||
peer = Fluence.getPeer();
|
||||
targetPeerId = args[0];
|
||||
targetRelayPeerId = args[1];
|
||||
config = args[2];
|
||||
}
|
||||
|
||||
let request: RequestFlow;
|
||||
const promise = new Promise<string>((resolve, reject) => {
|
||||
const r = new RequestFlowBuilder()
|
||||
.disableInjections()
|
||||
.withRawScript(
|
||||
`
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
@ -161,37 +154,34 @@ export function sayHello(...args: any) {
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
|
||||
)
|
||||
|
||||
`
|
||||
)
|
||||
.configHandler((h) => {
|
||||
h.on("getDataSrv", "-relay-", () => {
|
||||
return peer.connectionInfo.connectedRelay;
|
||||
});
|
||||
h.on("getDataSrv", "targetPeerId", () => {
|
||||
return targetPeerId;
|
||||
});
|
||||
h.on("getDataSrv", "targetRelayPeerId", () => {
|
||||
return targetRelayPeerId;
|
||||
});
|
||||
h.onEvent("callbackSrv", "response", (args) => {
|
||||
const [res] = args;
|
||||
resolve(res);
|
||||
});
|
||||
`,
|
||||
)
|
||||
.configHandler((h) => {
|
||||
h.on('getDataSrv', '-relay-', () => {
|
||||
return peer.getStatus().relayPeerId;
|
||||
});
|
||||
h.on('getDataSrv', 'targetPeerId', () => {return targetPeerId;});
|
||||
h.on('getDataSrv', 'targetRelayPeerId', () => {return targetRelayPeerId;});
|
||||
h.onEvent('callbackSrv', 'response', (args) => {
|
||||
const [res] = args;
|
||||
resolve(res);
|
||||
});
|
||||
|
||||
h.onEvent("errorHandlingSrv", "error", (args) => {
|
||||
const [err] = args;
|
||||
reject(err);
|
||||
});
|
||||
})
|
||||
.handleScriptError(reject)
|
||||
.handleTimeout(() => {
|
||||
reject("Request timed out for sayHello");
|
||||
});
|
||||
if (config && config.ttl) {
|
||||
r.withTTL(config.ttl);
|
||||
}
|
||||
request = r.build();
|
||||
});
|
||||
peer.internals.initiateFlow(request!);
|
||||
return promise;
|
||||
h.onEvent('errorHandlingSrv', 'error', (args) => {
|
||||
const [err] = args;
|
||||
reject(err);
|
||||
});
|
||||
})
|
||||
.handleScriptError(reject)
|
||||
.handleTimeout(() => {
|
||||
reject('Request timed out for sayHello');
|
||||
})
|
||||
if(config && config.ttl) {
|
||||
r.withTTL(config.ttl)
|
||||
}
|
||||
request = r.build();
|
||||
});
|
||||
peer.internals.initiateFlow(request!);
|
||||
return promise;
|
||||
}
|
||||
|
||||
|
24249
quickstart/3-browser-to-service/package-lock.json
generated
24249
quickstart/3-browser-to-service/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -2,7 +2,7 @@ import React, { useState } from "react";
|
||||
import logo from "./logo.svg";
|
||||
import "./App.scss";
|
||||
|
||||
import { FluencePeer } from "@fluencelabs/fluence";
|
||||
import { Fluence } from "@fluencelabs/fluence";
|
||||
import { krasnodar } from "@fluencelabs/fluence-network-environment";
|
||||
import { registerHelloPeer, sayHello } from "./_aqua/getting-started";
|
||||
|
||||
@ -56,11 +56,11 @@ function App() {
|
||||
<tbody>
|
||||
<tr>
|
||||
<td className="bold">Peer id:</td>
|
||||
<td className="mono">{FluencePeer.default.connectionInfo.selfPeerId}</td>
|
||||
<td className="mono">{Fluence.getStatus().peerId!}</td>
|
||||
<td>
|
||||
<button
|
||||
className="btn-clipboard"
|
||||
onClick={() => copyToClipboard(FluencePeer.default.connectionInfo.selfPeerId)}
|
||||
onClick={() => copyToClipboard(Fluence.getStatus().peerId!)}
|
||||
>
|
||||
<i className="gg-clipboard"></i>
|
||||
</button>
|
||||
@ -68,11 +68,11 @@ function App() {
|
||||
</tr>
|
||||
<tr>
|
||||
<td className="bold">Relay peer id:</td>
|
||||
<td className="mono">{FluencePeer.default.connectionInfo.connectedRelay}</td>
|
||||
<td className="mono">{Fluence.getStatus().relayPeerId!}</td>
|
||||
<td>
|
||||
<button
|
||||
className="btn-clipboard"
|
||||
onClick={() => copyToClipboard(FluencePeer.default.connectionInfo.connectedRelay!)}
|
||||
onClick={() => copyToClipboard(Fluence.getStatus().relayPeerId!)}
|
||||
>
|
||||
<i className="gg-clipboard"></i>
|
||||
</button>
|
||||
|
@ -3,10 +3,10 @@
|
||||
* This file is auto-generated. Do not edit manually: changes may be erased.
|
||||
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
|
||||
* If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues
|
||||
* Aqua version: 0.3.0-224
|
||||
* Aqua version: 0.3.0-226
|
||||
*
|
||||
*/
|
||||
import { FluencePeer } from '@fluencelabs/fluence';
|
||||
import { Fluence, FluencePeer } from '@fluencelabs/fluence';
|
||||
import {
|
||||
ResultCodes,
|
||||
RequestFlow,
|
||||
@ -27,10 +27,10 @@ export function registerHelloWorld(peer: FluencePeer, serviceId: string, service
|
||||
let peer: FluencePeer;
|
||||
let serviceId: any;
|
||||
let service: any;
|
||||
if (args[0] instanceof FluencePeer) {
|
||||
if (FluencePeer.isInstance(args[0])) {
|
||||
peer = args[0];
|
||||
} else {
|
||||
peer = FluencePeer.default;
|
||||
peer = Fluence.getPeer();
|
||||
}
|
||||
|
||||
if (typeof args[0] === 'string') {
|
||||
@ -39,7 +39,12 @@ export function registerHelloWorld(peer: FluencePeer, serviceId: string, service
|
||||
serviceId = args[1];
|
||||
}
|
||||
|
||||
if (!(args[0] instanceof FluencePeer) && typeof args[0] === 'object') {
|
||||
// Figuring out which overload is the service.
|
||||
// If the first argument is not Fluence Peer and it is an object, then it can only be the service def
|
||||
// If the first argument is peer, we are checking further. The second argument might either be
|
||||
// an object, that it must be the service object
|
||||
// or a string, which is the service id. In that case the service is the third argument
|
||||
if (!(FluencePeer.isInstance(args[0])) && typeof args[0] === 'object') {
|
||||
service = args[0];
|
||||
} else if (typeof args[1] === 'object') {
|
||||
service = args[1];
|
||||
@ -86,10 +91,10 @@ export function registerHelloPeer(peer: FluencePeer, serviceId: string, service:
|
||||
let peer: FluencePeer;
|
||||
let serviceId: any;
|
||||
let service: any;
|
||||
if (args[0] instanceof FluencePeer) {
|
||||
if (FluencePeer.isInstance(args[0])) {
|
||||
peer = args[0];
|
||||
} else {
|
||||
peer = FluencePeer.default;
|
||||
peer = Fluence.getPeer();
|
||||
}
|
||||
|
||||
if (typeof args[0] === 'string') {
|
||||
@ -101,7 +106,12 @@ export function registerHelloPeer(peer: FluencePeer, serviceId: string, service:
|
||||
serviceId = "HelloPeer"
|
||||
}
|
||||
|
||||
if (!(args[0] instanceof FluencePeer) && typeof args[0] === 'object') {
|
||||
// Figuring out which overload is the service.
|
||||
// If the first argument is not Fluence Peer and it is an object, then it can only be the service def
|
||||
// If the first argument is peer, we are checking further. The second argument might either be
|
||||
// an object, that it must be the service object
|
||||
// or a string, which is the service id. In that case the service is the third argument
|
||||
if (!(FluencePeer.isInstance(args[0])) && typeof args[0] === 'object') {
|
||||
service = args[0];
|
||||
} else if (typeof args[1] === 'object') {
|
||||
service = args[1];
|
||||
@ -144,13 +154,13 @@ export function registerHelloPeer(peer: FluencePeer, serviceId: string, service:
|
||||
let targetPeerId: any;
|
||||
let targetRelayPeerId: any;
|
||||
let config: any;
|
||||
if (args[0] instanceof FluencePeer) {
|
||||
if (FluencePeer.isInstance(args[0])) {
|
||||
peer = args[0];
|
||||
targetPeerId = args[1];
|
||||
targetRelayPeerId = args[2];
|
||||
config = args[3];
|
||||
} else {
|
||||
peer = FluencePeer.default;
|
||||
peer = Fluence.getPeer();
|
||||
targetPeerId = args[0];
|
||||
targetRelayPeerId = args[1];
|
||||
config = args[2];
|
||||
@ -219,7 +229,7 @@ config = args[2];
|
||||
)
|
||||
.configHandler((h) => {
|
||||
h.on('getDataSrv', '-relay-', () => {
|
||||
return peer.connectionInfo.connectedRelay ;
|
||||
return peer.getStatus().relayPeerId;
|
||||
});
|
||||
h.on('getDataSrv', 'targetPeerId', () => {return targetPeerId;});
|
||||
h.on('getDataSrv', 'targetRelayPeerId', () => {return targetRelayPeerId;});
|
||||
|
Loading…
x
Reference in New Issue
Block a user