Browse Source

stuff

master
Daniel Hübleitner 5 years ago
parent
commit
34ec2d0244

+ 3
- 1
lib/src/backend/RPCSocketServer.d.ts View File

2
 declare type rpcType = 'hook' | 'unhook' | 'call';
2
 declare type rpcType = 'hook' | 'unhook' | 'call';
3
 declare type visibility = 'public' | 'private';
3
 declare type visibility = 'public' | 'private';
4
 export declare type Outcome = "Success" | "Error";
4
 export declare type Outcome = "Success" | "Error";
5
+export declare type Visibility = "127.0.0.1" | "0.0.0.0";
5
 export declare class Response {
6
 export declare class Response {
6
     message?: string | undefined;
7
     message?: string | undefined;
7
     constructor(message?: string | undefined);
8
     constructor(message?: string | undefined);
86
 export declare class RPCSocketServer {
87
 export declare class RPCSocketServer {
87
     private port;
88
     private port;
88
     private rpcExporters;
89
     private rpcExporters;
90
+    private visibility;
89
     private conf;
91
     private conf;
90
     private io;
92
     private io;
91
     private wsServer;
93
     private wsServer;
92
-    constructor(port: number, rpcExporters?: RPCExporter[], conf?: RPCSocketConf);
94
+    constructor(port: number, rpcExporters?: RPCExporter[], visibility?: Visibility, conf?: RPCSocketConf);
93
     private startWebsocket;
95
     private startWebsocket;
94
     protected initApis(socket: any): void;
96
     protected initApis(socket: any): void;
95
 }
97
 }

+ 3
- 2
lib/src/backend/RPCSocketServer.js View File

107
     return ret;
107
     return ret;
108
 };
108
 };
109
 class RPCSocketServer {
109
 class RPCSocketServer {
110
-    constructor(port, rpcExporters = [], conf = {
110
+    constructor(port, rpcExporters = [], visibility = "127.0.0.1", conf = {
111
         errorHandler: (socket) => (error) => { socket.destroy(); console.error(error); },
111
         errorHandler: (socket) => (error) => { socket.destroy(); console.error(error); },
112
         closeHandler: (socket) => () => { console.log("Socket closing"); },
112
         closeHandler: (socket) => () => { console.log("Socket closing"); },
113
         connectionHandler: (socket) => { console.log("New websocket connection in port " + socket.port); }
113
         connectionHandler: (socket) => { console.log("New websocket connection in port " + socket.port); }
114
     }) {
114
     }) {
115
         this.port = port;
115
         this.port = port;
116
         this.rpcExporters = rpcExporters;
116
         this.rpcExporters = rpcExporters;
117
+        this.visibility = visibility;
117
         this.conf = conf;
118
         this.conf = conf;
118
         this.io = bsock.createServer();
119
         this.io = bsock.createServer();
119
         this.wsServer = http.createServer();
120
         this.wsServer = http.createServer();
127
                 socket.on('close', this.conf.closeHandler(socket));
128
                 socket.on('close', this.conf.closeHandler(socket));
128
                 this.initApis(socket);
129
                 this.initApis(socket);
129
             });
130
             });
130
-            this.wsServer.listen(this.port);
131
+            this.wsServer.listen(this.port, this.visibility);
131
         }
132
         }
132
         catch (e) {
133
         catch (e) {
133
             //@ts-ignore
134
             //@ts-ignore

+ 3
- 4
src/backend/RPCSocketServer.ts View File

5
 import { Socket } from "./RPCSocketServer"
5
 import { Socket } from "./RPCSocketServer"
6
 
6
 
7
 type rpcType = 'hook' | 'unhook' | 'call'
7
 type rpcType = 'hook' | 'unhook' | 'call'
8
-type visibility = 'public' | 'private'
9
-
10
 export type Outcome = "Success" | "Error"
8
 export type Outcome = "Success" | "Error"
9
+export type Visibility = "127.0.0.1" | "0.0.0.0"
11
 
10
 
12
 /* Responses */
11
 /* Responses */
13
 export class Response{
12
 export class Response{
56
 type baseRPC = { 
55
 type baseRPC = { 
57
     type: rpcType
56
     type: rpcType
58
     name: string
57
     name: string
59
-    visibility: visibility
60
 }
58
 }
61
 
59
 
62
 type hookRPC = baseRPC & {
60
 type hookRPC = baseRPC & {
211
     constructor(
209
     constructor(
212
         private port:number,
210
         private port:number,
213
         private rpcExporters: RPCExporter[] = [],
211
         private rpcExporters: RPCExporter[] = [],
212
+        private visibility: Visibility = "127.0.0.1",
214
         private conf: RPCSocketConf = {
213
         private conf: RPCSocketConf = {
215
             errorHandler: (socket:Socket) => (error:any) => { socket.destroy(); console.error(error) },
214
             errorHandler: (socket:Socket) => (error:any) => { socket.destroy(); console.error(error) },
216
             closeHandler: (socket:Socket) => () => { console.log("Socket closing") },
215
             closeHandler: (socket:Socket) => () => { console.log("Socket closing") },
228
                 socket.on('close', this.conf.closeHandler(socket))
227
                 socket.on('close', this.conf.closeHandler(socket))
229
                 this.initApis(socket)
228
                 this.initApis(socket)
230
             })
229
             })
231
-            this.wsServer.listen(this.port)
230
+            this.wsServer.listen(this.port, this.visibility)
232
         }catch(e){
231
         }catch(e){
233
             //@ts-ignore
232
             //@ts-ignore
234
             this.errorHandler(undefined)("Unable to connect to socket")
233
             this.errorHandler(undefined)("Unable to connect to socket")

Loading…
Cancel
Save