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

+ 1
- 1
package-lock.json View File

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

Loading…
Cancel
Save