*Add swarm to plugin api

This commit is contained in:
Derrick Hammer 2022-12-18 15:01:27 -05:00
parent 480bfdd0d0
commit 6fa5ccd49a
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 20 additions and 5 deletions

View File

@ -13,6 +13,7 @@ import pluginCore from "./plugins/core";
import type Config from "@lumeweb/cfg"; import type Config from "@lumeweb/cfg";
import EventEmitter2 from "eventemitter2"; import EventEmitter2 from "eventemitter2";
import log from "loglevel"; import log from "loglevel";
import { get as getSwarm } from "./swarm.js";
let pluginAPIManager: PluginAPIManager; let pluginAPIManager: PluginAPIManager;
let pluginAPI: PluginAPI; let pluginAPI: PluginAPI;
@ -27,10 +28,12 @@ class PluginAPI extends EventEmitter2 {
config, config,
logger, logger,
server, server,
swarm,
}: { }: {
config: Config; config: Config;
logger: Logger; logger: Logger;
server: RPCServer; server: RPCServer;
swarm: any;
}) { }) {
super({ super({
wildcard: true, wildcard: true,
@ -40,6 +43,13 @@ class PluginAPI extends EventEmitter2 {
this._config = config; this._config = config;
this._logger = logger; this._logger = logger;
this._server = server; this._server = server;
this._swarm = swarm;
}
private _swarm: any;
get swarm(): any {
return this._swarm;
} }
private _config: Config; private _config: Config;
@ -58,16 +68,16 @@ class PluginAPI extends EventEmitter2 {
return this._server; return this._server;
} }
get seed(): Uint8Array {
return getSeed();
}
public loadPlugin( public loadPlugin(
moduleName: string moduleName: string
): (moduleName: string) => Promise<Plugin> { ): (moduleName: string) => Promise<Plugin> {
return getPluginAPIManager().loadPlugin; return getPluginAPIManager().loadPlugin;
} }
get seed(): Uint8Array {
return getSeed();
}
registerMethod(methodName: string, method: RPCMethod): void { registerMethod(methodName: string, method: RPCMethod): void {
throw new Error("not implemented and should not be called"); throw new Error("not implemented and should not be called");
} }
@ -75,7 +85,12 @@ class PluginAPI extends EventEmitter2 {
export function getPluginAPI(): PluginAPI { export function getPluginAPI(): PluginAPI {
if (!pluginAPI) { if (!pluginAPI) {
pluginAPI = new PluginAPI({ config, logger: log, server: getRpcServer() }); pluginAPI = new PluginAPI({
config,
logger: log,
server: getRpcServer(),
swarm: getSwarm(),
});
} }
return pluginAPI as PluginAPI; return pluginAPI as PluginAPI;