fix examples
This commit is contained in:
@@ -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<string, Function> = 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<MyInterface>(port, host).then((async (client) => {
|
||||
|
||||
/* OR */
|
||||
|
||||
const client = new Frontend.RPCSocket(port, host)
|
||||
const client = new RPCSocket(port, host)
|
||||
client.connect<MyInterface>().then((async (client) => {
|
||||
const r = await client.Group2.echo("hee") //tsc knows about available RPCs
|
||||
}))
|
||||
|
||||
Generated
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "rpclibrary",
|
||||
"version": "1.3.8",
|
||||
"version": "1.3.9",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
||||
Reference in New Issue
Block a user