setExporters
This commit is contained in:
+17
-2
@@ -6,6 +6,9 @@ import bsock = require('bsock');
|
||||
import * as T from './Types';
|
||||
import * as U from './Utils';
|
||||
import * as I from './Interfaces';
|
||||
import { Socket } from 'dgram';
|
||||
|
||||
type Exporters<InterfaceT extends T.RPCInterface = T.RPCInterface, SubResType = {}> = I.RPCExporter<T.RPCInterface<InterfaceT>, keyof InterfaceT, SubResType>[]
|
||||
|
||||
/**
|
||||
* A Websocket-server-on-steroids with built-in RPC capabilities
|
||||
@@ -31,10 +34,9 @@ export class RPCServer<
|
||||
*/
|
||||
constructor(
|
||||
private port:number,
|
||||
private exporters: I.RPCExporter<T.RPCInterface<InterfaceT>, keyof InterfaceT, SubResType>[] = [],
|
||||
private exporters: Exporters<InterfaceT, SubResType> = [],
|
||||
conf: T.ServerConf = {}
|
||||
){
|
||||
|
||||
if(!conf.visibility) this.visibility = "127.0.0.1"
|
||||
|
||||
if(conf.sesame){
|
||||
@@ -91,6 +93,19 @@ export class RPCServer<
|
||||
]
|
||||
}
|
||||
|
||||
/**
|
||||
* Publishes a new list of Exporters. This destroys and restarts the socket
|
||||
* @param exporters the exporters to publish
|
||||
*/
|
||||
public setExporters(exporters: Exporters<InterfaceT, SubResType>):any{
|
||||
exporters.forEach(U.fixNames)
|
||||
this.destroy()
|
||||
this.ws = http.createServer()
|
||||
this.io = bsock.createServer()
|
||||
this.exporters = exporters
|
||||
this.startWebsocket()
|
||||
}
|
||||
|
||||
destroy(): void {
|
||||
this.io.close()
|
||||
this.ws.close()
|
||||
|
||||
Reference in New Issue
Block a user