This commit is contained in:
2019-09-23 17:26:54 +02:00
parent 257c1eeced
commit c45f9a2558
2 changed files with 47 additions and 1 deletions
+46
View File
@@ -77,5 +77,51 @@ client.connect().then(async () => {
}) })
``` ```
#Experimental typing support
It is possible to declare pseudo-interfaces for servers and clients
```typescript
type MyInterface = RPCInterface<{
Group1: {
triggerCallbacks: (...args:any[]) => Promise<void>,
subscribe: (param:string, callback:Function) => Promise<SubscriptionResponse<{a: string}>>,
unsubscribe: (uuid:string) => Promise<void>
},
Group2: {
echo: (x:string) => Promise<string>
}
}>
```
Create a client using
```typescript
RPCSocket.makeSocket<MyInterface>(port, host).then((async (client) => {
const r = await client.Group2.echo("hee") //tsc knows about available RPCs
}))
/* OR */
const client = new Frontend.RPCSocket(20000, 'localhost')
client.connect<MyInterface>().then((async (client) => {
const r = await client.Group2.echo("hee") //tsc knows about available RPCs
}))
```
Create a server using
```typescript
new RPCServer<{a:string}, MyInterface>(20001,
[{
//...
},{
name: 'Group2', //Auto completion for names
exportRPCs: () => [{
name: 'echo', //this name too!
call: async (x) => x+"llo World!" //the paramter and return types are known by tsc
}]
}]
)
```
# Documentation # Documentation
[https://gitea.frontblock.me/fw-docs/rpclibrary] [https://gitea.frontblock.me/fw-docs/rpclibrary]
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "rpclibrary", "name": "rpclibrary",
"version": "1.1.6", "version": "1.2.0",
"description": "rpclibrary is a websocket on steroids!", "description": "rpclibrary is a websocket on steroids!",
"main": "./js/Index.js", "main": "./js/Index.js",
"repository": { "repository": {