From bbfc197d75e38dbfcda2d5438c940943c763d284 Mon Sep 17 00:00:00 2001 From: Daniel Huebleitner Date: Tue, 29 Oct 2019 19:42:44 +0100 Subject: [PATCH] fix examples --- README.md | 26 ++++++++++++++++---------- package-lock.json | 2 +- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 7d126be..302bf99 100644 --- a/README.md +++ b/README.md @@ -8,11 +8,14 @@ npm i rpclibrary # Quickstart ```typescript -import {Backend, Frontend} from 'rpclibrary' +import {RPCServer, RPCSocket} from 'rpclibrary' + +const port = 1234 +const host = 'locahost' const echo = (x) => x -const server = new Backend.RPCServer(port, [{ +const server = new RPCServer(port, [{ name: 'HelloWorldRPCGroup', exportRPCs: () => [ echo, //named function variable @@ -24,7 +27,7 @@ const server = new Backend.RPCServer(port, [{ ] }]) -const client = new Frontend.RPCSocket(port, host) +const client = new RPCSocket(port, host) client.connect().then(async () => { const r0 = await client['HelloWorldRPCGroup'].echo('Hello') @@ -47,11 +50,14 @@ The uuid, as the name implies, is used to uniquely identify the callback for a g You should unhook the client socket once you're done with it as not to cause security or control flow issues. ```typescript -import {Backend, Frontend, Utils} from 'rpclibrary' +import {RPCServer, RPCSocket} from 'rpclibrary' + +const port = 1234 +const host = 'locahost' const callbacks:Map = new Map() -const server = new Backend.RPCServer(port, [{ +new RPCServer(port, [{ name: 'HelloWorldRPCGroup', exportRPCs: () => [ function triggerCallbacks(...messages){ callbacks.forEach(cb => cb.apply({}, messages)) }, @@ -69,7 +75,7 @@ const server = new Backend.RPCServer(port, [{ ] }]) -const client = new Frontend.RPCSocket(port, host) +const client = new RPCSocket(port, host) client.connect().then(async () => { const res = await client['HelloWorldRPCGroup'].subscribe(async (...args:any) => { console.log.apply(console, args) @@ -86,7 +92,7 @@ client.connect().then(async () => { If you need to include further response data into your `SubscriptionResponse` you can extend it using the server's first generic parameter `SubResType` ```typescript -new RPCServer<{extension: string}>(port, { +new RPCServer<{extension: string}>(port, [{ name: 'MyRPCGroup', exportRPCs: () => [{ name: 'subscribe', @@ -97,8 +103,8 @@ new RPCServer<{extension: string}>(port, { extension: 'your_data_here' //tsc will demand this field } } - }] -}) + }]} +]) ``` @@ -126,7 +132,7 @@ RPCSocket.makeSocket(port, host).then((async (client) => { /* OR */ -const client = new Frontend.RPCSocket(port, host) +const client = new RPCSocket(port, host) client.connect().then((async (client) => { const r = await client.Group2.echo("hee") //tsc knows about available RPCs })) diff --git a/package-lock.json b/package-lock.json index e3e278f..4a3bfe0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "rpclibrary", - "version": "1.3.8", + "version": "1.3.9", "lockfileVersion": 1, "requires": true, "dependencies": {