This commit is contained in:
Daniel Hübleitner
2019-09-18 01:19:33 +02:00
parent 41a5d14fd8
commit 34ec2d0244
3 changed files with 9 additions and 7 deletions
+3 -1
View File
@@ -2,6 +2,7 @@ import { Socket } from "./RPCSocketServer";
declare type rpcType = 'hook' | 'unhook' | 'call';
declare type visibility = 'public' | 'private';
export declare type Outcome = "Success" | "Error";
export declare type Visibility = "127.0.0.1" | "0.0.0.0";
export declare class Response {
message?: string | undefined;
constructor(message?: string | undefined);
@@ -86,10 +87,11 @@ export declare type RPCSocketConf = {
export declare class RPCSocketServer {
private port;
private rpcExporters;
private visibility;
private conf;
private io;
private wsServer;
constructor(port: number, rpcExporters?: RPCExporter[], conf?: RPCSocketConf);
constructor(port: number, rpcExporters?: RPCExporter[], visibility?: Visibility, conf?: RPCSocketConf);
private startWebsocket;
protected initApis(socket: any): void;
}
+3 -2
View File
@@ -107,13 +107,14 @@ const extractArgs = (f) => {
return ret;
};
class RPCSocketServer {
constructor(port, rpcExporters = [], conf = {
constructor(port, rpcExporters = [], visibility = "127.0.0.1", conf = {
errorHandler: (socket) => (error) => { socket.destroy(); console.error(error); },
closeHandler: (socket) => () => { console.log("Socket closing"); },
connectionHandler: (socket) => { console.log("New websocket connection in port " + socket.port); }
}) {
this.port = port;
this.rpcExporters = rpcExporters;
this.visibility = visibility;
this.conf = conf;
this.io = bsock.createServer();
this.wsServer = http.createServer();
@@ -127,7 +128,7 @@ class RPCSocketServer {
socket.on('close', this.conf.closeHandler(socket));
this.initApis(socket);
});
this.wsServer.listen(this.port);
this.wsServer.listen(this.port, this.visibility);
}
catch (e) {
//@ts-ignore