mirror of
https://github.com/logos-messaging/logos-messaging-js.git
synced 2026-01-14 22:13:09 +00:00
55 lines
1.2 KiB
TypeScript
55 lines
1.2 KiB
TypeScript
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<void>;
|
|
}
|
|
|
|
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<void> {
|
|
await this.ackManager.stop();
|
|
}
|
|
|
|
public send(encoder: IEncoder, message: IMessage): Promise<void> {
|
|
return this.sender.send(encoder, message);
|
|
}
|
|
}
|