Comparing version 1.2.0 to 1.2.3
26
index.js
@@ -7,3 +7,3 @@ 'use strict'; // always strict mode | ||
const ipc = require ('node-ipc'); | ||
const nacl = require ('tweetnacljs'); | ||
const nacl = require ('tweetnacl'); | ||
@@ -44,6 +44,15 @@ // Create general RPC class | ||
// Return function which takes all trailing params | ||
return async (...params) => { | ||
return (async (...params) => { | ||
// Issue remote call with property name and recieved params | ||
return await this._call (property, params); | ||
}; | ||
let result = await this._call (property, params); | ||
// Check if response is error | ||
if (result.isError) { | ||
// Throw if error to emulate native function | ||
throw result.data; | ||
} else { | ||
// Non error, simply return data | ||
return result.data; | ||
} | ||
}); | ||
}, | ||
@@ -114,10 +123,3 @@ }; | ||
// Check if response is error | ||
if (response.isError) { | ||
// Throw if error to emulate native function | ||
throw new Error(response.data); | ||
} else { | ||
// Non error, simply return data | ||
return response.data; | ||
} | ||
return response; | ||
} | ||
@@ -124,0 +126,0 @@ |
{ | ||
"name": "arc-rpc", | ||
"version": "1.2.0", | ||
"version": "1.2.3", | ||
"description": "Asynchronous Remote Classes make RPC simple", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -20,12 +20,19 @@ # Arc RPC | ||
``` | ||
```js | ||
// Include library for IPC-RPC clients | ||
let ClientIpcRpc = require("arc-rpc").ClientIpcRpc | ||
let rpc = null | ||
// Define `serverIpc` in higher scope for testing purposes | ||
let serverRpc = null | ||
// Example remotely-callable class (this can be anything) | ||
class ClientClass { | ||
// Example method | ||
clientTest() { | ||
console.log("Remotely called by server, calling server method.") | ||
let server = rpc.genClass() | ||
await server.serverTest() | ||
// Call remote as if it was a local class instance | ||
await rpc.class.serverTest() | ||
// This is garuanteed to be afterwards, as ES7 awaits are used | ||
console.log("Called remote server method!") | ||
@@ -35,3 +42,4 @@ } | ||
rpc = new ClientIpcRpc ("testing", Buffer.from ('flbd+mTz8bIWl2DQxFMKHYAA1+PFxpEKmVNsZpFP5xQ=', 'base64'), new ClientClass()) | ||
// Create RPC to server, on IPC channel testing, predefined encryption key, with an instance of the example client class | ||
serverRpc = new ClientIpcRpc ("testing", Buffer.from ('flbd+mTz8bIWl2DQxFMKHYAA1+PFxpEKmVNsZpFP5xQ=', 'base64'), new ClientClass()) | ||
``` | ||
@@ -41,5 +49,8 @@ | ||
``` | ||
```js | ||
// Include library for IPC-RPC servers | ||
let ServerIpcRpcMaster = require("arc-rpc").ServerIpcRpcMaster | ||
// Example remotely-callable class (this can be anything) | ||
class ServerClass { | ||
@@ -51,8 +62,13 @@ serverTest() { | ||
// Create RPC master/listener, on IPC channel testing, predefined encryption key, with an instance of the example server class | ||
let rpcMaster = new ServerIpcRpcMaster ("testing", Buffer.from ('flbd+mTz8bIWl2DQxFMKHYAA1+PFxpEKmVNsZpFP5xQ=', 'base64'), new ServerClass()) | ||
// Listen for new clients | ||
rpcMaster.on("client", (clientRpc) => { | ||
console.log("Got new client, remotely calling client test.") | ||
let client = clientRpc.genClass() | ||
await client.clientTest() | ||
// Call remote as if it was a local class instance | ||
await clientRpc.class.clientTest() | ||
// This is garuanteed to be afterwards, as ES7 awaits are used | ||
console.log("Remotely called client test!") | ||
@@ -59,0 +75,0 @@ }) |
10365
236
76