Server/project/src/services/NotificationService.ts
Alex d13e86ba46 Rebranding to SPT (!345)
Rebranded src code and scripts to SPT

Co-authored-by: clodan <clodan@clodan.com>
Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/345
Co-authored-by: Alex <clodan@noreply.dev.sp-tarkov.com>
Co-committed-by: Alex <clodan@noreply.dev.sp-tarkov.com>
2024-05-21 17:59:04 +00:00

64 lines
1.3 KiB
TypeScript

import { injectable } from "tsyringe";
import { IWsNotificationEvent } from "@spt/models/eft/ws/IWsNotificationEvent";
@injectable()
export class NotificationService
{
protected messageQueue: Record<string, any[]> = {};
public getMessageQueue(): Record<string, any[]>
{
return this.messageQueue;
}
public getMessageFromQueue(sessionId: string): any[]
{
return this.messageQueue[sessionId];
}
public updateMessageOnQueue(sessionId: string, value: any[]): void
{
this.messageQueue[sessionId] = value;
}
public has(sessionID: string): boolean
{
return this.get(sessionID).length > 0;
}
/**
* Pop first message from queue.
*/
public pop(sessionID: string): any
{
return this.get(sessionID).shift();
}
/**
* Add message to queue
*/
public add(sessionID: string, message: IWsNotificationEvent): void
{
this.get(sessionID).push(message);
}
/**
* Get message queue for session
* @param sessionID
*/
public get(sessionID: string): any[]
{
if (!sessionID)
{
throw new Error("sessionID missing");
}
if (!this.messageQueue[sessionID])
{
this.messageQueue[sessionID] = [];
}
return this.messageQueue[sessionID];
}
}