mirror of
https://github.com/fluencelabs/fluence-js.git
synced 2025-06-29 07:41:35 +00:00
Fix host imports in fluence-js (#997)
This commit is contained in:
@ -59,7 +59,7 @@ export class FluenceClient {
|
||||
enqueueParticle(particle);
|
||||
} else {
|
||||
if (this.interpreter === undefined) {
|
||||
throw new Error("Undefined. Interpreter is not initialized. User 'Fluence.connect' to create a client.")
|
||||
throw new Error("Undefined. Interpreter is not initialized. Use 'Fluence.connect' to create a client.")
|
||||
}
|
||||
// start particle processing if queue is empty
|
||||
try {
|
||||
@ -87,8 +87,8 @@ export class FluenceClient {
|
||||
log.info("inner interpreter outcome:");
|
||||
log.info(stepperOutcome);
|
||||
|
||||
// do nothing if there is no `next_peer_pks`
|
||||
if (stepperOutcome.next_peer_pks.length > 0) {
|
||||
// do nothing if there is no `next_peer_pks` or if client isn't connected to the network
|
||||
if (stepperOutcome.next_peer_pks.length > 0 && this.connection) {
|
||||
let newParticle: Particle = {...particle};
|
||||
newParticle.data = JSON.parse(stepperOutcome.call_path);
|
||||
|
||||
@ -138,18 +138,27 @@ export class FluenceClient {
|
||||
return this.connection.disconnect();
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiate WebAssembly with AIR interpreter to execute AIR scripts
|
||||
*/
|
||||
async instantiateInterpreter() {
|
||||
this.interpreter = await instantiateInterpreter(this.selfPeerId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Establish a connection to the node. If the connection is already established, disconnect and reregister all services in a new connection.
|
||||
*
|
||||
* @param multiaddr
|
||||
*/
|
||||
async connect(multiaddr: string | Multiaddr): Promise<void> {
|
||||
|
||||
async connect(multiaddr: string | Multiaddr) {
|
||||
multiaddr = Multiaddr(multiaddr);
|
||||
|
||||
if (!this.interpreter) {
|
||||
throw Error("you must call 'instantiateInterpreter' before 'connect'")
|
||||
}
|
||||
|
||||
let nodePeerId = multiaddr.getPeerId();
|
||||
this.nodePeerIdStr = nodePeerId;
|
||||
|
||||
if (!nodePeerId) {
|
||||
throw Error("'multiaddr' did not contain a valid peer id")
|
||||
}
|
||||
@ -160,12 +169,8 @@ export class FluenceClient {
|
||||
await this.connection.disconnect();
|
||||
}
|
||||
|
||||
let peerId = PeerId.createFromB58String(nodePeerId);
|
||||
|
||||
this.interpreter = await instantiateInterpreter(this.selfPeerId);
|
||||
|
||||
let connection = new FluenceConnection(multiaddr, peerId, this.selfPeerId, this.handleExternalParticle());
|
||||
|
||||
let node = PeerId.createFromB58String(nodePeerId);
|
||||
let connection = new FluenceConnection(multiaddr, node, this.selfPeerId, this.handleExternalParticle());
|
||||
await connection.connect();
|
||||
|
||||
this.connection = connection;
|
||||
@ -176,6 +181,10 @@ export class FluenceClient {
|
||||
return particle.id
|
||||
}
|
||||
|
||||
async executeParticle(particle: Particle) {
|
||||
await this.handleParticle(particle);
|
||||
}
|
||||
|
||||
nodeIdentityCall(): string {
|
||||
return `(call "${this.nodePeerIdStr}" ("op" "identity") [] void[])`
|
||||
}
|
||||
|
Reference in New Issue
Block a user