加入插件及调用上下文 #1

Merged
tone merged 17 commits from dev into main 2025-12-02 15:48:35 +08:00
Showing only changes of commit 99c673a8dc - Show all commits

View File

@@ -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;