|
@@ -77,5 +77,51 @@ client.connect().then(async () => {
|
77
|
77
|
})
|
78
|
78
|
```
|
79
|
79
|
|
|
80
|
+#Experimental typing support
|
|
81
|
+It is possible to declare pseudo-interfaces for servers and clients
|
|
82
|
+```typescript
|
|
83
|
+type MyInterface = RPCInterface<{
|
|
84
|
+ Group1: {
|
|
85
|
+ triggerCallbacks: (...args:any[]) => Promise<void>,
|
|
86
|
+ subscribe: (param:string, callback:Function) => Promise<SubscriptionResponse<{a: string}>>,
|
|
87
|
+ unsubscribe: (uuid:string) => Promise<void>
|
|
88
|
+ },
|
|
89
|
+ Group2: {
|
|
90
|
+ echo: (x:string) => Promise<string>
|
|
91
|
+ }
|
|
92
|
+}>
|
|
93
|
+```
|
|
94
|
+Create a client using
|
|
95
|
+```typescript
|
|
96
|
+RPCSocket.makeSocket<MyInterface>(port, host).then((async (client) => {
|
|
97
|
+ const r = await client.Group2.echo("hee") //tsc knows about available RPCs
|
|
98
|
+}))
|
|
99
|
+
|
|
100
|
+/* OR */
|
|
101
|
+
|
|
102
|
+const client = new Frontend.RPCSocket(20000, 'localhost')
|
|
103
|
+client.connect<MyInterface>().then((async (client) => {
|
|
104
|
+ const r = await client.Group2.echo("hee") //tsc knows about available RPCs
|
|
105
|
+}))
|
|
106
|
+```
|
|
107
|
+
|
|
108
|
+Create a server using
|
|
109
|
+```typescript
|
|
110
|
+new RPCServer<{a:string}, MyInterface>(20001,
|
|
111
|
+ [{
|
|
112
|
+ //...
|
|
113
|
+ },{
|
|
114
|
+ name: 'Group2', //Auto completion for names
|
|
115
|
+ exportRPCs: () => [{
|
|
116
|
+ name: 'echo', //this name too!
|
|
117
|
+ call: async (x) => x+"llo World!" //the paramter and return types are known by tsc
|
|
118
|
+ }]
|
|
119
|
+ }]
|
|
120
|
+)
|
|
121
|
+```
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
80
|
126
|
# Documentation
|
81
|
127
|
[https://gitea.frontblock.me/fw-docs/rpclibrary]
|