incomingMessage.service.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. public 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(messages => (messages.data))
  21. )
  22. /* Trying new promise chaining structure */
  23. this.logService.init(logSetting).then(() => {
  24. this.logService.subscribe(transformedOBS)
  25. }).catch((e) => console.error(e)).then(() => {
  26. this.acknowledgeService.init(logSetting)
  27. }).catch((e) => console.error(e)).then(() => {
  28. this.acknowledgeService.subscribe(transformedOBS)
  29. }).catch((e) => console.error(e))
  30. // this.logService.init(logSetting).then(() => {
  31. // this.logService.subscribe(transformedOBS).then(() => {
  32. // this.acknowledgeService.init(logSetting).then(() => {
  33. // this.acknowledgeService.subscribe(transformedOBS)
  34. // }).catch((e) => console.error(e))
  35. // }).catch((e) => console.log(e))
  36. // }).catch((e) => console.error(e))
  37. }
  38. }