|
@@ -3,15 +3,12 @@ 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, 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, Transport, TransportEvent, TransportService, Event } from "../interface/connector.interface";
|
|
|
|
|
|
+import { AdapterSet, TransportEvent, 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 { HttpTransportService } from "../transport/http";
|
|
|
|
|
|
|
|
export class MessageTransmissionManager implements MessageTransmissionManagerInterface {
|
|
export class MessageTransmissionManager implements MessageTransmissionManagerInterface {
|
|
- private transportServiceArray: TransportService[] = []
|
|
|
|
- private transportSet: Set<TransportSet> = new Set()
|
|
|
|
|
|
+
|
|
transmission: MessageTransmission[] = []
|
|
transmission: MessageTransmission[] = []
|
|
connectionManager!: ConnectionManager
|
|
connectionManager!: ConnectionManager
|
|
event!: Subject<TransportEvent>
|
|
event!: Subject<TransportEvent>
|
|
@@ -22,12 +19,6 @@ export class MessageTransmissionManager implements MessageTransmissionManagerInt
|
|
this.event = event
|
|
this.event = event
|
|
this.connectionManager = new ConnectionManager(this.event)
|
|
this.connectionManager = new ConnectionManager(this.event)
|
|
|
|
|
|
- this.sort(this.transportSet)
|
|
|
|
- this.transportSet.forEach(set => {
|
|
|
|
- this.setUpTransportService(set, event)
|
|
|
|
- })
|
|
|
|
-
|
|
|
|
- // temporarily off for now
|
|
|
|
// this.event.subscribe(event => console.log(`event`, 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
|
|
// 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
|
|
@@ -50,8 +41,8 @@ export class MessageTransmissionManager implements MessageTransmissionManagerInt
|
|
|
|
|
|
private instantiateComponents(clientId: string): MessageTransmission {
|
|
private instantiateComponents(clientId: string): MessageTransmission {
|
|
let adapterSet: AdapterSet[] = []
|
|
let adapterSet: AdapterSet[] = []
|
|
- if (this.transportServiceArray.length > 0) {
|
|
|
|
- this.transportServiceArray.forEach(transport => {
|
|
|
|
|
|
+ if (this.connectionManager.getTransportArray().length > 0) {
|
|
|
|
+ this.connectionManager.getTransportArray().forEach(transport => {
|
|
adapterSet.push(this.connectionManager.getAdapter(clientId, transport))
|
|
adapterSet.push(this.connectionManager.getAdapter(clientId, transport))
|
|
})
|
|
})
|
|
} else {
|
|
} else {
|
|
@@ -97,42 +88,6 @@ export class MessageTransmissionManager implements MessageTransmissionManagerInt
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- // Server to be set up as well as acquiring client information if needed. Like in the case for grpc and socket. Http not requ`ired.
|
|
|
|
- private setUpTransportService(transportSet: TransportSet, event: Subject<TransportEvent>): void {
|
|
|
|
- this.instantiateTransportService(transportSet.transport, event).then((transportService: TransportService) => {
|
|
|
|
- this.transportServiceArray.push(transportService)
|
|
|
|
- if (transportService instanceof WebsocketTransportService) {
|
|
|
|
- console.log(`Just Double Checking... this is websocket`)
|
|
|
|
- transportService.startServer(transportSet.port);
|
|
|
|
- } else if (transportService instanceof HttpTransportService) {
|
|
|
|
- console.log(`Just Double Checking... this is http`)
|
|
|
|
- transportService.startServer(transportSet.port);
|
|
|
|
- // Additional Http-specific setup if needed.
|
|
|
|
- }
|
|
|
|
- }).catch((error) => { throw new Error(error) })
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private async instantiateTransportService(transportType: Transport, event: Subject<TransportEvent>): Promise<TransportService> {
|
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
|
- if (transportType == Transport.Websocket) {
|
|
|
|
- resolve(new WebsocketTransportService(event))
|
|
|
|
- }
|
|
|
|
- else if (transportType == Transport.Http) {
|
|
|
|
- resolve(new HttpTransportService(event))
|
|
|
|
- } else {
|
|
|
|
- reject(`No Transport Service is not properly instantiated`)
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private sort(transportSet: Set<TransportSet>): void {
|
|
|
|
- let transportList: string[] = process.env.Transport?.split(',') || []
|
|
|
|
- let portList: number[] = (process.env.PORT?.split(',') || []).map(port => Number(port));
|
|
|
|
- transportList.forEach((transport, index) => {
|
|
|
|
- transportSet.add({ transport: transport, port: portList[index] } as unknown as TransportSet)
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
|
|
private handleEvent(eventName: Event, eventObs: Observable<TransportEvent>): void {
|
|
private handleEvent(eventName: Event, eventObs: Observable<TransportEvent>): void {
|
|
eventObs.pipe(
|
|
eventObs.pipe(
|
|
@@ -158,8 +113,3 @@ export class MessageTransmissionManager implements MessageTransmissionManagerInt
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-interface TransportSet {
|
|
|
|
- transport: Transport,
|
|
|
|
- port: number
|
|
|
|
-}
|
|
|
|
-
|
|
|