From 815c7a824cfe94fa367841be5cabf5b68b733e9b Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Fri, 30 Dec 2022 01:06:29 -0500 Subject: [PATCH] *Add protocol manager api --- src/index.ts | 1 + src/plugin.ts | 2 ++ src/swarm.ts | 6 ++++++ 3 files changed, 9 insertions(+) create mode 100644 src/swarm.ts diff --git a/src/index.ts b/src/index.ts index 5588454..b42b9da 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,2 +1,3 @@ export * from "./rpc.js"; export * from "./plugin.js"; +export * from "./swarm.js"; diff --git a/src/plugin.ts b/src/plugin.ts index 913c9c4..d908f27 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -4,6 +4,7 @@ import { Logger } from "pino"; import SSLManager from "./ssl.js"; import type { HDKey } from "micro-ed25519-hdkey"; import type Config from "@lumeweb/cfg"; +import type { ProtocolManager } from "./swarm.js"; export type PluginFunction = (api: PluginAPI) => Promise; @@ -34,6 +35,7 @@ export declare class PluginAPI extends EventEmitter2 { get seed(): Uint8Array; get identity(): HDKey; get ssl(): SSLManager; + get protocols(): ProtocolManager; loadPlugin(moduleName: string): (moduleName: string) => Promise; registerMethod(methodName: string, method: RPCMethod): void; } diff --git a/src/swarm.ts b/src/swarm.ts new file mode 100644 index 0000000..7d3ebfb --- /dev/null +++ b/src/swarm.ts @@ -0,0 +1,6 @@ +export type ProtocolHandler = (peer: any, muxer: any) => void; + +export declare class ProtocolManager { + constructor(swarm: any); + register(name: string, handler: ProtocolHandler): boolean; +}