Server/project/src/helpers/NotificationSendHelper.ts

29 lines
944 B
TypeScript
Raw Normal View History

2023-03-03 16:23:46 +01:00
import { inject, injectable } from "tsyringe";
import { INotification } from "../models/eft/notifier/INotifier";
import { WebSocketServer } from "../servers/WebSocketServer";
import { NotificationService } from "../services/NotificationService";
@injectable()
export class NotificationSendHelper
{
constructor(
@inject("WebSocketServer") protected webSocketServer: WebSocketServer,
@inject("NotificationService") protected notificationService: NotificationService
)
{}
/**
* Send notification message to the appropriate channel
*/
public sendMessage(sessionID: string, notificationMessage: INotification): void
{
if (this.webSocketServer.isConnectionWebSocket(sessionID))
{
this.webSocketServer.sendMessage(sessionID, notificationMessage);
}
else
{
this.notificationService.add(sessionID, notificationMessage);
}
}
}