v 1.2.0
This commit is contained in:
@@ -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
|
||||
[https://gitea.frontblock.me/fw-docs/rpclibrary]
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "rpclibrary",
|
||||
"version": "1.1.6",
|
||||
"version": "1.2.0",
|
||||
"description": "rpclibrary is a websocket on steroids!",
|
||||
"main": "./js/Index.js",
|
||||
"repository": {
|
||||
|
||||
Reference in New Issue
Block a user