Daniel Hübleitner il y a 5 ans
Parent
révision
34ec2d0244

+ 3
- 1
lib/src/backend/RPCSocketServer.d.ts Voir le fichier

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

+ 3
- 2
lib/src/backend/RPCSocketServer.js Voir le fichier

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

+ 3
- 4
src/backend/RPCSocketServer.ts Voir le fichier

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

Chargement…
Annuler
Enregistrer