Browse Source

v 1.2.0

master
peter 4 years ago
parent
commit
c45f9a2558
2 changed files with 47 additions and 1 deletions
  1. 46
    0
      README.md
  2. 1
    1
      package.json

+ 46
- 0
README.md View File

@@ -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]

+ 1
- 1
package.json View File

@@ -1,6 +1,6 @@
1 1
 {
2 2
   "name": "rpclibrary",
3
-  "version": "1.1.6",
3
+  "version": "1.2.0",
4 4
   "description": "rpclibrary is a websocket on steroids!",
5 5
   "main": "./js/Index.js",
6 6
   "repository": {

Loading…
Cancel
Save