diff --git a/package.json b/package.json index ce6c6aa1..c8f6bd0c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fluence", - "version": "0.6.1", + "version": "0.6.5", "description": "the browser js-libp2p client for the Fluence network", "main": "./dist/fluence.js", "typings": "./dist/fluence.d.ts", diff --git a/src/fluence_client.ts b/src/fluence_client.ts index 07f33cd6..bceb320c 100644 --- a/src/fluence_client.ts +++ b/src/fluence_client.ts @@ -70,9 +70,11 @@ export class FluenceClient { * @param target receiver * @param args message in the call * @param predicate will be applied to each incoming call until it matches + * @param moduleId module name + * @param fname functin name */ - async sendCallWaitResponse(target: Address, args: any, predicate: (args: any, target: Address, replyTo: Address) => (boolean | undefined)): Promise { - await this.sendCall(target, args, true); + async sendCallWaitResponse(target: Address, args: any, predicate: (args: any, target: Address, replyTo: Address) => (boolean | undefined), moduleId?: string, fname?: string): Promise { + await this.sendCall(target, args, true, moduleId, fname); return this.waitResponse(predicate); } @@ -82,11 +84,13 @@ export class FluenceClient { * @param target receiver * @param args message in the call * @param reply add a `replyTo` field or not + * @param moduleId module name + * @param fname function name * @param name common field for debug purposes */ - async sendCall(target: Address, args: any, reply?: boolean, name?: string) { + async sendCall(target: Address, args: any, reply?: boolean, moduleId?: string, fname?: string, name?: string) { if (this.connection && this.connection.isConnected()) { - await this.connection.sendFunctionCall(target, args, reply, name); + await this.connection.sendFunctionCall(target, args, reply, moduleId, fname, name); } else { throw Error("client is not connected") } @@ -95,13 +99,14 @@ export class FluenceClient { /** * Send call to the service. * - * @param serviceId + * @param moduleId * @param args message to the service + * @param fname function name * @param name common field for debug purposes */ - async sendServiceCall(serviceId: string, args: any, name?: string) { + async sendServiceCall(moduleId: string, args: any, fname?: string, name?: string) { if (this.connection && this.connection.isConnected()) { - await this.connection.sendServiceCall(serviceId, false, args, name); + await this.connection.sendServiceCall(moduleId, false, args, fname, name); } else { throw Error("client is not connected") } @@ -110,13 +115,14 @@ export class FluenceClient { /** * Send a call to the local service on a peer the client connected with. * - * @param serviceId + * @param moduleId * @param args message to the service + * @param fname function name * @param name common field for debug purposes */ - async sendServiceLocalCall(serviceId: string, args: any, name?: string) { + async sendServiceLocalCall(moduleId: string, args: any, fname?: string, name?: string) { if (this.connection && this.connection.isConnected()) { - await this.connection.sendServiceCall(serviceId, true, args, name); + await this.connection.sendServiceCall(moduleId, true, args, fname, name); } else { throw Error("client is not connected") } @@ -125,24 +131,26 @@ export class FluenceClient { /** * Send call to the service and wait a response matches predicate. * - * @param serviceId + * @param moduleId * @param args message to the service * @param predicate will be applied to each incoming call until it matches + * @param fname function name */ - async sendServiceCallWaitResponse(serviceId: string, args: any, predicate: (args: any, target: Address, replyTo: Address) => (boolean | undefined)): Promise { - await this.sendServiceCall(serviceId, args); + async sendServiceCallWaitResponse(moduleId: string, args: any, predicate: (args: any, target: Address, replyTo: Address) => (boolean | undefined), fname?: string): Promise { + await this.sendServiceCall(moduleId, args, fname, fname); return await this.waitResponse(predicate); } /** * Send a call to the local service and wait a response matches predicate on a peer the client connected with. * - * @param serviceId + * @param moduleId * @param args message to the service * @param predicate will be applied to each incoming call until it matches + * @param fname function name */ - async sendServiceLocalCallWaitResponse(serviceId: string, args: any, predicate: (args: any, target: Address, replyTo: Address) => (boolean | undefined)): Promise { - await this.sendServiceLocalCall(serviceId, args); + async sendServiceLocalCallWaitResponse(moduleId: string, args: any, predicate: (args: any, target: Address, replyTo: Address) => (boolean | undefined), fname?: string): Promise { + await this.sendServiceLocalCall(moduleId, args, fname); return await this.waitResponse(predicate); } @@ -230,10 +238,10 @@ export class FluenceClient { /** * Sends a call to register the service_id. */ - async registerService(serviceId: string, fn: (req: FunctionCall) => void) { - await this.connection.registerService(serviceId); + async registerService(moduleId: string, fn: (req: FunctionCall) => void) { + await this.connection.registerService(moduleId); - this.services.addService(serviceId, fn) + this.services.addService(moduleId, fn) } // subscribe new hook for every incoming call, to handle in-service responses and other different cases @@ -244,10 +252,10 @@ export class FluenceClient { /** - * Sends a call to unregister the service_id. + * Sends a call to unregister the service. */ - async unregisterService(serviceId: string) { - if (this.services.deleteService(serviceId)) { + async unregisterService(moduleId: string) { + if (this.services.deleteService(moduleId)) { console.warn("unregister is not implemented yet (service: ${serviceId}") // TODO unregister in fluence network when it will be supported // let regMsg = makeRegisterMessage(serviceId, PeerId.createFromB58String(this.nodePeerId)); diff --git a/src/fluence_connection.ts b/src/fluence_connection.ts index f511cfed..9c0ca0d2 100644 --- a/src/fluence_connection.ts +++ b/src/fluence_connection.ts @@ -89,15 +89,15 @@ export class FluenceConnection { /** * Sends remote service_id call. */ - async sendServiceCall(serviceId: string, isLocal: boolean, args: any, name?: string) { + async sendServiceCall(moduleId: string, isLocal: boolean, args: any, fname?: string, name?: string) { let target; if (isLocal) { target = createPeerAddress(this.nodePeerId.toB58String()); } else { - target = createServiceAddress(serviceId); + target = createServiceAddress(moduleId); } - let regMsg = makeCall(serviceId, target, args, this.sender, this.sender, name); + let regMsg = makeCall(moduleId, target, args, this.sender, this.sender, fname, name); await this.sendCall(regMsg); } @@ -187,13 +187,13 @@ export class FluenceConnection { /** * Send FunctionCall to the connected node. */ - async sendFunctionCall(target: Address, args: any, reply?: boolean, name?: string) { + async sendFunctionCall(target: Address, args: any, reply?: boolean, moduleId?: string, fname?: string, name?: string) { this.checkConnectedOrThrow(); let replyTo; if (reply) replyTo = this.sender; - let call = makeFunctionCall(genUUID(), target, this.sender, args, undefined, undefined, replyTo, name); + let call = makeFunctionCall(genUUID(), target, this.sender, args, moduleId, fname, replyTo, name); await this.sendCall(call); } diff --git a/src/function_call.ts b/src/function_call.ts index 4839df00..9aeca5d0 100644 --- a/src/function_call.ts +++ b/src/function_call.ts @@ -47,14 +47,14 @@ export function callToString(call: FunctionCall) { return JSON.stringify(obj) } -export function makeFunctionCall(uuid: string, target: Address, sender: Address, args: object, moduleF?: string, fname?: string, replyTo?: Address, name?: string): FunctionCall { +export function makeFunctionCall(uuid: string, target: Address, sender: Address, args: object, moduleId?: string, fname?: string, replyTo?: Address, name?: string): FunctionCall { return { uuid: uuid, target: target, reply_to: replyTo, sender: sender, - "module": moduleF, + "module": moduleId, fname: fname, arguments: args, name: name, @@ -113,12 +113,12 @@ export function makePeerCall(client: PeerId, msg: any, sender: Address, replyTo? } /** - * Message to call remote service_id + * Message to call remote service */ -export function makeCall(functionId: string, target: Address, args: any, sender: Address, replyTo?: Address, name?: string): FunctionCall { +export function makeCall(moduleId: string, target: Address, args: any, sender: Address, replyTo?: Address, fname?: string, name?: string): FunctionCall { - return makeFunctionCall(genUUID(), target, sender, args, functionId, undefined, replyTo, name); + return makeFunctionCall(genUUID(), target, sender, args, moduleId, fname, replyTo, name); } /**