import { IEncoder, IFilter, ILightPush, IMessage, IStore } from "@waku/interfaces"; import { AckManager } from "./ack_manager.js"; import { MessageStore } from "./message_store.js"; import { Sender } from "./sender.js"; interface IMessaging { send(encoder: IEncoder, message: IMessage): Promise; } type MessagingConstructorParams = { lightPush: ILightPush; filter: IFilter; store: IStore; }; export class Messaging implements IMessaging { private readonly messageStore: MessageStore; private readonly ackManager: AckManager; private readonly sender: Sender; public constructor(params: MessagingConstructorParams) { this.messageStore = new MessageStore(); this.ackManager = new AckManager({ messageStore: this.messageStore, filter: params.filter, store: params.store }); this.sender = new Sender({ messageStore: this.messageStore, lightPush: params.lightPush }); } public start(): void { this.ackManager.start(); } public async stop(): Promise { await this.ackManager.stop(); } public send(encoder: IEncoder, message: IMessage): Promise { return this.sender.send(encoder, message); } }