mirror of
https://github.com/fluencelabs/examples
synced 2025-06-23 23:01:32 +00:00
Update js-sdk section
This commit is contained in:
3222
js-sdk-examples/hello-world/package-lock.json
generated
3222
js-sdk-examples/hello-world/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -4,7 +4,7 @@
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"exec": "node -r ts-node/register src/index.ts",
|
||||
"start": "node -r ts-node/register src/index.ts",
|
||||
"compile-aqua": "aqua --import . -i ./aqua/ -o ./src/_aqua",
|
||||
"watch-aqua": "chokidar \"**/*.aqua\" -c \"npm run compile-aqua\""
|
||||
},
|
||||
|
@ -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-222
|
||||
* Aqua version: 0.3.0-226
|
||||
*
|
||||
*/
|
||||
import { FluencePeer } from '@fluencelabs/fluence';
|
||||
import { Fluence, FluencePeer } from '@fluencelabs/fluence';
|
||||
import {
|
||||
ResultCodes,
|
||||
RequestFlow,
|
||||
@ -25,14 +25,14 @@ import {
|
||||
export function registerHelloWorld(serviceId: string, service: HelloWorldDef): void;
|
||||
export function registerHelloWorld(peer: FluencePeer, service: HelloWorldDef): void;
|
||||
export function registerHelloWorld(peer: FluencePeer, serviceId: string, service: HelloWorldDef): void;
|
||||
export function registerHelloWorld(...args) {
|
||||
export function registerHelloWorld(...args: any) {
|
||||
let peer: FluencePeer;
|
||||
let serviceId;
|
||||
let service;
|
||||
if (args[0] instanceof FluencePeer) {
|
||||
let serviceId: any;
|
||||
let service: any;
|
||||
if (FluencePeer.isInstance(args[0])) {
|
||||
peer = args[0];
|
||||
} else {
|
||||
peer = FluencePeer.default;
|
||||
peer = Fluence.getPeer();
|
||||
}
|
||||
|
||||
if (typeof args[0] === 'string') {
|
||||
@ -44,7 +44,12 @@ export function registerHelloWorld(peer: FluencePeer, serviceId: string, service
|
||||
serviceId = "hello-world"
|
||||
}
|
||||
|
||||
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];
|
||||
@ -82,15 +87,15 @@ export function registerHelloWorld(peer: FluencePeer, serviceId: string, service
|
||||
|
||||
export function sayHello(config?: {ttl?: number}) : Promise<void>;
|
||||
export function sayHello(peer: FluencePeer, config?: {ttl?: number}) : Promise<void>;
|
||||
export function sayHello(...args) {
|
||||
export function sayHello(...args: any) {
|
||||
let peer: FluencePeer;
|
||||
|
||||
let config;
|
||||
if (args[0] instanceof FluencePeer) {
|
||||
let config: any;
|
||||
if (FluencePeer.isInstance(args[0])) {
|
||||
peer = args[0];
|
||||
config = args[1];
|
||||
} else {
|
||||
peer = FluencePeer.default;
|
||||
peer = Fluence.getPeer();
|
||||
config = args[0];
|
||||
}
|
||||
|
||||
@ -112,7 +117,7 @@ export function registerHelloWorld(peer: FluencePeer, serviceId: string, service
|
||||
)
|
||||
.configHandler((h) => {
|
||||
h.on('getDataSrv', '-relay-', () => {
|
||||
return peer.connectionInfo.connectedRelay ;
|
||||
return peer.getStatus().relayPeerId;
|
||||
});
|
||||
|
||||
h.onEvent('callbackSrv', 'response', (args) => {
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { FluencePeer } from "@fluencelabs/fluence";
|
||||
import { Fluence } from "@fluencelabs/fluence";
|
||||
import { registerHelloWorld, sayHello } from "./_aqua/hello-world";
|
||||
|
||||
async function main() {
|
||||
await FluencePeer.default.init();
|
||||
await Fluence.start();
|
||||
|
||||
registerHelloWorld({
|
||||
hello: async (str) => {
|
||||
@ -12,7 +12,7 @@ async function main() {
|
||||
|
||||
await sayHello();
|
||||
|
||||
await FluencePeer.default.uninit();
|
||||
await Fluence.stop();
|
||||
}
|
||||
|
||||
main();
|
||||
|
Reference in New Issue
Block a user