@fluencelabs/fluence
exports a facade Fluence
which provides all the needed functionality for the most uses cases. It defined 4 functions:start
: Start the default peer.stop
: Stops the default peergetStatus
: Gets the status of the default peer. This includes connectiongetPeer
: Gets the default Fluence Peer instance (see below)Fluence
facade calls the corresponding method on the default instance of FluencePeer. This instance is passed to the Aqua-compiler generated functions by default.@fluencelabs/fluence
package is FluencePeer
class. It is useful in scenarios when the application need to run several different peer at once. The overall workflow with the FluencePeer
is the following:FluencePeer
class:start
function starts the Aqua VM, initializes the default call service handlers and (optionally) connect to the Fluence network. The function takes an optional object specifying additional peer configuration. On option you will be using a lot is connectTo
. It tells the peer to connect to a relay. For example:@fluencelabs/fluence-network-environment
package. The full list of supported options is described in the API reference​FluencePeer
instance for each of them. The generated functions accept the peer as the first argument. For example:func
declarations are turned into callable async functionsservice
declarations are turned into functions which register callback handler in a typed mannerservice
the compiler generated it's interface under the name {serviceName}Def
FluencePeer
instance as the first argument, and one without it. Otherwise arguments are the same and correspond to the arguments of aqua functions. The last argument is always an optional config object with the following properties:ttl
: Optional parameter which specify TTL (time to live) of particle with execution logic for the functionPromise<void>
.service
declaration the compiler will generate two entities: service interface under the name {serviceName}Def
and a function named register{serviceName}
with several overloads. First let's describe the most complete one using the following example:peer
- the Fluence Peer instance where the handler should be registered. The peer can be omitted. In that case the default Fluence Peer will be used insteadserviceId
- the name of the service id. If the service was defined with the default service id in aqua code, this argument can be omitted.service
- the handler for the service.CallParams
will be described later in the sectionstring
is converted to string
in typescriptbool
is converted to boolean
in typescriptu8
, u16
, u32
, u64
, s8
, s16
, s32
, s64
, f32
, f64
) are converted to number
in typescriptservice
and func
definitions. For example a func
with a callback might look like this:callback
argument will be:string | Promise<string>
. Fluence-js supports both sync and async version of callbacks and figures out which one is used under the hood. The callback be made asynchronous like any other function in javascript: either return a Promise or mark it with async keyword to take advantage of async-await pattern.initPeerId
- the peer which initiated the particle execution, particle signature and most importantly security tetraplets. All this data is contained inside the last callParams
argument in every generated function definition. These data is passed to the handler on each function call can be used in the application.securityGuard
specifies the way the sign
method checks where the incoming data is allowed to be signed or not. It accepts one argument: call params (see "Call params and tetraplets") and must return either true or false. Any predicate can be specified. Also, FluenceJS is shipped with a set of useful predicates:Sig
definition can be found in @fluencelabs/fluence/dist/services
Sig
class is accompanied by registerSig
which allows registering different signing services with different keys. The mechanism is exactly the same as with ordinary aqua services e.g:FluencePeer
ships with the default signing service implementation, registered with id "Sig". Is is useful to work with TrustGraph and Registry API. The default implementation has the following restrictions on the sign
operation:FluencePeer
API.FluencePeer
API.FluencePeer API
.FluencePeer
. To do so use registerMarineService function.
registerMarineService
function.