This commit is contained in:
2019-09-21 16:15:31 +02:00
parent 6005382a54
commit 597be1b80f
7 changed files with 878 additions and 130 deletions
+8 -2
View File
@@ -9,7 +9,8 @@ import * as I from './Interfaces';
export class RPCServer<
SubResType = {}
>{
> implements I.Destroyable{
private ws = http.createServer()
private io = bsock.createServer()
private visibility:T.Visibility
@@ -34,7 +35,7 @@ export class RPCServer<
if(!conf.closeHandler) this.closeHandler =
(socket:I.Socket) => () => {
console.log("Socket on port "+socket.port+"closing")
console.log("Socket on port "+socket.port+" closing")
}
if(!conf.connectionHandler) this.connectionHandler =
@@ -78,4 +79,9 @@ export class RPCServer<
...this.exporters.flatMap(exporter => U.rpcHooker(socket, exporter))
]
}
async destroy(): Promise<void> {
this.io.close()
this.ws.close()
}
}
+1
View File
@@ -47,6 +47,7 @@ export class RPCSocket implements I.Socket{
public async connect(){
this.socket = await bsock.connect(this.port, this.server, this.tls)
this.on('error', () => {})
const info:T.ExtendedRpcInfo[] = await this.info()
info.forEach(i => {
+7 -4
View File
@@ -6,13 +6,16 @@ export interface Exporter<T = {}>{
exportRPCs() : T.RPC<T>[]
}
export interface Socket {
export interface Socket extends Destroyable {
port: number
hook: (rpcname: T.Name, ...args: T.Any[]) => I.Socket
unhook: (rpcname:T.Name) => I.Socket
call: (rpcname:T.Name, ...args: T.Any[]) => Promise<T.Any>
fire: (rpcname:T.Name, ...args: T.Any[]) => Promise<T.Any>
on: T.OnFunction
destroy: ()=>void
close: ()=>void
on: T.OnFunction
close() : void
}
export interface Destroyable{
destroy() : void
}