瀏覽代碼

fix

master
Daniel Hübleitner 5 年之前
父節點
當前提交
76dee64a54

+ 0
- 19
lib/RPCaller.min.js
文件差異過大導致無法顯示
查看文件


lib/src/frontend/RPCSocket.d.ts → lib/src/Client.d.ts 查看文件

@@ -1,12 +1,5 @@
1
-import { Socket } from "../backend/RPCSocketServer";
2
-/**
3
- * Dynamic library to communicate with FrontblockService remotely
4
- *
5
- * This will be automatically injected into the webpages served by FrontblockService
6
- * Will ask it's service for available RPCs and parse them into methods of this object
7
- * for convenient access.
8
- */
9
-export declare class RPCSocket implements Socket {
1
+import { Socket } from './interfaces/Socket';
2
+export declare class Client implements Socket {
10 3
     port: number;
11 4
     private server;
12 5
     private tls;

lib/src/frontend/RPCSocket.js → lib/src/Client.js 查看文件

@@ -5,14 +5,7 @@ var bsock = require('bsock');
5 5
 function stripAfterEquals(str) {
6 6
     return str.split("=")[0];
7 7
 }
8
-/**
9
- * Dynamic library to communicate with FrontblockService remotely
10
- *
11
- * This will be automatically injected into the webpages served by FrontblockService
12
- * Will ask it's service for available RPCs and parse them into methods of this object
13
- * for convenient access.
14
- */
15
-class RPCSocket {
8
+class Client {
16 9
     constructor(port, server, tls = false) {
17 10
         this.port = port;
18 11
         this.server = server;
@@ -45,13 +38,13 @@ class RPCSocket {
45 38
         info.forEach(i => {
46 39
             let f;
47 40
             switch (i.type) {
48
-                case 'call':
41
+                case 'Call':
49 42
                     f = this.callGenerator(i.uniqueName, i.argNames);
50 43
                     break;
51
-                case 'hook':
44
+                case 'Hook':
52 45
                     f = this.hookGenerator(i.uniqueName, i.argNames);
53 46
                     break;
54
-                case 'unhook':
47
+                case 'Unhook':
55 48
                     f = this.unhookGenerator(i.uniqueName, i.argNames);
56 49
                     break;
57 50
             }
@@ -92,4 +85,4 @@ class RPCSocket {
92 85
                         } )()`);
93 86
     }
94 87
 }
95
-exports.RPCSocket = RPCSocket;
88
+exports.Client = Client;

+ 17
- 0
lib/src/Response.d.ts 查看文件

@@ -0,0 +1,17 @@
1
+export declare type Outcome = "Success" | "Error";
2
+export declare class Response {
3
+    message?: string | undefined;
4
+    constructor(message?: string | undefined);
5
+}
6
+export declare class SuccessResponse extends Response {
7
+    result: Outcome;
8
+    constructor(message?: string);
9
+}
10
+export declare class ErrorResponse extends Response {
11
+    result: Outcome;
12
+    constructor(message?: string);
13
+}
14
+export declare class SubscriptionResponse extends SuccessResponse {
15
+    uid: string;
16
+    constructor(uid: string, message?: string);
17
+}

+ 30
- 0
lib/src/Response.js 查看文件

@@ -0,0 +1,30 @@
1
+"use strict";
2
+Object.defineProperty(exports, "__esModule", { value: true });
3
+/* Responses */
4
+class Response {
5
+    constructor(message) {
6
+        this.message = message;
7
+    }
8
+}
9
+exports.Response = Response;
10
+class SuccessResponse extends Response {
11
+    constructor(message) {
12
+        super(message);
13
+        this.result = "Success";
14
+    }
15
+}
16
+exports.SuccessResponse = SuccessResponse;
17
+class ErrorResponse extends Response {
18
+    constructor(message = "Unknown error") {
19
+        super(message);
20
+        this.result = "Error";
21
+    }
22
+}
23
+exports.ErrorResponse = ErrorResponse;
24
+class SubscriptionResponse extends SuccessResponse {
25
+    constructor(uid, message) {
26
+        super(message);
27
+        this.uid = uid;
28
+    }
29
+}
30
+exports.SubscriptionResponse = SubscriptionResponse;

+ 14
- 0
lib/src/Server.d.ts 查看文件

@@ -0,0 +1,14 @@
1
+import { SocketConf } from './Types';
2
+import { Exporter } from './interfaces/Exporter';
3
+import { Socket } from "./interfaces/Socket";
4
+export declare class Server {
5
+    private port;
6
+    private rpcExporters;
7
+    private conf;
8
+    private io;
9
+    private wsServer;
10
+    constructor(port: number, rpcExporters?: Exporter[], conf?: SocketConf);
11
+    private startWebsocket;
12
+    protected initRPCs(socket: Socket): void;
13
+    protected initPublicRPCs(socket: Socket): void;
14
+}

+ 58
- 0
lib/src/Server.js 查看文件

@@ -0,0 +1,58 @@
1
+"use strict";
2
+Object.defineProperty(exports, "__esModule", { value: true });
3
+const http = require("http");
4
+const bsock = require("bsock");
5
+const Util_1 = require("./Util");
6
+class Server {
7
+    constructor(port, rpcExporters = [], conf = {
8
+        errorHandler: (socket) => (error) => { socket.destroy(); console.error(error); },
9
+        closeHandler: (socket) => () => { console.log("Socket closing"); },
10
+        connectionHandler: (socket) => { console.log("New websocket connection in port " + socket.port); },
11
+        visibility: "127.0.0.1"
12
+    }) {
13
+        this.port = port;
14
+        this.rpcExporters = rpcExporters;
15
+        this.conf = conf;
16
+        this.io = bsock.createServer();
17
+        this.wsServer = http.createServer();
18
+        this.startWebsocket();
19
+    }
20
+    startWebsocket() {
21
+        try {
22
+            this.io.attach(this.wsServer);
23
+            this.io.on('socket', (socket) => {
24
+                socket.on('error', this.conf.errorHandler(socket));
25
+                socket.on('close', this.conf.closeHandler(socket));
26
+                if (this.conf.visibility === "127.0.0.1")
27
+                    this.initRPCs(socket);
28
+                else
29
+                    this.initPublicRPCs(socket);
30
+            });
31
+            this.wsServer.listen(this.port, this.conf.visibility);
32
+        }
33
+        catch (e) {
34
+            //@ts-ignore
35
+            this.errorHandler(undefined)("Unable to connect to socket");
36
+        }
37
+    }
38
+    initRPCs(socket) {
39
+        const infoRPC = [
40
+            {
41
+                name: 'info',
42
+                type: 'Call',
43
+                func: async () => rpcInfos
44
+            }
45
+        ];
46
+        const rpcInfos = [
47
+            ...Util_1.rpcHooker(socket, "RPC", infoRPC, false),
48
+            ...this.rpcExporters.flatMap(exporter => Util_1.rpcHooker(socket, exporter.name, [...exporter.exportPublicRPCs(), ...exporter.exportRPCs()]))
49
+        ];
50
+    }
51
+    initPublicRPCs(socket) {
52
+        const rpcInfos = [
53
+            ...Util_1.rpcHooker(socket, "Admin", adminRPCs, false),
54
+            ...this.rpcExporters.flatMap(exporter => Util_1.rpcHooker(socket, exporter.name, exporter.exportPublicRPCs()))
55
+        ];
56
+    }
57
+}
58
+exports.Server = Server;

+ 54
- 0
lib/src/Types.d.ts 查看文件

@@ -0,0 +1,54 @@
1
+import { SuccessResponse, ErrorResponse, SubscriptionResponse } from "./Response";
2
+import { Socket } from "./interfaces/Socket";
3
+export declare type Visibility = "127.0.0.1" | "0.0.0.0";
4
+export declare type Name = string;
5
+export declare type SocketConf = {
6
+    connectionHandler: (socket: Socket) => void;
7
+    errorHandler: (socket: Socket) => (error: any) => void;
8
+    closeHandler: (socket: Socket) => () => void;
9
+    visibility: Visibility;
10
+};
11
+export declare type rpcType = 'Hook' | 'Unhook' | 'Call';
12
+export declare type BaseRPC = {
13
+    type: rpcType;
14
+    name: string;
15
+};
16
+export declare type HookRPC = BaseRPC & {
17
+    type: 'Hook';
18
+    func: CallbackFunction;
19
+    unhook: UnhookFunction;
20
+};
21
+export declare type UnhookRPC = BaseRPC & {
22
+    type: 'Unhook';
23
+    func: UnhookFunction;
24
+};
25
+export declare type CallRPC = BaseRPC & {
26
+    type: 'Call';
27
+    func: (...args: any[]) => Promise<any>;
28
+};
29
+export declare type SocketioRPC = CallRPC | UnhookRPC | HookRPC;
30
+export declare type BaseInfo = {
31
+    owner: string;
32
+    argNames: string[];
33
+};
34
+export declare type HookInfo = BaseRPC & BaseInfo & {
35
+    type: 'Hook';
36
+    generator: (socket: any) => CallbackFunction;
37
+    unhook: UnhookFunction;
38
+};
39
+export declare type UnhookInfo = BaseRPC & BaseInfo & {
40
+    type: 'Unhook';
41
+    func: UnhookFunction;
42
+};
43
+export declare type CallInfo = BaseRPC & BaseInfo & {
44
+    type: 'Call';
45
+    func: AsyncFunction;
46
+};
47
+export declare type RpcInfo = HookInfo | UnhookInfo | CallInfo;
48
+export declare type ExtendedRpcInfo = RpcInfo & {
49
+    uniqueName: string;
50
+};
51
+export declare type OnFunction = (type: 'error' | 'close', f: (e?: any) => void) => Socket;
52
+export declare type UnhookFunction = (uid: string) => Promise<SuccessResponse | ErrorResponse>;
53
+export declare type CallbackFunction = (...args: any[]) => Promise<SubscriptionResponse | ErrorResponse>;
54
+export declare type AsyncFunction = (...args: any[]) => Promise<any>;

+ 2
- 0
lib/src/Types.js 查看文件

@@ -0,0 +1,2 @@
1
+"use strict";
2
+Object.defineProperty(exports, "__esModule", { value: true });

+ 4
- 0
lib/src/Util.d.ts 查看文件

@@ -0,0 +1,4 @@
1
+import { SocketioRPC, RpcInfo, ExtendedRpcInfo } from "./Types";
2
+import { Socket } from "./interfaces/Socket";
3
+export declare const rpcToRpcinfo: (rpc: SocketioRPC, owner: string) => RpcInfo;
4
+export declare const rpcHooker: (socket: Socket, owner: string, RPCs: SocketioRPC[], makeUnique?: boolean) => ExtendedRpcInfo[];

+ 75
- 0
lib/src/Util.js 查看文件

@@ -0,0 +1,75 @@
1
+"use strict";
2
+Object.defineProperty(exports, "__esModule", { value: true });
3
+const uuid = require("uuid/v4");
4
+exports.rpcToRpcinfo = (rpc, owner) => {
5
+    switch (rpc.type) {
6
+        case "Call":
7
+            return {
8
+                owner: owner,
9
+                argNames: extractArgs(rpc.func),
10
+                type: rpc.type,
11
+                name: rpc.name,
12
+                func: rpc.func,
13
+            };
14
+        case "Unhook":
15
+            return {
16
+                owner: owner,
17
+                argNames: extractArgs(rpc.func),
18
+                type: rpc.type,
19
+                name: rpc.name,
20
+                func: rpc.func,
21
+            };
22
+        case "Hook":
23
+            const generator = hookGenerator(rpc);
24
+            return {
25
+                owner: owner,
26
+                argNames: extractArgs(generator(undefined)),
27
+                type: rpc.type,
28
+                name: rpc.name,
29
+                unhook: rpc.unhook,
30
+                generator: generator,
31
+            };
32
+    }
33
+};
34
+exports.rpcHooker = (socket, owner, RPCs, makeUnique = true) => {
35
+    const suffix = makeUnique ? "-" + uuid().substr(0, 4) : "";
36
+    return RPCs.map(rpc => exports.rpcToRpcinfo(rpc, owner))
37
+        .map(info => {
38
+        const ret = info;
39
+        ret.uniqueName = info.name + suffix;
40
+        switch (info.type) {
41
+            case "Hook":
42
+                socket.hook(ret.uniqueName, info.generator(socket));
43
+                break;
44
+            default:
45
+                socket.hook(ret.uniqueName, info.func);
46
+        }
47
+        socket.on('close', () => socket.unhook(info.name));
48
+        return ret;
49
+    });
50
+};
51
+const hookGenerator = (rpc) => {
52
+    const argsArr = extractArgs(rpc.func);
53
+    argsArr.pop();
54
+    const args = argsArr.join(',');
55
+    return eval(`(socket) => async (` + args + `) => { 
56
+        const res = await rpc.func(` + args + (args.length !== 0 ? ',' : '') + ` (x) => {
57
+            socket.call(res.uid, x)
58
+        })
59
+        if(res.result == 'Success'){
60
+            socket.on('close', async () => {
61
+                const unhookRes = await rpc.unhook(res.uid)
62
+                console.log("Specific close handler for", rpc.name, res.uid, unhookRes)
63
+            })
64
+
65
+        }
66
+        return res
67
+    }`);
68
+};
69
+const extractArgs = (f) => {
70
+    let fn = String(f);
71
+    let args = fn.substr(0, fn.indexOf(")"));
72
+    args = args.substr(fn.indexOf("(") + 1);
73
+    let ret = args.split(",");
74
+    return ret;
75
+};

+ 0
- 98
lib/src/backend/RPCSocketServer.d.ts 查看文件

@@ -1,98 +0,0 @@
1
-import { Socket } from "./RPCSocketServer";
2
-declare type rpcType = 'hook' | 'unhook' | 'call';
3
-export declare type Outcome = "Success" | "Error";
4
-export declare type Visibility = "127.0.0.1" | "0.0.0.0";
5
-export declare class Response {
6
-    message?: string | undefined;
7
-    constructor(message?: string | undefined);
8
-}
9
-export declare class SuccessResponse extends Response {
10
-    result: Outcome;
11
-    constructor(message?: string);
12
-}
13
-export declare class ErrorResponse extends Response {
14
-    result: Outcome;
15
-    constructor(message?: string);
16
-}
17
-export declare class SubscriptionResponse extends SuccessResponse {
18
-    uid: string;
19
-    constructor(uid: string, message?: string);
20
-}
21
-export declare type UnhookFunction = (uid: string) => Promise<SuccessResponse | ErrorResponse>;
22
-export declare type callbackFunction = (...args: any[]) => Promise<SubscriptionResponse | ErrorResponse>;
23
-export declare type AsyncFunction = (...args: any[]) => Promise<any>;
24
-export interface RPCExporter {
25
-    name: string;
26
-    exportRPCs(): socketioRPC[];
27
-    exportPublicRPCs(): socketioRPC[];
28
-}
29
-declare type baseRPC = {
30
-    type: rpcType;
31
-    name: string;
32
-};
33
-declare type hookRPC = baseRPC & {
34
-    type: 'hook';
35
-    func: callbackFunction;
36
-    unhook: UnhookFunction;
37
-};
38
-declare type unhookRPC = baseRPC & {
39
-    type: 'unhook';
40
-    func: UnhookFunction;
41
-};
42
-declare type callRPC = baseRPC & {
43
-    type: 'call';
44
-    func: (...args: any[]) => Promise<any>;
45
-};
46
-export declare type socketioRPC = callRPC | unhookRPC | hookRPC;
47
-export declare type baseInfo = {
48
-    owner: string;
49
-    argNames: string[];
50
-};
51
-declare type HookInfo = baseRPC & baseInfo & {
52
-    type: 'hook';
53
-    generator: (socket: any) => callbackFunction;
54
-    unhook: UnhookFunction;
55
-};
56
-declare type UnhookInfo = baseRPC & baseInfo & {
57
-    type: 'unhook';
58
-    func: UnhookFunction;
59
-};
60
-declare type CallInfo = baseRPC & baseInfo & {
61
-    type: 'call';
62
-    func: AsyncFunction;
63
-};
64
-declare type RpcInfo = HookInfo | UnhookInfo | CallInfo;
65
-export declare type ExtendedRpcInfo = RpcInfo & {
66
-    uniqueName: string;
67
-};
68
-export declare const rpcToRpcinfo: (rpc: socketioRPC, owner: string) => RpcInfo;
69
-export declare const rpcHooker: (socket: Socket, owner: string, RPCs: socketioRPC[], makeUnique?: boolean) => ExtendedRpcInfo[];
70
-declare type OnFunction = (type: 'error' | 'close', f: (e?: any) => void) => Socket;
71
-export interface Socket {
72
-    port: number;
73
-    hook: (rpcname: string, ...args: any[]) => Socket;
74
-    unhook: (rpcname: string) => Socket;
75
-    call: (rpcname: string, ...args: any[]) => Promise<any>;
76
-    fire: (rpcname: string, ...args: any[]) => Promise<any>;
77
-    on: OnFunction;
78
-    destroy: () => void;
79
-    close: () => void;
80
-}
81
-export declare type RPCSocketConf = {
82
-    connectionHandler: (socket: Socket) => void;
83
-    errorHandler: (socket: Socket) => (error: any) => void;
84
-    closeHandler: (socket: Socket) => () => void;
85
-};
86
-export declare class RPCSocketServer {
87
-    private port;
88
-    private rpcExporters;
89
-    private visibility;
90
-    private conf;
91
-    private io;
92
-    private wsServer;
93
-    constructor(port: number, rpcExporters?: RPCExporter[], visibility?: Visibility, conf?: RPCSocketConf);
94
-    private startWebsocket;
95
-    protected initApis(socket: Socket): void;
96
-    protected initPublicApis(socket: Socket): void;
97
-}
98
-export {};

+ 0
- 165
lib/src/backend/RPCSocketServer.js 查看文件

@@ -1,165 +0,0 @@
1
-"use strict";
2
-Object.defineProperty(exports, "__esModule", { value: true });
3
-const http = require("http");
4
-const bsock = require("bsock");
5
-const uuid = require("uuid/v4");
6
-/* Responses */
7
-class Response {
8
-    constructor(message) {
9
-        this.message = message;
10
-    }
11
-}
12
-exports.Response = Response;
13
-class SuccessResponse extends Response {
14
-    constructor(message) {
15
-        super(message);
16
-        this.result = "Success";
17
-    }
18
-}
19
-exports.SuccessResponse = SuccessResponse;
20
-class ErrorResponse extends Response {
21
-    constructor(message = "Unknown error") {
22
-        super(message);
23
-        this.result = "Error";
24
-    }
25
-}
26
-exports.ErrorResponse = ErrorResponse;
27
-class SubscriptionResponse extends SuccessResponse {
28
-    constructor(uid, message) {
29
-        super(message);
30
-        this.uid = uid;
31
-    }
32
-}
33
-exports.SubscriptionResponse = SubscriptionResponse;
34
-exports.rpcToRpcinfo = (rpc, owner) => {
35
-    switch (rpc.type) {
36
-        case "call":
37
-            return {
38
-                owner: owner,
39
-                argNames: extractArgs(rpc.func),
40
-                type: rpc.type,
41
-                name: rpc.name,
42
-                func: rpc.func,
43
-            };
44
-        case "unhook":
45
-            return {
46
-                owner: owner,
47
-                argNames: extractArgs(rpc.func),
48
-                type: rpc.type,
49
-                name: rpc.name,
50
-                func: rpc.func,
51
-            };
52
-        case "hook":
53
-            const generator = hookGenerator(rpc);
54
-            return {
55
-                owner: owner,
56
-                argNames: extractArgs(generator(undefined)),
57
-                type: rpc.type,
58
-                name: rpc.name,
59
-                unhook: rpc.unhook,
60
-                generator: generator,
61
-            };
62
-    }
63
-};
64
-exports.rpcHooker = (socket, owner, RPCs, makeUnique = true) => {
65
-    const suffix = makeUnique ? "-" + uuid().substr(0, 4) : "";
66
-    return RPCs.map(rpc => exports.rpcToRpcinfo(rpc, owner))
67
-        .map(info => {
68
-        const ret = info;
69
-        ret.uniqueName = info.name + suffix;
70
-        switch (info.type) {
71
-            case "hook":
72
-                socket.hook(ret.uniqueName, info.generator(socket));
73
-                break;
74
-            default:
75
-                socket.hook(ret.uniqueName, info.func);
76
-        }
77
-        socket.on('close', () => socket.unhook(info.name));
78
-        return ret;
79
-    });
80
-};
81
-const hookGenerator = (rpc) => {
82
-    const argsArr = extractArgs(rpc.func);
83
-    argsArr.pop();
84
-    const args = argsArr.join(',');
85
-    return eval(`(socket) => async (` + args + `) => { 
86
-        const res = await rpc.func(` + args + (args.length !== 0 ? ',' : '') + ` (x) => {
87
-            socket.call(res.uid, x)
88
-        })
89
-        if(res.result == 'Success'){
90
-            socket.on('close', async () => {
91
-                const unhookRes = await rpc.unhook(res.uid)
92
-                console.log("Specific close handler for", rpc.name, res.uid, unhookRes)
93
-            })
94
-
95
-        }
96
-        return res
97
-    }`);
98
-};
99
-const extractArgs = (f) => {
100
-    let fn = String(f);
101
-    let args = fn.substr(0, fn.indexOf(")"));
102
-    args = args.substr(fn.indexOf("(") + 1);
103
-    let ret = args.split(",");
104
-    return ret;
105
-};
106
-class RPCSocketServer {
107
-    constructor(port, rpcExporters = [], visibility = "127.0.0.1", conf = {
108
-        errorHandler: (socket) => (error) => { socket.destroy(); console.error(error); },
109
-        closeHandler: (socket) => () => { console.log("Socket closing"); },
110
-        connectionHandler: (socket) => { console.log("New websocket connection in port " + socket.port); }
111
-    }) {
112
-        this.port = port;
113
-        this.rpcExporters = rpcExporters;
114
-        this.visibility = visibility;
115
-        this.conf = conf;
116
-        this.io = bsock.createServer();
117
-        this.wsServer = http.createServer();
118
-        this.startWebsocket();
119
-    }
120
-    startWebsocket() {
121
-        try {
122
-            this.io.attach(this.wsServer);
123
-            this.io.on('socket', (socket) => {
124
-                socket.on('error', this.conf.errorHandler(socket));
125
-                socket.on('close', this.conf.closeHandler(socket));
126
-                if (this.visibility === "127.0.0.1")
127
-                    this.initApis(socket);
128
-                else
129
-                    this.initPublicApis(socket);
130
-            });
131
-            this.wsServer.listen(this.port, this.visibility);
132
-        }
133
-        catch (e) {
134
-            //@ts-ignore
135
-            this.errorHandler(undefined)("Unable to connect to socket");
136
-        }
137
-    }
138
-    initApis(socket) {
139
-        const adminRPCs = [
140
-            {
141
-                name: 'info',
142
-                type: 'call',
143
-                func: async () => rpcInfos
144
-            }
145
-        ];
146
-        const rpcInfos = [
147
-            ...exports.rpcHooker(socket, "Admin", adminRPCs, false),
148
-            ...this.rpcExporters.flatMap(exporter => exports.rpcHooker(socket, exporter.name, [...exporter.exportPublicRPCs(), ...exporter.exportRPCs()]))
149
-        ];
150
-    }
151
-    initPublicApis(socket) {
152
-        const adminRPCs = [
153
-            {
154
-                name: 'info',
155
-                type: 'call',
156
-                func: async () => rpcInfos
157
-            }
158
-        ];
159
-        const rpcInfos = [
160
-            ...exports.rpcHooker(socket, "Admin", adminRPCs, false),
161
-            ...this.rpcExporters.flatMap(exporter => exports.rpcHooker(socket, exporter.name, exporter.exportPublicRPCs()))
162
-        ];
163
-    }
164
-}
165
-exports.RPCSocketServer = RPCSocketServer;

+ 6
- 0
lib/src/interfaces/Exporter.d.ts 查看文件

@@ -0,0 +1,6 @@
1
+import { SocketioRPC, Name } from "../Types";
2
+export interface Exporter {
3
+    name: Name;
4
+    exportRPCs(): SocketioRPC[];
5
+    exportPublicRPCs(): SocketioRPC[];
6
+}

+ 2
- 0
lib/src/interfaces/Exporter.js 查看文件

@@ -0,0 +1,2 @@
1
+"use strict";
2
+Object.defineProperty(exports, "__esModule", { value: true });

+ 11
- 0
lib/src/interfaces/Socket.d.ts 查看文件

@@ -0,0 +1,11 @@
1
+import { OnFunction } from "../Types";
2
+export interface Socket {
3
+    port: number;
4
+    hook: (rpcname: string, ...args: any[]) => Socket;
5
+    unhook: (rpcname: string) => Socket;
6
+    call: (rpcname: string, ...args: any[]) => Promise<any>;
7
+    fire: (rpcname: string, ...args: any[]) => Promise<any>;
8
+    on: OnFunction;
9
+    destroy: () => void;
10
+    close: () => void;
11
+}

+ 2
- 0
lib/src/interfaces/Socket.js 查看文件

@@ -0,0 +1,2 @@
1
+"use strict";
2
+Object.defineProperty(exports, "__esModule", { value: true });

+ 5
- 5
lib/test/test.js 查看文件

@@ -1,9 +1,9 @@
1 1
 "use strict";
2 2
 Object.defineProperty(exports, "__esModule", { value: true });
3
-const RPCSocketServer_1 = require("../src/backend/RPCSocketServer");
3
+const Server_1 = require("../src/Server");
4 4
 //@ts-ignore
5
-const RPCSocket_1 = require("../src/frontend/RPCSocket");
6
-new RPCSocketServer_1.RPCSocketServer(20000, [{
5
+const Client_1 = require("../src/Client");
6
+new Server_1.Server(20000, [{
7 7
         name: "HelloWorldRPCGroup",
8 8
         exportPublicRPCs: () => [],
9 9
         exportRPCs: () => [{
@@ -11,8 +11,8 @@ new RPCSocketServer_1.RPCSocketServer(20000, [{
11 11
                 name: 'echo',
12 12
                 func: async (s) => s,
13 13
             }],
14
-    }], "0.0.0.0");
15
-const caller = new RPCSocket_1.RPCSocket(20000, 'localhost');
14
+    }]);
15
+const caller = new Client_1.Client(20000, 'localhost');
16 16
 caller.connect().then(_ => {
17 17
     caller.info().then(console.log);
18 18
     caller["HelloWorldRPCGroup"].echo("x").then(console.log);

+ 1
- 1
package.json 查看文件

@@ -5,7 +5,7 @@
5 5
   "scripts": {
6 6
     "build": "npm run clean; npm run tsc; npm run webpack",
7 7
     "tsc": "tsc",
8
-    "webpack": "webpack  --config src/frontend/webpack.prod.js --progress --colors",
8
+    "webpack": "webpack  --config src/webpack.prod.js --progress --colors",
9 9
     "clean": "rm -rf lib"
10 10
   },
11 11
   "author": "",

src/frontend/RPCSocket.ts → src/Client.ts 查看文件

@@ -1,20 +1,14 @@
1
-import { ExtendedRpcInfo, UnhookFunction, callbackFunction, AsyncFunction, Socket } from "../backend/RPCSocketServer";
2 1
 var bsock = require('bsock')
3 2
 
3
+import { ExtendedRpcInfo, UnhookFunction, CallbackFunction, AsyncFunction } from "./Types";
4
+import { Socket } from './interfaces/Socket'
5
+
4 6
 //fix args with defaults like "force = true" -> "force"
5 7
 function stripAfterEquals(str:string){
6 8
     return str.split("=")[0]
7 9
 }
8 10
 
9
-
10
-/**
11
- * Dynamic library to communicate with FrontblockService remotely
12
- *
13
- * This will be automatically injected into the webpages served by FrontblockService
14
- * Will ask it's service for available RPCs and parse them into methods of this object
15
- * for convenient access.
16
- */
17
-export class RPCSocket implements Socket{
11
+export class Client implements Socket{
18 12
     private socket: Socket
19 13
     constructor(public port:number, private server: string, private tls: boolean = false){
20 14
     }
@@ -54,13 +48,13 @@ export class RPCSocket implements Socket{
54 48
         info.forEach(i => {
55 49
             let f: any
56 50
             switch (i.type) {
57
-                case 'call':
51
+                case 'Call':
58 52
                     f = this.callGenerator(i.uniqueName, i.argNames)    
59 53
                     break                
60
-                case 'hook':
54
+                case 'Hook':
61 55
                     f = this.hookGenerator(i.uniqueName, i.argNames)                    
62 56
                     break
63
-                case 'unhook':
57
+                case 'Unhook':
64 58
                     f = this.unhookGenerator(i.uniqueName, i.argNames)                    
65 59
                     break
66 60
             }
@@ -81,7 +75,7 @@ export class RPCSocket implements Socket{
81 75
         return eval( '( () => async ('+headerArgs+') => { return await this.socket.call("'+fnName+'", '+argParams+')} )()' )
82 76
     }
83 77
 
84
-    private hookGenerator(fnName, fnArgs:string[]): callbackFunction{
78
+    private hookGenerator(fnName, fnArgs:string[]): CallbackFunction{
85 79
         const headerArgs = fnArgs.join(",")
86 80
         const argParams = fnArgs.map(stripAfterEquals).join(",")
87 81
         return eval( `( () => async (`+headerArgs+(headerArgs.length!==0?",":"")+` callback) => {

+ 38
- 0
src/Response.ts 查看文件

@@ -0,0 +1,38 @@
1
+
2
+export type Outcome = "Success" | "Error"
3
+
4
+/* Responses */
5
+export class Response{
6
+    constructor(
7
+        public message?:string
8
+    ){}
9
+}
10
+
11
+export class SuccessResponse extends Response{
12
+    result:Outcome = "Success"
13
+
14
+    constructor(
15
+        message?:string
16
+    ){
17
+        super(message)
18
+    }
19
+}
20
+
21
+export class ErrorResponse extends Response{
22
+    result:Outcome = "Error"
23
+
24
+    constructor(
25
+        message: string = "Unknown error"
26
+    ){
27
+        super(message)
28
+    } 
29
+}
30
+
31
+export class SubscriptionResponse extends SuccessResponse{
32
+    constructor(
33
+        public uid: string,
34
+        message?:string
35
+    ){
36
+        super(message)
37
+    }
38
+}

+ 60
- 0
src/Server.ts 查看文件

@@ -0,0 +1,60 @@
1
+import http = require('http');
2
+import bsock = require('bsock');
3
+
4
+import { ExtendedRpcInfo, SocketConf, SocketioRPC } from './Types';
5
+import { rpcHooker } from './Util';
6
+import { Exporter } from './interfaces/Exporter';
7
+import { Socket } from "./interfaces/Socket";
8
+
9
+export class Server{
10
+    
11
+    private io = bsock.createServer()
12
+    private wsServer = http.createServer()
13
+
14
+    constructor(
15
+        private port:number,
16
+        private rpcExporters: Exporter[] = [],
17
+        private conf: SocketConf = {
18
+            errorHandler: (socket:Socket) => (error:any) => { socket.destroy(); console.error(error) },
19
+            closeHandler: (socket:Socket) => () => { console.log("Socket closing") },
20
+            connectionHandler: (socket:Socket) => { console.log("New websocket connection in port "+socket.port)},
21
+            visibility: "127.0.0.1"
22
+        }
23
+    ){
24
+        this.startWebsocket()
25
+    }
26
+
27
+    private startWebsocket(){
28
+        try{
29
+            this.io.attach(this.wsServer)
30
+            this.io.on('socket', (socket:Socket) => {
31
+                socket.on('error', this.conf.errorHandler(socket))
32
+                socket.on('close', this.conf.closeHandler(socket))
33
+                if(this.conf.visibility === "127.0.0.1")
34
+                    this.initRPCs(socket)
35
+                else
36
+                    this.initPublicRPCs(socket)
37
+            })
38
+            this.wsServer.listen(this.port, this.conf.visibility)
39
+        }catch(e){
40
+            //@ts-ignore
41
+            this.errorHandler(undefined)("Unable to connect to socket")
42
+        }
43
+    }
44
+
45
+    protected initRPCs(socket:Socket){
46
+        const infoRPC:SocketioRPC[] = [
47
+            {
48
+                name: 'info',
49
+                type: 'Call',
50
+                func: async () => rpcInfos
51
+            }
52
+        ]
53
+        const rpcInfos:ExtendedRpcInfo[] = [
54
+            ...rpcHooker(socket, "RPC", infoRPC, false),
55
+            ...this.rpcExporters.flatMap(exporter => rpcHooker(socket, exporter.name, [...exporter.exportPublicRPCs(), ...exporter.exportRPCs()]))
56
+        ]
57
+    }
58
+
59
+    protected initPublicRPCs(socket:Socket){}
60
+}

+ 66
- 0
src/Types.ts 查看文件

@@ -0,0 +1,66 @@
1
+import { SuccessResponse, ErrorResponse, SubscriptionResponse } from "./Response";
2
+import { Socket } from "./interfaces/Socket";
3
+
4
+export type Visibility = "127.0.0.1" | "0.0.0.0"
5
+export type Name = string
6
+
7
+export type SocketConf = {
8
+    connectionHandler: (socket:Socket) => void
9
+    errorHandler: (socket:Socket) => (error:any) => void
10
+    closeHandler: (socket:Socket) => () =>  void
11
+    visibility: Visibility
12
+}
13
+
14
+export type rpcType = 'Hook' | 'Unhook' | 'Call'
15
+
16
+export type BaseRPC = { 
17
+    type: rpcType
18
+    name: string
19
+}
20
+
21
+export type HookRPC = BaseRPC & {
22
+    type: 'Hook'
23
+    func: CallbackFunction
24
+    unhook: UnhookFunction
25
+}
26
+
27
+export type UnhookRPC = BaseRPC & {
28
+    type: 'Unhook'
29
+    func: UnhookFunction
30
+}
31
+
32
+export type CallRPC = BaseRPC & {
33
+    type: 'Call'
34
+    func: (...args) => Promise<any>
35
+}
36
+
37
+export type SocketioRPC = CallRPC | UnhookRPC | HookRPC
38
+
39
+export type BaseInfo = {
40
+    owner: string,
41
+    argNames: string[],
42
+}
43
+
44
+export type HookInfo = BaseRPC & BaseInfo & { 
45
+    type: 'Hook', 
46
+    generator: (socket) => CallbackFunction
47
+    unhook: UnhookFunction
48
+}
49
+
50
+export type UnhookInfo = BaseRPC & BaseInfo & {
51
+    type: 'Unhook',
52
+    func: UnhookFunction
53
+}
54
+
55
+export type CallInfo = BaseRPC & BaseInfo & {
56
+    type: 'Call',
57
+    func: AsyncFunction
58
+}
59
+
60
+export type RpcInfo = HookInfo | UnhookInfo | CallInfo
61
+export type ExtendedRpcInfo = RpcInfo & { uniqueName: string } 
62
+
63
+export type OnFunction = (type: 'error' | 'close', f: (e?:any)=>void) => Socket
64
+export type UnhookFunction = (uid:string) => Promise<SuccessResponse | ErrorResponse>
65
+export type CallbackFunction = (...args) => Promise<SubscriptionResponse | ErrorResponse>
66
+export type AsyncFunction = (...args) => Promise<any>

+ 82
- 0
src/Util.ts 查看文件

@@ -0,0 +1,82 @@
1
+import * as uuid from "uuid/v4"
2
+
3
+import { HookRPC, HookInfo, SocketioRPC, RpcInfo, ExtendedRpcInfo } from "./Types";
4
+import { Socket } from "./interfaces/Socket";
5
+
6
+export const rpcToRpcinfo = (rpc : SocketioRPC, owner: string):RpcInfo => {
7
+    switch(rpc.type){
8
+        case "Call" :
9
+            return {
10
+                owner: owner,
11
+                argNames: extractArgs(rpc.func),
12
+                type: rpc.type,
13
+                name: rpc.name,
14
+                func: rpc.func,
15
+            }
16
+        case "Unhook" :
17
+            return {
18
+                owner: owner,
19
+                argNames: extractArgs(rpc.func),
20
+                type: rpc.type,
21
+                name: rpc.name,
22
+                func: rpc.func,
23
+            }
24
+        case "Hook" :
25
+            const generator = hookGenerator(rpc)
26
+            return {
27
+                owner: owner,
28
+                argNames: extractArgs(generator(undefined)),
29
+                type: rpc.type,
30
+                name: rpc.name,
31
+                unhook: rpc.unhook,
32
+                generator: generator,
33
+            }
34
+    }
35
+}
36
+
37
+export const rpcHooker = (socket: Socket, owner:string, RPCs: SocketioRPC[], makeUnique = true):ExtendedRpcInfo[] => {
38
+    const suffix = makeUnique?"-"+uuid().substr(0,4):""
39
+    return RPCs.map(rpc => rpcToRpcinfo(rpc, owner))
40
+    .map(info => {
41
+        const ret:any = info
42
+        ret.uniqueName = info.name+suffix
43
+
44
+        switch(info.type){
45
+            case "Hook":
46
+                socket.hook(ret.uniqueName, info.generator(socket))
47
+                break;
48
+            default:
49
+                socket.hook(ret.uniqueName, info.func)
50
+        }
51
+        socket.on('close', () => socket.unhook(info.name))
52
+        return ret
53
+    })
54
+}
55
+
56
+const hookGenerator = (rpc:HookRPC): HookInfo['generator'] => { 
57
+    const argsArr = extractArgs(rpc.func)
58
+    argsArr.pop()
59
+    const args = argsArr.join(',')
60
+
61
+    return eval(`(socket) => async (`+args+`) => { 
62
+        const res = await rpc.func(`+args+(args.length!==0?',':'')+` (x) => {
63
+            socket.call(res.uid, x)
64
+        })
65
+        if(res.result == 'Success'){
66
+            socket.on('close', async () => {
67
+                const unhookRes = await rpc.unhook(res.uid)
68
+                console.log("Specific close handler for", rpc.name, res.uid, unhookRes)
69
+            })
70
+
71
+        }
72
+        return res
73
+    }`)
74
+}
75
+
76
+const extractArgs = (f:Function):string[] => {
77
+    let fn = String(f)
78
+    let args = fn.substr(0, fn.indexOf(")"))
79
+    args = args.substr(fn.indexOf("(")+1)
80
+    let ret = args.split(",")
81
+    return ret
82
+}

+ 0
- 267
src/backend/RPCSocketServer.ts 查看文件

@@ -1,267 +0,0 @@
1
-import http = require('http');
2
-import bsock = require('bsock');
3
-
4
-import * as uuid from "uuid/v4"
5
-import { Socket } from "./RPCSocketServer"
6
-
7
-type rpcType = 'hook' | 'unhook' | 'call'
8
-export type Outcome = "Success" | "Error"
9
-export type Visibility = "127.0.0.1" | "0.0.0.0"
10
-
11
-/* Responses */
12
-export class Response{
13
-    constructor(
14
-        public message?:string
15
-    ){}
16
-}
17
-
18
-export class SuccessResponse extends Response{
19
-    result:Outcome = "Success"
20
-
21
-    constructor(
22
-        message?:string
23
-    ){
24
-        super(message)
25
-    }
26
-}
27
-
28
-export class ErrorResponse extends Response{
29
-    result:Outcome = "Error"
30
-
31
-    constructor(
32
-        message: string = "Unknown error"
33
-    ){
34
-        super(message)
35
-    } 
36
-}
37
-
38
-export class SubscriptionResponse extends SuccessResponse{
39
-    constructor(
40
-        public uid: string,
41
-        message?:string
42
-    ){
43
-        super(message)
44
-    }
45
-}
46
-export type UnhookFunction = (uid:string) => Promise<SuccessResponse | ErrorResponse>
47
-export type callbackFunction = (...args) => Promise<SubscriptionResponse | ErrorResponse>
48
-export type AsyncFunction = (...args) => Promise<any>
49
-
50
-export interface RPCExporter{
51
-    name: string
52
-    exportRPCs() : socketioRPC[]
53
-    exportPublicRPCs() : socketioRPC[]
54
-}
55
-
56
-type baseRPC = { 
57
-    type: rpcType
58
-    name: string
59
-}
60
-
61
-type hookRPC = baseRPC & {
62
-    type: 'hook'
63
-    func: callbackFunction
64
-    unhook: UnhookFunction
65
-}
66
-
67
-type unhookRPC = baseRPC & {
68
-    type: 'unhook'
69
-    func: UnhookFunction
70
-}
71
-
72
-type callRPC = baseRPC & {
73
-    type: 'call'
74
-    func: (...args) => Promise<any>
75
-}
76
-
77
-export type socketioRPC = callRPC | unhookRPC | hookRPC
78
-
79
-export type baseInfo = {
80
-    owner: string,
81
-    argNames: string[],
82
-}
83
-
84
-type HookInfo = baseRPC & baseInfo & { 
85
-    type: 'hook', 
86
-    generator: (socket) => callbackFunction
87
-    unhook: UnhookFunction
88
-}
89
-
90
-type UnhookInfo = baseRPC & baseInfo & {
91
-    type: 'unhook',
92
-    func: UnhookFunction
93
-}
94
-
95
-type CallInfo = baseRPC & baseInfo & {
96
-    type: 'call',
97
-    func: AsyncFunction
98
-}
99
-
100
-type RpcInfo = HookInfo | UnhookInfo | CallInfo
101
-
102
-export type ExtendedRpcInfo = RpcInfo & { uniqueName: string } 
103
-
104
-export const rpcToRpcinfo = (rpc : socketioRPC, owner: string):RpcInfo => {
105
-    switch(rpc.type){
106
-        case "call" :
107
-            return {
108
-                owner: owner,
109
-                argNames: extractArgs(rpc.func),
110
-                type: rpc.type,
111
-                name: rpc.name,
112
-                func: rpc.func,
113
-            }
114
-        case "unhook" :
115
-            return {
116
-                owner: owner,
117
-                argNames: extractArgs(rpc.func),
118
-                type: rpc.type,
119
-                name: rpc.name,
120
-                func: rpc.func,
121
-            }
122
-        case "hook" :
123
-            const generator = hookGenerator(rpc)
124
-            return {
125
-                owner: owner,
126
-                argNames: extractArgs(generator(undefined)),
127
-                type: rpc.type,
128
-                name: rpc.name,
129
-                unhook: rpc.unhook,
130
-                generator: generator,
131
-            }
132
-    }
133
-}
134
-
135
-export const rpcHooker = (socket: Socket, owner:string, RPCs: socketioRPC[], makeUnique = true):ExtendedRpcInfo[] => {
136
-    const suffix = makeUnique?"-"+uuid().substr(0,4):""
137
-    return RPCs.map(rpc => rpcToRpcinfo(rpc, owner))
138
-    .map(info => {
139
-        const ret:any = info
140
-        ret.uniqueName = info.name+suffix
141
-
142
-        switch(info.type){
143
-            case "hook":
144
-                socket.hook(ret.uniqueName, info.generator(socket))
145
-                break;
146
-            default:
147
-                socket.hook(ret.uniqueName, info.func)
148
-        }
149
-        socket.on('close', () => socket.unhook(info.name))
150
-        return ret
151
-    })
152
-}
153
-
154
-const hookGenerator = (rpc:hookRPC): HookInfo['generator'] => { 
155
-    const argsArr = extractArgs(rpc.func)
156
-    argsArr.pop()
157
-    const args = argsArr.join(',')
158
-
159
-    return eval(`(socket) => async (`+args+`) => { 
160
-        const res = await rpc.func(`+args+(args.length!==0?',':'')+` (x) => {
161
-            socket.call(res.uid, x)
162
-        })
163
-        if(res.result == 'Success'){
164
-            socket.on('close', async () => {
165
-                const unhookRes = await rpc.unhook(res.uid)
166
-                console.log("Specific close handler for", rpc.name, res.uid, unhookRes)
167
-            })
168
-
169
-        }
170
-        return res
171
-    }`)
172
-}
173
-
174
-const extractArgs = (f:Function):string[] => {
175
-    let fn = String(f)
176
-    let args = fn.substr(0, fn.indexOf(")"))
177
-    args = args.substr(fn.indexOf("(")+1)
178
-    let ret = args.split(",")
179
-    return ret
180
-}
181
-
182
-
183
-type OnFunction = (type: 'error' | 'close', f: (e?:any)=>void) => Socket
184
-
185
-export interface Socket {
186
-    port: number
187
-    hook: (rpcname: string, ...args: any[]) => Socket
188
-    unhook: (rpcname:string) => Socket
189
-    call: (rpcname:string, ...args: any[]) => Promise<any>
190
-    fire: (rpcname:string, ...args: any[]) => Promise<any>
191
-    on: OnFunction
192
-    destroy: ()=>void
193
-    close: ()=>void
194
-}
195
-
196
-export type RPCSocketConf = {
197
-    connectionHandler: (socket:Socket) => void
198
-    errorHandler: (socket:Socket) => (error:any) => void
199
-    closeHandler: (socket:Socket) => () =>  void
200
-}
201
-
202
-export class RPCSocketServer{
203
-    
204
-    private io = bsock.createServer()
205
-    private wsServer = http.createServer()
206
-
207
-    constructor(
208
-        private port:number,
209
-        private rpcExporters: RPCExporter[] = [],
210
-        private visibility: Visibility = "127.0.0.1",
211
-        private conf: RPCSocketConf = {
212
-            errorHandler: (socket:Socket) => (error:any) => { socket.destroy(); console.error(error) },
213
-            closeHandler: (socket:Socket) => () => { console.log("Socket closing") },
214
-            connectionHandler: (socket:Socket) => { console.log("New websocket connection in port "+socket.port) }
215
-        }
216
-    ){
217
-        this.startWebsocket()
218
-    }
219
-
220
-    private startWebsocket(){
221
-        try{
222
-            this.io.attach(this.wsServer)
223
-            this.io.on('socket', (socket:Socket) => {
224
-                socket.on('error', this.conf.errorHandler(socket))
225
-                socket.on('close', this.conf.closeHandler(socket))
226
-                if(this.visibility === "127.0.0.1")
227
-                    this.initRPCs(socket)
228
-                else
229
-                    this.initPublicRPCs(socket)
230
-            })
231
-            this.wsServer.listen(this.port, this.visibility)
232
-        }catch(e){
233
-            //@ts-ignore
234
-            this.errorHandler(undefined)("Unable to connect to socket")
235
-        }
236
-    }
237
-
238
-    protected initRPCs(socket:Socket){
239
-        const infoRPC:socketioRPC[] = [
240
-            {
241
-                name: 'info',
242
-                type: 'call',
243
-                func: async () => rpcInfos
244
-            }
245
-        ]
246
-
247
-        const rpcInfos:ExtendedRpcInfo[] = [
248
-            ...rpcHooker(socket, "RPC", infoRPC, false),
249
-            ...this.rpcExporters.flatMap(exporter => rpcHooker(socket, exporter.name, [...exporter.exportPublicRPCs(), ...exporter.exportRPCs()]))
250
-        ]
251
-    }
252
-
253
-    protected initPublicRPCs(socket:Socket){
254
-        const adminRPCs:socketioRPC[] = [
255
-            {
256
-                name: 'info',
257
-                type: 'call',
258
-                func: async () => rpcInfos
259
-            }
260
-        ]
261
-
262
-        const rpcInfos:ExtendedRpcInfo[] = [
263
-            ...rpcHooker(socket, "Admin", adminRPCs, false),
264
-            ...this.rpcExporters.flatMap(exporter => rpcHooker(socket, exporter.name, exporter.exportPublicRPCs()))
265
-        ]
266
-    }
267
-}

+ 7
- 0
src/interfaces/Exporter.ts 查看文件

@@ -0,0 +1,7 @@
1
+import { SocketioRPC, Name } from "../Types";
2
+
3
+export interface Exporter{
4
+    name: Name
5
+    exportRPCs() : SocketioRPC[]
6
+    exportPublicRPCs() : SocketioRPC[]
7
+}

+ 12
- 0
src/interfaces/Socket.ts 查看文件

@@ -0,0 +1,12 @@
1
+import { OnFunction } from "../Types";
2
+
3
+export interface Socket {
4
+    port: number
5
+    hook: (rpcname: string, ...args: any[]) => Socket
6
+    unhook: (rpcname:string) => Socket
7
+    call: (rpcname:string, ...args: any[]) => Promise<any>
8
+    fire: (rpcname:string, ...args: any[]) => Promise<any>
9
+    on: OnFunction
10
+    destroy: ()=>void
11
+    close: ()=>void
12
+}

src/frontend/webpack.prod.js → src/webpack.prod.js 查看文件

@@ -4,10 +4,10 @@ const TerserPlugin = require('terser-webpack-plugin');
4 4
 module.exports = {
5 5
   mode: 'production',
6 6
   target: "web",
7
-  entry: path.resolve(__dirname, 'RPCSocket.ts'),
7
+  entry: path.resolve(__dirname, 'Client.ts'),
8 8
   output: {
9 9
       path: path.resolve(__dirname, '../../lib'),
10
-      filename: 'RPCaller.min.js',
10
+      filename: 'Frontend.min.js',
11 11
       libraryTarget: 'commonjs',
12 12
   },
13 13
   resolve: {

+ 4
- 4
test/test.ts 查看文件

@@ -1,8 +1,8 @@
1
-import { RPCSocketServer } from '../src/backend/RPCSocketServer'
1
+import { Server } from '../src/Server'
2 2
 //@ts-ignore
3
-import {RPCSocket} from '../src/frontend/RPCSocket'
3
+import {Client} from '../src/Client'
4 4
 
5
-new RPCSocketServer(20000, [{
5
+new Server(20000, [{
6 6
     name: "HelloWorldRPCGroup",
7 7
     exportPublicRPCs: () => [],
8 8
     exportRPCs: () => [{
@@ -12,7 +12,7 @@ new RPCSocketServer(20000, [{
12 12
     }],
13 13
 }])
14 14
 
15
-const caller = new RPCSocket(20000, 'localhost')
15
+const caller = new Client(20000, 'localhost')
16 16
 caller.connect().then(_ => {
17 17
     caller.info().then(console.log)
18 18
     caller["HelloWorldRPCGroup"].echo("x").then(console.log)

Loading…
取消
儲存