stuff
This commit is contained in:
Vendored
+3
-1
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -5,9 +5,8 @@ import * as uuid from "uuid/v4"
|
||||
import { Socket } from "./RPCSocketServer"
|
||||
|
||||
type rpcType = 'hook' | 'unhook' | 'call'
|
||||
type visibility = 'public' | 'private'
|
||||
|
||||
export type Outcome = "Success" | "Error"
|
||||
export type Visibility = "127.0.0.1" | "0.0.0.0"
|
||||
|
||||
/* Responses */
|
||||
export class Response{
|
||||
@@ -56,7 +55,6 @@ export interface RPCExporter{
|
||||
type baseRPC = {
|
||||
type: rpcType
|
||||
name: string
|
||||
visibility: visibility
|
||||
}
|
||||
|
||||
type hookRPC = baseRPC & {
|
||||
@@ -211,6 +209,7 @@ export class RPCSocketServer{
|
||||
constructor(
|
||||
private port:number,
|
||||
private rpcExporters: RPCExporter[] = [],
|
||||
private visibility: Visibility = "127.0.0.1",
|
||||
private conf: RPCSocketConf = {
|
||||
errorHandler: (socket:Socket) => (error:any) => { socket.destroy(); console.error(error) },
|
||||
closeHandler: (socket:Socket) => () => { console.log("Socket closing") },
|
||||
@@ -228,7 +227,7 @@ export 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
|
||||
this.errorHandler(undefined)("Unable to connect to socket")
|
||||
|
||||
Reference in New Issue
Block a user