Browse Source

fix examples

master
Daniel Huebleitner 4 years ago
parent
commit
bbfc197d75
2 changed files with 17 additions and 11 deletions
  1. 16
    10
      README.md
  2. 1
    1
      package-lock.json

+ 16
- 10
README.md View File

@@ -8,11 +8,14 @@ npm i rpclibrary
8 8
 
9 9
 # Quickstart
10 10
 ```typescript
11
-import {Backend, Frontend} from 'rpclibrary' 
11
+import {RPCServer, RPCSocket} from 'rpclibrary' 
12
+
13
+const port = 1234
14
+const host = 'locahost'
12 15
 
13 16
 const echo = (x) => x
14 17
 
15
-const server = new Backend.RPCServer(port, [{
18
+const server = new RPCServer(port, [{
16 19
     name: 'HelloWorldRPCGroup',
17 20
     exportRPCs: ()  => [
18 21
         echo, //named function variable
@@ -24,7 +27,7 @@ const server = new Backend.RPCServer(port, [{
24 27
     ]
25 28
 }])
26 29
 
27
-const client = new Frontend.RPCSocket(port, host)
30
+const client = new RPCSocket(port, host)
28 31
 
29 32
 client.connect().then(async () => {
30 33
     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
47 50
 You should unhook the client socket once you're done with it as not to cause security or control flow issues.
48 51
 
49 52
 ```typescript
50
-import {Backend, Frontend, Utils} from 'rpclibrary'
53
+import {RPCServer, RPCSocket} from 'rpclibrary'
54
+
55
+const port = 1234
56
+const host = 'locahost'
51 57
 
52 58
 const callbacks:Map<string, Function> = new Map()
53 59
 
54
-const server = new Backend.RPCServer(port, [{
60
+new RPCServer(port, [{
55 61
     name: 'HelloWorldRPCGroup',
56 62
     exportRPCs: ()  => [
57 63
         function  triggerCallbacks(...messages){ callbacks.forEach(cb => cb.apply({}, messages)) },
@@ -69,7 +75,7 @@ const server = new Backend.RPCServer(port, [{
69 75
     ]
70 76
 }])
71 77
 
72
-const client = new Frontend.RPCSocket(port, host)
78
+const client = new RPCSocket(port, host)
73 79
 client.connect().then(async () => {
74 80
     const res = await client['HelloWorldRPCGroup'].subscribe(async (...args:any) => {
75 81
         console.log.apply(console, args)
@@ -86,7 +92,7 @@ client.connect().then(async () => {
86 92
 If you need to include further response data into your `SubscriptionResponse` you can extend it using the server's first generic parameter `SubResType`
87 93
 
88 94
 ```typescript
89
-new RPCServer<{extension: string}>(port, {
95
+new RPCServer<{extension: string}>(port, [{
90 96
     name: 'MyRPCGroup',
91 97
     exportRPCs: ()  => [{
92 98
         name: 'subscribe',
@@ -97,8 +103,8 @@ new RPCServer<{extension: string}>(port, {
97 103
                 extension: 'your_data_here' //tsc will demand this field
98 104
             }
99 105
         }
100
-    }]
101
-})
106
+    }]}
107
+])
102 108
 
103 109
 ```
104 110
 
@@ -126,7 +132,7 @@ RPCSocket.makeSocket<MyInterface>(port, host).then((async (client) => {
126 132
 
127 133
 /* OR */
128 134
 
129
-const client = new Frontend.RPCSocket(port, host)
135
+const client = new RPCSocket(port, host)
130 136
 client.connect<MyInterface>().then((async (client) => {
131 137
     const r = await client.Group2.echo("hee") //tsc knows about available RPCs 
132 138
 })) 

+ 1
- 1
package-lock.json View File

@@ -1,6 +1,6 @@
1 1
 {
2 2
   "name": "rpclibrary",
3
-  "version": "1.3.8",
3
+  "version": "1.3.9",
4 4
   "lockfileVersion": 1,
5 5
   "requires": true,
6 6
   "dependencies": {

Loading…
Cancel
Save