hide info
This commit is contained in:
Vendored
+2
-3
@@ -66,7 +66,6 @@ export declare type ExtendedRpcInfo = RpcInfo & {
|
||||
uniqueName: string;
|
||||
};
|
||||
export declare const rpcToRpcinfo: (rpc: socketioRPC, owner: string) => RpcInfo;
|
||||
export declare const rpcHooker: (socket: Socket, owner: string, RPCs: socketioRPC[], makeUnique?: boolean) => ExtendedRpcInfo[];
|
||||
declare type OnFunction = (type: 'error' | 'close', f: (e?: any) => void) => Socket;
|
||||
export interface Socket {
|
||||
port: number;
|
||||
@@ -92,7 +91,7 @@ export declare class RPCSocketServer {
|
||||
private wsServer;
|
||||
constructor(port: number, rpcExporters?: RPCExporter[], visibility?: Visibility, conf?: RPCSocketConf);
|
||||
private startWebsocket;
|
||||
protected initApis(socket: Socket): void;
|
||||
protected initPublicApis(socket: Socket): void;
|
||||
protected initRPCs(socket: Socket): void;
|
||||
protected initPublicRPCs(socket: Socket): void;
|
||||
}
|
||||
export {};
|
||||
|
||||
@@ -61,7 +61,9 @@ exports.rpcToRpcinfo = (rpc, owner) => {
|
||||
};
|
||||
}
|
||||
};
|
||||
exports.rpcHooker = (socket, owner, RPCs, makeUnique = true) => {
|
||||
function rpcHooker(socket, exporter, makeUnique = true) {
|
||||
const owner = exporter.name;
|
||||
const RPCs = [...exporter.exportPublicRPCs(), ...exporter.exportRPCs()];
|
||||
const suffix = makeUnique ? "-" + uuid().substr(0, 4) : "";
|
||||
return RPCs.map(rpc => exports.rpcToRpcinfo(rpc, owner))
|
||||
.map(info => {
|
||||
@@ -77,7 +79,7 @@ exports.rpcHooker = (socket, owner, RPCs, makeUnique = true) => {
|
||||
socket.on('close', () => socket.unhook(info.name));
|
||||
return ret;
|
||||
});
|
||||
};
|
||||
}
|
||||
const hookGenerator = (rpc) => {
|
||||
const argsArr = extractArgs(rpc.func);
|
||||
argsArr.pop();
|
||||
@@ -124,9 +126,9 @@ class RPCSocketServer {
|
||||
socket.on('error', this.conf.errorHandler(socket));
|
||||
socket.on('close', this.conf.closeHandler(socket));
|
||||
if (this.visibility === "127.0.0.1")
|
||||
this.initApis(socket);
|
||||
this.initRPCs(socket);
|
||||
else
|
||||
this.initPublicApis(socket);
|
||||
this.initPublicRPCs(socket);
|
||||
});
|
||||
this.wsServer.listen(this.port, this.visibility);
|
||||
}
|
||||
@@ -135,30 +137,16 @@ class RPCSocketServer {
|
||||
this.errorHandler(undefined)("Unable to connect to socket");
|
||||
}
|
||||
}
|
||||
initApis(socket) {
|
||||
const adminRPCs = [
|
||||
{
|
||||
name: 'info',
|
||||
type: 'call',
|
||||
func: async () => rpcInfos
|
||||
}
|
||||
];
|
||||
initRPCs(socket) {
|
||||
socket.hook('info', () => rpcInfos);
|
||||
const rpcInfos = [
|
||||
...exports.rpcHooker(socket, "Admin", adminRPCs, false),
|
||||
...this.rpcExporters.flatMap(exporter => exports.rpcHooker(socket, exporter.name, [...exporter.exportPublicRPCs(), ...exporter.exportRPCs()]))
|
||||
...this.rpcExporters.flatMap(exporter => rpcHooker(socket, exporter))
|
||||
];
|
||||
}
|
||||
initPublicApis(socket) {
|
||||
const adminRPCs = [
|
||||
{
|
||||
name: 'info',
|
||||
type: 'call',
|
||||
func: async () => rpcInfos
|
||||
}
|
||||
];
|
||||
initPublicRPCs(socket) {
|
||||
socket.hook('info', () => rpcInfos);
|
||||
const rpcInfos = [
|
||||
...exports.rpcHooker(socket, "Admin", adminRPCs, false),
|
||||
...this.rpcExporters.flatMap(exporter => exports.rpcHooker(socket, exporter.name, exporter.exportPublicRPCs()))
|
||||
...this.rpcExporters.flatMap(exporter => rpcHooker(socket, exporter))
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ new RPCSocketServer_1.RPCSocketServer(20000, [{
|
||||
name: 'echo',
|
||||
func: async (s) => s,
|
||||
}],
|
||||
}], "0.0.0.0");
|
||||
}]);
|
||||
const caller = new RPCSocket_1.RPCSocket(20000, 'localhost');
|
||||
caller.connect().then(_ => {
|
||||
caller.info().then(console.log);
|
||||
|
||||
@@ -132,7 +132,10 @@ export const rpcToRpcinfo = (rpc : socketioRPC, owner: string):RpcInfo => {
|
||||
}
|
||||
}
|
||||
|
||||
export const rpcHooker = (socket: Socket, owner:string, RPCs: socketioRPC[], makeUnique = true):ExtendedRpcInfo[] => {
|
||||
|
||||
function rpcHooker(socket: Socket, exporter:RPCExporter, makeUnique = true):ExtendedRpcInfo[]{
|
||||
const owner = exporter.name
|
||||
const RPCs = [...exporter.exportPublicRPCs(), ...exporter.exportRPCs()]
|
||||
const suffix = makeUnique?"-"+uuid().substr(0,4):""
|
||||
return RPCs.map(rpc => rpcToRpcinfo(rpc, owner))
|
||||
.map(info => {
|
||||
@@ -236,32 +239,18 @@ export class RPCSocketServer{
|
||||
}
|
||||
|
||||
protected initRPCs(socket:Socket){
|
||||
const infoRPC:socketioRPC[] = [
|
||||
{
|
||||
name: 'info',
|
||||
type: 'call',
|
||||
func: async () => rpcInfos
|
||||
}
|
||||
]
|
||||
socket.hook('info', () => rpcInfos)
|
||||
|
||||
const rpcInfos:ExtendedRpcInfo[] = [
|
||||
...rpcHooker(socket, "RPC", infoRPC, false),
|
||||
...this.rpcExporters.flatMap(exporter => rpcHooker(socket, exporter.name, [...exporter.exportPublicRPCs(), ...exporter.exportRPCs()]))
|
||||
...this.rpcExporters.flatMap(exporter => rpcHooker(socket, exporter))
|
||||
]
|
||||
}
|
||||
|
||||
protected initPublicRPCs(socket:Socket){
|
||||
const adminRPCs:socketioRPC[] = [
|
||||
{
|
||||
name: 'info',
|
||||
type: 'call',
|
||||
func: async () => rpcInfos
|
||||
}
|
||||
]
|
||||
socket.hook('info', () => rpcInfos)
|
||||
|
||||
const rpcInfos:ExtendedRpcInfo[] = [
|
||||
...rpcHooker(socket, "Admin", adminRPCs, false),
|
||||
...this.rpcExporters.flatMap(exporter => rpcHooker(socket, exporter.name, exporter.exportPublicRPCs()))
|
||||
...this.rpcExporters.flatMap(exporter => rpcHooker(socket, exporter))
|
||||
]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user