|
@@ -12,7 +12,7 @@ import {Backend, Frontend} from 'rpclibrary'
|
12
|
12
|
|
13
|
13
|
const echo = (x) => x
|
14
|
14
|
|
15
|
|
-const server = new Backend.RPCServer(20000, [{
|
|
15
|
+const server = new Backend.RPCServer(port, [{
|
16
|
16
|
name: 'HelloWorldRPCGroup',
|
17
|
17
|
exportRPCs: () => [
|
18
|
18
|
echo, //named function variable
|
|
@@ -24,7 +24,7 @@ const server = new Backend.RPCServer(20000, [{
|
24
|
24
|
]
|
25
|
25
|
}])
|
26
|
26
|
|
27
|
|
-const client = new Frontend.RPCSocket(20000, 'localhost')
|
|
27
|
+const client = new Frontend.RPCSocket(port, host)
|
28
|
28
|
|
29
|
29
|
client.connect().then(async () => {
|
30
|
30
|
const r0 = await client['HelloWorldRPCGroup'].echo('Hello')
|
|
@@ -51,7 +51,7 @@ import {Backend, Frontend, Utils} from 'rpclibrary'
|
51
|
51
|
|
52
|
52
|
const callbacks:Map<string, Function> = new Map()
|
53
|
53
|
|
54
|
|
-const server = new Backend.RPCServer(20000, [{
|
|
54
|
+const server = new Backend.RPCServer(port, [{
|
55
|
55
|
name: 'HelloWorldRPCGroup',
|
56
|
56
|
exportRPCs: () => [
|
57
|
57
|
function triggerCallbacks(...messages){ callbacks.forEach(cb => cb.apply({}, messages)) },
|
|
@@ -69,7 +69,7 @@ const server = new Backend.RPCServer(20000, [{
|
69
|
69
|
]
|
70
|
70
|
}])
|
71
|
71
|
|
72
|
|
-const client = new Frontend.RPCSocket(20000, 'localhost')
|
|
72
|
+const client = new Frontend.RPCSocket(port, host)
|
73
|
73
|
client.connect().then(async () => {
|
74
|
74
|
const res = await client['HelloWorldRPCGroup'].subscribe(async (...args:any) => {
|
75
|
75
|
console.log.apply(console, args)
|
|
@@ -86,7 +86,7 @@ client.connect().then(async () => {
|
86
|
86
|
If you need to include further response data into your `SubscriptionResponse` you can extend it using the server's first generic parameter `SubResType`
|
87
|
87
|
|
88
|
88
|
```typescript
|
89
|
|
-new RPCServer<{extension: string}>({
|
|
89
|
+new RPCServer<{extension: string}>(port, {
|
90
|
90
|
name: 'MyRPCGroup',
|
91
|
91
|
exportRPCs: () => [{
|
92
|
92
|
name: 'subscribe',
|
|
@@ -126,7 +126,7 @@ RPCSocket.makeSocket<MyInterface>(port, host).then((async (client) => {
|
126
|
126
|
|
127
|
127
|
/* OR */
|
128
|
128
|
|
129
|
|
-const client = new Frontend.RPCSocket(20000, 'localhost')
|
|
129
|
+const client = new Frontend.RPCSocket(port, host)
|
130
|
130
|
client.connect<MyInterface>().then((async (client) => {
|
131
|
131
|
const r = await client.Group2.echo("hee") //tsc knows about available RPCs
|
132
|
132
|
}))
|
|
@@ -134,7 +134,7 @@ client.connect<MyInterface>().then((async (client) => {
|
134
|
134
|
|
135
|
135
|
Create a server using
|
136
|
136
|
```typescript
|
137
|
|
-new RPCServer<{a:string}, MyInterface>(20001,
|
|
137
|
+new RPCServer<{a:string}, MyInterface>(port,
|
138
|
138
|
[{
|
139
|
139
|
//...
|
140
|
140
|
},{
|