diff --git a/src/core/RPCHandler.ts b/src/core/RPCHandler.ts index 1dba807..03959a0 100644 --- a/src/core/RPCHandler.ts +++ b/src/core/RPCHandler.ts @@ -3,6 +3,7 @@ import { RPCClient } from "./RPCClient"; import { RPCServer } from "./RPCServer"; import { RPCProvider } from "./RPCProvider"; import { RPCSession } from "./RPCSession"; +import { RPCPlugin } from "./RPCPlugin"; const DefaultListenOptions = { port: 5201, @@ -34,6 +35,7 @@ export class RPCHandler extends EventEmitter { private provider?: RPCProvider; private accessKey?: string; private config: RPCConfig; + private plugins: RPCPlugin[] = []; constructor( args?: { @@ -88,6 +90,29 @@ export class RPCHandler extends EventEmitter { } } + loadPlugin(plugin: RPCPlugin): boolean { + const plugins = this.plugins; + if (plugins.includes(plugin)) { + return false; + } + plugins.push(plugin); + return true; + } + + unloadPlugin(plugin: RPCPlugin): boolean { + const plugins = this.plugins; + const idx = plugins.indexOf(plugin); + if (idx === -1) { + return false; + } + plugins.splice(idx, 1); + return true; + } + + getPlugins(): RPCPlugin[] { + return [...this.plugins]; + } + async connect(options: { url?: string; accessKey?: string;