|
@@ -2,7 +2,7 @@ import { filter, interval, map, Observable, Observer, Subject, take } from "rxjs
|
|
import { Bus, FisMessage, MessageTransmission, TransmissionMessage } from "../interface/transport.interface";
|
|
import { Bus, FisMessage, MessageTransmission, TransmissionMessage } from "../interface/transport.interface";
|
|
import { v4 as uuidv4 } from 'uuid'
|
|
import { v4 as uuidv4 } from 'uuid'
|
|
import { MessageTransmissionManager } from "../transmission/msg.transmission.manager";
|
|
import { MessageTransmissionManager } from "../transmission/msg.transmission.manager";
|
|
-import { TransportEvent } from "../interface/connector.interface";
|
|
|
|
|
|
+import { TransportEvent, TransportMessage } from "../interface/connector.interface";
|
|
|
|
|
|
class Supervisor {
|
|
class Supervisor {
|
|
private clientIncomingMessage: Subject<FisMessage> = new Subject()
|
|
private clientIncomingMessage: Subject<FisMessage> = new Subject()
|
|
@@ -26,10 +26,10 @@ class Supervisor {
|
|
// only called once for each connected clients.
|
|
// only called once for each connected clients.
|
|
private handleClientActivity(messageTransmission: MessageTransmission): void {
|
|
private handleClientActivity(messageTransmission: MessageTransmission): void {
|
|
// start listening to incoming messages from this client
|
|
// start listening to incoming messages from this client
|
|
- messageTransmission.receiver.getMessageBus(Bus.GeneralBus).subscribe((event: TransmissionMessage) => {
|
|
|
|
|
|
+ messageTransmission.receiver.getMessageBus(Bus.GeneralBus).subscribe((event: TransportEvent) => {
|
|
console.log(event)
|
|
console.log(event)
|
|
- let requestMessage: FisMessage = event.payload
|
|
|
|
- // this.clientIncomingMessage.next(event.payload as FisMessage)
|
|
|
|
|
|
+ let requestMessage: FisMessage = (event.data as TransportMessage).payload as FisMessage
|
|
|
|
+ this.clientIncomingMessage.next(requestMessage)
|
|
this.messageProducer.getOutgoingMessages().pipe(
|
|
this.messageProducer.getOutgoingMessages().pipe(
|
|
filter(message => message.header.messageID === requestMessage.header.messageID)
|
|
filter(message => message.header.messageID === requestMessage.header.messageID)
|
|
).subscribe(message => {
|
|
).subscribe(message => {
|
|
@@ -47,17 +47,16 @@ class Supervisor {
|
|
|
|
|
|
|
|
|
|
class MessageProducer {
|
|
class MessageProducer {
|
|
- private transmissionInstance!: MessageTransmission
|
|
|
|
private generalNotification: Subject<FisMessage> = new Subject()
|
|
private generalNotification: Subject<FisMessage> = new Subject()
|
|
private incomingMessageBus!: Subject<FisMessage>
|
|
private incomingMessageBus!: Subject<FisMessage>
|
|
private outgoingMessageBus: Subject<FisMessage> = new Subject()
|
|
private outgoingMessageBus: Subject<FisMessage> = new Subject()
|
|
|
|
|
|
- constructor(incomingMessageBus: Subject<any>) {
|
|
|
|
|
|
+ constructor(incomingMessageBus: Subject<FisMessage>) {
|
|
console.log(`Contructing Application....`)
|
|
console.log(`Contructing Application....`)
|
|
this.incomingMessageBus = incomingMessageBus
|
|
this.incomingMessageBus = incomingMessageBus
|
|
|
|
|
|
this.generateNotifcation().subscribe(this.generalNotification)
|
|
this.generateNotifcation().subscribe(this.generalNotification)
|
|
- this.handleIncomingRequests(this.incomingMessageBus, this.outgoingMessageBus)
|
|
|
|
|
|
+ this.handleIncomingRequests(this.incomingMessageBus.asObservable(), this.outgoingMessageBus)
|
|
}
|
|
}
|
|
|
|
|
|
public getNotificationMessage(): Observable<FisMessage> {
|
|
public getNotificationMessage(): Observable<FisMessage> {
|
|
@@ -68,8 +67,10 @@ class MessageProducer {
|
|
return this.outgoingMessageBus.asObservable()
|
|
return this.outgoingMessageBus.asObservable()
|
|
}
|
|
}
|
|
|
|
|
|
- private handleIncomingRequests(requests: Subject<FisMessage>, outgoingMessageBus: Subject<FisMessage>): void {
|
|
|
|
- requests.subscribe(request => {
|
|
|
|
|
|
+ // this is called no problem
|
|
|
|
+ private handleIncomingRequests(requests: Observable<FisMessage>, outgoingMessageBus: Subject<FisMessage>): void {
|
|
|
|
+ requests.subscribe((request: FisMessage) => {
|
|
|
|
+ console.log(`Generating response for new request ${request.header.messageID}`)
|
|
this.generateMessage(10).subscribe({
|
|
this.generateMessage(10).subscribe({
|
|
next: message => outgoingMessageBus.next(message),
|
|
next: message => outgoingMessageBus.next(message),
|
|
error: error => console.error(error),
|
|
error: error => console.error(error),
|