incomingMessage.service.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334
  1. import { map, Observable, of, tap } from "rxjs";
  2. import { BaseMessage, Command, ResponseMessage, Uuid } from "../dependencies/fisappmessagejsutilty/interface/export"
  3. import { LoggingService } from "../dependencies/fisloggingservice/services/logging-service";
  4. import { LogSetting, MessageLog } from "../dependencies/fisloggingservice/type/datatype";
  5. import { IncomingMessageServiceInterface } from "../type/datatype";
  6. import { AcknowledgementService } from "./acknowledgement.service";
  7. export class IncomingMessageService implements IncomingMessageServiceInterface {
  8. constructor(private logService?: LoggingService, private acknowledgeService?: AcknowledgementService) {
  9. this.logService = new LoggingService()
  10. this.acknowledgeService = new AcknowledgementService()
  11. }
  12. init(settings: LogSetting & { incomingObservable: Observable<BaseMessage>; }): void {
  13. let logSetting: LogSetting = {
  14. storage: settings.storage,
  15. setting: settings.setting,
  16. customSetting: settings.customSetting
  17. }
  18. // Transform incoming observables into Observable<MessageLog> to be logged
  19. let transformedOBS: Observable<any> = settings.incomingObservable.pipe(
  20. map(
  21. messages => (messages.data)
  22. )
  23. )
  24. this.logService.init(logSetting).then(() => {
  25. this.logService.subscribe(transformedOBS).then(() => {
  26. this.acknowledgeService.init(logSetting).then(() => {
  27. this.acknowledgeService.subscribe(transformedOBS)
  28. }).catch((e) => console.error(e))
  29. }).catch((e) => console.log(e))
  30. }).catch((e) => console.error(e))
  31. }
  32. }