24 lines
683 B
TypeScript
24 lines
683 B
TypeScript
import { Channel, OnInboundMessage, OnChatMetadata, RegisteredGroup } from '../types.js';
|
|
|
|
export interface ChannelOpts {
|
|
onMessage: OnInboundMessage;
|
|
onChatMetadata: OnChatMetadata;
|
|
registeredGroups: () => Record<string, RegisteredGroup>;
|
|
}
|
|
|
|
export type ChannelFactory = (opts: ChannelOpts) => Channel | null;
|
|
|
|
const registry = new Map<string, ChannelFactory>();
|
|
|
|
export function registerChannel(name: string, factory: ChannelFactory): void {
|
|
registry.set(name, factory);
|
|
}
|
|
|
|
export function getChannelFactory(name: string): ChannelFactory | undefined {
|
|
return registry.get(name);
|
|
}
|
|
|
|
export function getRegisteredChannelNames(): string[] {
|
|
return [...registry.keys()];
|
|
}
|