feat: add plugin management methods to RPCHandler
This commit is contained in:
@@ -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<RPCHandlerEvents> {
|
||||
private provider?: RPCProvider;
|
||||
private accessKey?: string;
|
||||
private config: RPCConfig;
|
||||
private plugins: RPCPlugin[] = [];
|
||||
|
||||
constructor(
|
||||
args?: {
|
||||
@@ -88,6 +90,29 @@ export class RPCHandler extends EventEmitter<RPCHandlerEvents> {
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user