|
@@ -1,16 +1,15 @@
|
|
import { MessageTransmissionTransmitter } from "./msg.transmission.transmitter";
|
|
import { MessageTransmissionTransmitter } from "./msg.transmission.transmitter";
|
|
import { MessageTransmissionReceiver } from "./msg.transmission.receiver";
|
|
import { MessageTransmissionReceiver } from "./msg.transmission.receiver";
|
|
import { ConnectionManager } from "../connector/connector.manager";
|
|
import { ConnectionManager } from "../connector/connector.manager";
|
|
-import { EventMessage, MessageTransmission, MessageTransmissionManager as MessageTransmissionManagerInterface, ReceiverProfile, TransmissionProfile, TransmitterProfile } from "../interface/transport.interface";
|
|
|
|
|
|
+import { EventMessage, MessageTransmission, MessageTransmissionManager as MessageTransmissionManagerInterface, ReceiverProfile, TransmitterProfile } from "../interface/transport.interface";
|
|
import { v4 as uuidv4 } from 'uuid'
|
|
import { v4 as uuidv4 } from 'uuid'
|
|
-import { AdapterSet, AdaptorTransmissionRole, RequestResponseConnectionAdapter, Transport, TransportEvent, TransportService } from "../interface/connector.interface";
|
|
|
|
|
|
+import { AdapterSet, Transport, TransportEvent, TransportService, Event } from "../interface/connector.interface";
|
|
import { MessageTransmissionRequestResponse } from "./msg.transmission.request-response";
|
|
import { MessageTransmissionRequestResponse } from "./msg.transmission.request-response";
|
|
import { filter, Observable, Observer, Subject } from "rxjs";
|
|
import { filter, Observable, Observer, Subject } from "rxjs";
|
|
import { WebsocketTransportService } from "../transport/websocket";
|
|
import { WebsocketTransportService } from "../transport/websocket";
|
|
import { HttpTransportService } from "../transport/http";
|
|
import { HttpTransportService } from "../transport/http";
|
|
-import { error } from "console";
|
|
|
|
|
|
|
|
-export class MessageTransmissionManager implements MessageTransmissionManagerInterface{
|
|
|
|
|
|
+export class MessageTransmissionManager implements MessageTransmissionManagerInterface {
|
|
private transportServiceArray: TransportService[] = []
|
|
private transportServiceArray: TransportService[] = []
|
|
private transportSet: Set<TransportSet> = new Set()
|
|
private transportSet: Set<TransportSet> = new Set()
|
|
transmission: MessageTransmission[] = []
|
|
transmission: MessageTransmission[] = []
|
|
@@ -27,6 +26,12 @@ export class MessageTransmissionManager implements MessageTransmissionManagerInt
|
|
this.transportSet.forEach(set => {
|
|
this.transportSet.forEach(set => {
|
|
this.setUpTransportService(set, event)
|
|
this.setUpTransportService(set, event)
|
|
})
|
|
})
|
|
|
|
+
|
|
|
|
+ this.event.subscribe(event => console.log(`event`, event))
|
|
|
|
+
|
|
|
|
+ // note that if this server is down, all these instances of transmission and connector would be lost as well. SO cannot just simply find "instances" and reuse them. Must reinstantiate them again
|
|
|
|
+ this.handleEvent(`Client Disconnected` as Event, event)
|
|
|
|
+ this.handleEvent('Client Reconnected' as Event, event)
|
|
}
|
|
}
|
|
|
|
|
|
/* so there will be some changes here. will nto be assigning just one, but all of them dynamically to pour into this boy
|
|
/* so there will be some changes here. will nto be assigning just one, but all of them dynamically to pour into this boy
|
|
@@ -37,34 +42,36 @@ export class MessageTransmissionManager implements MessageTransmissionManagerInt
|
|
filter(event => event.event == 'New Client')
|
|
filter(event => event.event == 'New Client')
|
|
).subscribe(event => {
|
|
).subscribe(event => {
|
|
// get all adapters for all the connection
|
|
// get all adapters for all the connection
|
|
- let adapterSet: AdapterSet[] = []
|
|
|
|
- let clientId: string = (event.data as EventMessage).clientId
|
|
|
|
- if (this.transportServiceArray.length > 0) {
|
|
|
|
- this.transportServiceArray.forEach(transport => {
|
|
|
|
- adapterSet.push(this.connectionManager.getAdapter(clientId, transport))
|
|
|
|
- })
|
|
|
|
- } else {
|
|
|
|
- observer.error('No Transport is instantiated.... ERROR!!!!')
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // 1 set only
|
|
|
|
- let transmitter: MessageTransmissionTransmitter = this.getTransmitter(clientId, adapterSet, this.event.asObservable())
|
|
|
|
- let receiver: MessageTransmissionReceiver = this.getReceiver(clientId, adapterSet, this.event.asObservable())
|
|
|
|
- let requestResponse: MessageTransmissionRequestResponse = this.getRequestResponse(transmitter, receiver, this.event.asObservable())
|
|
|
|
- let transmission: MessageTransmission = {
|
|
|
|
- id: clientId,
|
|
|
|
- transmitter: transmitter,
|
|
|
|
- receiver: receiver,
|
|
|
|
- requestResponse: requestResponse,
|
|
|
|
- event: this.event.asObservable()
|
|
|
|
- }
|
|
|
|
- this.transmission.push(transmission)
|
|
|
|
-
|
|
|
|
- observer.next(transmission)
|
|
|
|
|
|
+ observer.next(this.instantiateComponents((event.data as EventMessage).clientId))
|
|
})
|
|
})
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private instantiateComponents(clientId: string): MessageTransmission {
|
|
|
|
+ let adapterSet: AdapterSet[] = []
|
|
|
|
+ if (this.transportServiceArray.length > 0) {
|
|
|
|
+ this.transportServiceArray.forEach(transport => {
|
|
|
|
+ adapterSet.push(this.connectionManager.getAdapter(clientId, transport))
|
|
|
|
+ })
|
|
|
|
+ } else {
|
|
|
|
+ throw new Error(`Transmission Manager: No transport is Instantiated`)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 1 set only
|
|
|
|
+ let transmitter: MessageTransmissionTransmitter = this.getTransmitter(clientId, adapterSet, this.event.asObservable())
|
|
|
|
+ let receiver: MessageTransmissionReceiver = this.getReceiver(clientId, adapterSet, this.event.asObservable())
|
|
|
|
+ let requestResponse: MessageTransmissionRequestResponse = this.getRequestResponse(transmitter, receiver, this.event.asObservable())
|
|
|
|
+ let transmission: MessageTransmission = {
|
|
|
|
+ id: clientId,
|
|
|
|
+ transmitter: transmitter,
|
|
|
|
+ receiver: receiver,
|
|
|
|
+ requestResponse: requestResponse,
|
|
|
|
+ event: this.event.asObservable()
|
|
|
|
+ }
|
|
|
|
+ this.transmission.push(transmission)
|
|
|
|
+ return transmission
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
private getTransmitter(transmissionId: string, adapterSets: AdapterSet[], event: Observable<TransportEvent>): MessageTransmissionTransmitter {
|
|
private getTransmitter(transmissionId: string, adapterSets: AdapterSet[], event: Observable<TransportEvent>): MessageTransmissionTransmitter {
|
|
let transmitterProfile: TransmitterProfile = {
|
|
let transmitterProfile: TransmitterProfile = {
|
|
@@ -124,6 +131,28 @@ export class MessageTransmissionManager implements MessageTransmissionManagerInt
|
|
transportSet.add({ transport: transport, port: portList[index] } as unknown as TransportSet)
|
|
transportSet.add({ transport: transport, port: portList[index] } as unknown as TransportSet)
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ private handleEvent(eventName: Event, eventObs: Observable<TransportEvent>): void {
|
|
|
|
+ eventObs.pipe(
|
|
|
|
+ filter((event: TransportEvent) => event.event === eventName)
|
|
|
|
+ ).subscribe(event => {
|
|
|
|
+ // assuming this is reconnection case
|
|
|
|
+ if(event.event == 'Client Reconnected') {
|
|
|
|
+ this.reconnectionHandler((event.data as EventMessage).clientId)
|
|
|
|
+ }
|
|
|
|
+ // can include more event handlers here
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private reconnectionHandler(clientId: string): void {
|
|
|
|
+ let transmissionObj: MessageTransmission | undefined = Array.from(this.transmission).find(obj => obj.id === clientId)
|
|
|
|
+ if (!transmissionObj) {
|
|
|
|
+ let transmission: MessageTransmission = this.instantiateComponents(clientId)
|
|
|
|
+ this.transmission.push(transmission)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|