Browse Source

refactoring for new spec. Non tested code

Enzo 4 days ago
parent
commit
077b9ac588

+ 2 - 2
.env

@@ -1,2 +1,2 @@
-Transport = "Websocket"
-PORT = 3000
+Transport = "Websocket, Http"
+PORT = 3000, 3001

+ 4 - 9
src/connector/connector.base.ts

@@ -1,14 +1,13 @@
 import { BehaviorSubject, Observable, Observer, Subject, Subscriber, Unsubscribable } from "rxjs";
 import dotenv from 'dotenv';
-import { AdapterProfile, AdaptorTransmissionRole, ConnectionAdaptorBase, ConnectionState, TransportEvent, TransportMessage } from "../interface/connector.interface";
-import { Bus, FisAppActor, FisMessage } from "../interface/transport.interface";
+import { AdapterProfile, AdaptorTransmissionRole, ConnectionAdaptorBase, ConnectionState, Transport, TransportEvent, TransportMessage, TransportService } from "../interface/connector.interface";
 
 dotenv.config();
 /* This transport manager will be instantiating the necessary transport to deal with tranmission and receiving from different receivers
 So how?: */
 export class ConnectionAdapter implements ConnectionAdaptorBase {
     event!: Subject<TransportEvent>
-    connector: any;
+    connector!: TransportService;
     connectorProfile!: AdapterProfile;
     connectionStateBus!: Subject<ConnectionState>;
     adaptorTransmissionRole!: AdaptorTransmissionRole;
@@ -16,9 +15,7 @@ export class ConnectionAdapter implements ConnectionAdaptorBase {
     constructor() {
         //logic here
     }
-    setAdapterProfile(adapterId: string): void {
-        throw new Error("Method not implemented.")
-    }
+
     getInfo(): AdapterProfile {
         throw new Error("Method not implemented.");
     }
@@ -34,11 +31,9 @@ export class ConnectionAdapter implements ConnectionAdaptorBase {
     disconnect(): void {
         throw new Error("Method not implemented.");
     }
-    getMessageBus(bus: Bus): Observable<any> {
+    setAdapterProfile(id: string, transportType: Transport): void {
         throw new Error("Method not implemented.");
     }
-
-
 }
 
 

+ 24 - 85
src/connector/connector.manager.ts

@@ -1,101 +1,40 @@
-import { v4 as uuidv4 } from 'uuid'
-import dotenv from 'dotenv';
-import { TransportEvent, ConnectionManager as ConnectionManagerInterface, AdapterSet, Transport, TransportService, ClientObject } from "../interface/connector.interface"
+import { ConnectionManager as ConnectionManagerInterface, AdapterSet, TransportService, TransportEvent, Transport } from "../interface/connector.interface"
 import { TransmitterConnectionAdapter } from './connector.transmitter'
 import { ReceiverConnectionAdapter } from './connector.receiver'
-import { EventMessage } from '../interface/transport.interface'
-import { Subject } from 'rxjs'
-import { WebsocketTransportService } from '../transport/websocket'
 import { RequestResponseConnectionAdapter } from './connector.request.response'
-import { HttpTransportService } from '../transport/http'
-/* now, this connection manager, after setting up the servers, will also need to start assigning receivers so to speak.
-From Provider's perspective: When instantiating a new server, there will be no doubt multiple clients connecting in. So that means, the connector instances that will be used from
-the transmission side, must already be configured and locked to their respective target so to speak. So for one client, there would only be one transmitter and receiver connector instances
-as well as request response. Let's go along with this line for now. */
+import { v4 as uuidv4 } from 'uuid'
+import { Subject } from "rxjs"
 export class ConnectionManager implements ConnectionManagerInterface {
-    transportService!: TransportService;
-    transportEvent: Subject<TransportEvent> = new Subject() // Every event goes through this boy, and it will be expose across differnet components
-    adapterSet: AdapterSet[] = []
+    private adapterSet: AdapterSet[] = []
+    private event!: Subject<TransportEvent>
 
-    constructor() {
+    constructor(event: Subject<TransportEvent>) {
+        this.event = event
         console.log(`Connection Manager: Contructing ConnectionManager....`)
-        // logic here
-        this.getTransportService(process.env.Transport as unknown as Transport)
-        this.setUpServer(process.env.PORT as unknown as number)
-
-        // Everything that happens will go through here. Can also plug in logging service here at a later time
-        this.transportEvent.subscribe((event: TransportEvent) => {
-            console.log(`TransportEvent: `, event)
-            if (event.event == 'New Client') {
-                this.handleNewClient((event.data as EventMessage).payload) // payload is connectedclientInstance
-            }
-        })
-    }
-
-    // alternatives. Though the transmission instances have their own set of pointers
-    getAdapterSetById(adapterSetid: string): AdapterSet {
-        let adapterSet: AdapterSet | undefined = this.adapterSet.find(obj => obj.id === adapterSetid)
-        if (adapterSet) {
-            return adapterSet
-        } else {
-            throw new Error(`Adapter Set not found!!!`)
-        }
-    }
-
-    getTransportService(transportType: Transport): void {
-        console.log(`Instantiating ${transportType} tranport service to be used.`)
-        if (transportType === Transport.Websocket) {
-            this.transportService = new WebsocketTransportService()
-            this.triggerTransportEvent(`Setting up Websocket Transport Service`)
-        }
-        if (transportType === Transport.Http) {
-            this.transportService = new HttpTransportService()
-            this.triggerTransportEvent(`Setting up Http Transport Service`)
-        }
     }
 
-    private triggerTransportEvent(message: string): void {
-        this.transportEvent.next({
-            id: uuidv4(),
-            event: `New Transport`,
-            data: { message }
-        });
-    }
-
-    // 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 setUpServer(port: number): void {
-        if (this.transportService instanceof WebsocketTransportService) {
-            this.transportService.startServer(port);
-            this.transportService.getTransportEvent().subscribe(this.transportEvent);
-        } else if (this.transportService instanceof HttpTransportService) {
-            this.transportService.startServer(port);
-            this.transportService.getTransportEvent().subscribe(this.transportEvent);
-            // Additional Http-specific setup if needed.
-        }
-    }
-
-    private handleNewClient(clientInstance: ClientObject): void {
-        // need to setup the adapters to be called by the transmission manager
-        let transmitter: TransmitterConnectionAdapter = new TransmitterConnectionAdapter(this.transportService, clientInstance.id, this.transportEvent, clientInstance.connectionState.asObservable())
-        let receiver: ReceiverConnectionAdapter = new ReceiverConnectionAdapter(this.transportService, clientInstance.id, this.transportEvent)
-        let requestResponse: RequestResponseConnectionAdapter = new RequestResponseConnectionAdapter(transmitter, receiver, clientInstance.id)
+    getAdapter(clientId: string, transportService: TransportService): AdapterSet {
+        let transportType: Transport = transportService.getInfo()
+        let adapterId: string = clientId
+        let transmitterAdapter: TransmitterConnectionAdapter = new TransmitterConnectionAdapter(adapterId, transportType, transportService)
+        let receiverAdapter: ReceiverConnectionAdapter = new ReceiverConnectionAdapter(adapterId, transportType, transportService)
         let adapterSet: AdapterSet = {
-            id: clientInstance.id,
+            id: adapterId,
             dateCreated: new Date(),
-            transmitterAdapter: transmitter,
-            receiverAdapter: receiver,
-            requestResponsAdapter: requestResponse
+            transmitterAdapter: transmitterAdapter,
+            receiverAdapter: receiverAdapter,
+            requestResponsAdapter: new RequestResponseConnectionAdapter(transmitterAdapter, receiverAdapter)
         }
         this.adapterSet.push(adapterSet)
 
-        this.transportEvent.next({
+        this.event.next({
             id: uuidv4(),
-            event: `New Adapter`,
-            data: {
-                adapterId: adapterSet.id,
-                message: `New Adapter Set${adapterSet.id} has been added`,
-                payload: adapterSet
-            } as EventMessage
-        })
+            event: 'New Adapter',
+            data: adapterId
+        } as TransportEvent)
+        return adapterSet
     }
+
+
+
 }

+ 9 - 24
src/connector/connector.receiver.ts

@@ -1,7 +1,7 @@
 import dotenv from 'dotenv';
-import { Bus, FisAppActor, FisMessage } from "../interface/transport.interface";
+import { Bus, FisMessage } from "../interface/transport.interface";
 import { ConnectionAdapter } from "./connector.base";
-import { AdapterProfile, AdaptorTransmissionRole, ConnectionState, ReceiverConnectionAdapter as ReceiverConnectionAdapterInterface, TransportEvent, TransportMessage, TransportService } from "../interface/connector.interface";
+import { AdapterProfile, AdaptorTransmissionRole, ConnectionState, ReceiverConnectionAdapter as ReceiverConnectionAdapterInterface, Transport, TransportEvent, TransportMessage, TransportService } from "../interface/connector.interface";
 import { BehaviorSubject, filter, map, Observable, Observer, Subject, Subscription, takeWhile } from 'rxjs';
 import { v4 as uuidv4 } from 'uuid'
 
@@ -9,31 +9,23 @@ dotenv.config();
 /* This transport manager will be instantiating the necessary transport to deal with tranmission and receiving from different receivers
 So how?: */
 export class ReceiverConnectionAdapter extends ConnectionAdapter implements ReceiverConnectionAdapterInterface {
-    event!: Subject<TransportEvent>
-
-    constructor(adapter: TransportService, adapterId: string, event: Subject<TransportEvent>) {
+    constructor(adapterId: string, transportType: Transport, adapter: TransportService) {
         super()
-        // logic here
-        this.event = event
-        this.adaptorTransmissionRole = AdaptorTransmissionRole.Receiver
         this.connector = adapter
-
-        this.setAdapterProfile(adapterId)
+        this.setAdapterProfile(adapterId, transportType)
     }
 
-
-    setAdapterProfile(adapterId: string): void {
+    setAdapterProfile(id: string, transportType: Transport): void {
         this.connectorProfile = {
-            id: adapterId,
-            connectionState: this.connectionStateBus,
-            adapter: this.connector
+            id: id,
+            transportType: transportType
         }
     }
 
-    getMessageBus(bus: Bus): Observable<any> {
+    getMessageBus(bus: Bus): Observable<TransportEvent> {
         return new Observable((observable: Observer<any>) => {
             if (bus == Bus.GeneralBus) {
-                const subscription: Subscription = this.event.pipe(
+                const subscription: Subscription = this.connector.subscribe().pipe(
                     filter((message: TransportEvent) => message.event === 'New Message'),
                     // take message only specific for this adapter. Although that itself wouldn't be necessary, considerng everything goes through transportEvent. I guess it's for better management
                     filter((message: TransportEvent) => (message.data as TransportMessage).target == this.connectorProfile.id),
@@ -66,13 +58,6 @@ export class ReceiverConnectionAdapter extends ConnectionAdapter implements Rece
         });
     }
 
-    getInfo(): AdapterProfile {
-        return this.connectorProfile
-    }
-
-    subscribeMessages(messageFilter: any): Observable<any> {
-        throw new Error('Method not implemented.');
-    }
 }
 
 

+ 18 - 29
src/connector/connector.request.response.ts

@@ -1,10 +1,10 @@
-import dotenv from 'dotenv';
-import { Bus, FisAppActor, FisMessage, TransmissionMessage } from "../interface/transport.interface";
+ import dotenv from 'dotenv';
+import { Bus, FisMessage, TransmissionMessage } from "../interface/transport.interface";
 import { ConnectionAdapter } from "./connector.base";
-import { RequestResponseConnectionAdapter as RequestResponseConnectionAdapterInterface, TransportEvent, TransportMessage } from "../interface/connector.interface";
+import { RequestResponseConnectionAdapter as RequestResponseConnectionAdapterInterface, TransportEvent, TransportMessage, TransportService } from "../interface/connector.interface";
 import { TransmitterConnectionAdapter } from './connector.transmitter';
 import { ReceiverConnectionAdapter } from './connector.receiver';
-import { filter, map, Observable, Observer, Subject, Subscription, takeWhile } from 'rxjs';
+import { filter, map, Observable, Observer, Subscription, takeWhile } from 'rxjs';
 
 dotenv.config();
 /* This transport manager will be instantiating the necessary transport to deal with tranmission and receiving from different receivers
@@ -13,30 +13,22 @@ export class RequestResponseConnectionAdapter extends ConnectionAdapter implemen
     private transmitterAdapter!: TransmitterConnectionAdapter
     private receiverAdapter!: ReceiverConnectionAdapter
 
-    constructor(transmitterAdapter: TransmitterConnectionAdapter, receiverAdapter: ReceiverConnectionAdapter, adapterId: string) {
+    constructor( transmitterAdapter: TransmitterConnectionAdapter, receiverAdapter: ReceiverConnectionAdapter) {
         super()
         // logic here
         this.transmitterAdapter = transmitterAdapter
         this.receiverAdapter = receiverAdapter
-        this.setAdapterProfile(adapterId)
     }
-    setAdapterProfile(adapterId: string): void {
-        this.connectorProfile = {
-            id: adapterId,
-            connectionState: this.connectionStateBus,
-            adapter: this.connector
-        }    
-    }
-    
-    
-    send(message: TransmissionMessage): Observable<TransportMessage> {
-        return new Observable((response: Observer<TransportMessage>) => {
+
+    // Make use of the adapters ref passed in
+    send(message: FisMessage): Observable<FisMessage> {
+        return new Observable((response: Observer<FisMessage>) => {
             // logic here
             this.transmitterAdapter.emit(message)
-            const subscription: Subscription = this.event.pipe(
+            const subscription: Subscription = this.receiverAdapter.getMessageBus(Bus.GeneralBus).pipe(
                 filter((message: TransportEvent) => message.event === 'New Message'),
                 // take message only specific for this adapter. Although that itself wouldn't be necessary, considerng everything goes through transportEvent. I guess it's for better management
-                filter((message:TransportEvent) => (message.data as TransportMessage).target == this.connectorProfile.id), 
+                filter((message: TransportEvent) => (message.data as TransportMessage).target == this.connectorProfile.id),
                 takeWhile((message: TransportEvent) => {
                     const shouldTake = ((message.data as TransportMessage).payload as FisMessage).data !== 'Complete';
                     if (!shouldTake) {
@@ -44,8 +36,8 @@ export class RequestResponseConnectionAdapter extends ConnectionAdapter implemen
                     }
                     return shouldTake;
                 }),
-                map(message => message.data as TransportMessage)
-            ).subscribe((message: TransportMessage) => {
+                map(message => (message.data as TransportMessage).payload as FisMessage)
+            ).subscribe((message: FisMessage) => {
                 response.next(message);
             });
 
@@ -55,19 +47,16 @@ export class RequestResponseConnectionAdapter extends ConnectionAdapter implemen
             };
         })
     }
-  
+
 
     /* Extended from both transmitter and receiver */
-    subscribeMessages(messageFilter: any): Observable<any> {
-        throw new Error('Method not implemented.');
-    }
-    
-    emit(message: TransmissionMessage): void {
+    getMessageBus(bus: Bus): Observable<TransportEvent> {
         throw new Error('Method not implemented.');
     }
-    emitStream(message: TransmissionMessage): void {
+
+    emit(message: FisMessage): void {
         throw new Error('Method not implemented.');
     }
-}
 
+}
 

+ 15 - 26
src/connector/connector.transmitter.ts

@@ -1,5 +1,5 @@
 import dotenv from 'dotenv';
-import { FisAppActor, FisMessage, TransmissionMessage } from "../interface/transport.interface";
+import { FisMessage, TransmissionMessage } from "../interface/transport.interface";
 import { ConnectionAdapter } from "./connector.base";
 import { AdapterProfile, AdaptorTransmissionRole, ConnectionState, TransmitterConnectionAdapter as TransmitterConnectionAdapterInterface, Transport, TransportEvent, TransportMessage, TransportService } from '../interface/connector.interface';
 import { BehaviorSubject, Observable, Observer, Subject } from 'rxjs';
@@ -11,39 +11,28 @@ So how?: */
 export class TransmitterConnectionAdapter extends ConnectionAdapter implements TransmitterConnectionAdapterInterface {
     connectionStateBus: Subject<ConnectionState> = new Subject() 
 
-    constructor(transportService: TransportService, adapterId: string, event: Subject<TransportEvent>, connectionState: Observable<ConnectionState>) {
+    constructor(adapterId: string, adapterType: Transport, transportService: TransportService) {
         super()
         // logic here
-        this.event = event
         this.connector = transportService
-        this.setAdapterProfile(adapterId)
-        connectionState.subscribe(this.connectionStateBus)
+        this.setAdapterProfile(adapterId, adapterType)
     }
 
-    setAdapterProfile(adapterId: string): void {
-        this.connectorProfile = {
-            id: adapterId,
-            connectionState: this.connectionStateBus,
-            adapter: this.connector
-        }
-    }
-
-    emitStream(message: TransmissionMessage): void {
-        throw new Error('Method not implemented.');
-    }
-
-    emit(message: TransmissionMessage): void {
-        (this.connector as TransportService).emit({
-            id: uuidv4(),
-            dateCreated: new Date(),
-            transport: Transport.Websocket,
-            target: message.adapterId,
-            payload: message.payload
+    emit(message: FisMessage): void {
+       // logic here
+        this.connector.emit({
+            id: this.connectorProfile.id,
+            transport: this.connectorProfile.transportType,
+            target: this.connectorProfile.id, // this should be directed to the channel/client established. Make sure this is right
+            payload: message
         } as TransportMessage)
     }
 
-    getInfo(): AdapterProfile {
-        return this.connectorProfile
+    setAdapterProfile(id: string, adapterType: Transport): void {
+        this.connectorProfile = {
+            id: id,
+            transportType: adapterType
+        }
     }
     
 }

+ 7 - 17
src/interface/connector.interface.ts

@@ -1,6 +1,5 @@
 import { BehaviorSubject, Observable, Subject } from "rxjs"
-import { Bus, FisAppActor, ReceiverProfile, TransmissionMessage, TransmissionProfile, TransmitterProfile } from "./transport.interface"
-import { ConnectionAdapter } from "../connector/connector.base"
+import { Bus, FisMessage, ReceiverProfile, TransmissionMessage, TransmissionProfile, TransmitterProfile } from "./transport.interface"
 
 
 export type TYPE = {
@@ -12,19 +11,12 @@ export type TYPE = {
 
 export interface AdapterProfile {
     id: string,
-    adapter: ConnectionAdapter,
-    connectionState: Subject<ConnectionState>
+    transportType: Transport,
 }
 
 
 export interface ConnectionManager {
-    transportService: TransportService
-    // to get notified on what's going on in Transmission Manager
-    transportEvent: Subject<TransportEvent>
-    // list of connection
-    adapterSet: AdapterSet[]
-    // Called by transmission manager to have an instance of these adapters
-    getAdapterSetById(adapterSetid: string): AdapterSet
+    getAdapter(clientId: string, transportService: TransportService): AdapterSet
 }
 
 export interface ConnectionAdaptorBase {
@@ -38,23 +30,21 @@ export interface ConnectionAdaptorBase {
     publishConnectionState(): void
     connect(): void
     disconnect(): void
-    getMessageBus(bus: Bus): Observable<any>
     getInfo(): AdapterProfile
-    setAdapterProfile(id: string): void
+    setAdapterProfile(id: string, transportType: Transport): void
 }
 
 
 export interface TransmitterConnectionAdapter extends ConnectionAdaptorBase {
-    emit(message: TransmissionMessage): void
-    emitStream(message: TransmissionMessage): void
+    emit(message: FisMessage): void
 }
 
 export interface ReceiverConnectionAdapter extends ConnectionAdaptorBase {
-    subscribeMessages(messageFilter: any): Observable<any>
+    getMessageBus(bus: Bus): Observable<any>
 }
 
 export interface RequestResponseConnectionAdapter extends TransmitterConnectionAdapter, ReceiverConnectionAdapter {
-    send(message: TransmissionMessage): Observable<TransportMessage>
+    send(message: FisMessage): Observable<FisMessage>
 }
 
 export type ConnectionState = 'ONLINE' | 'OFFLINE'

+ 10 - 20
src/interface/transport.interface.ts

@@ -1,11 +1,12 @@
 import { Observable, Subject } from "rxjs";
-import { AdapterProfile, AdaptorTransmissionRole, RequestResponseConnectionAdapter, TransportEvent } from "./connector.interface";
+import { AdapterProfile, AdapterSet, AdaptorTransmissionRole, ConnectionManager, RequestResponseConnectionAdapter, TransportEvent, TransportService } from "./connector.interface";
 import { MessageTransmissionTransmitter } from "../transmission/msg.transmission.transmitter";
 import { MessageTransmissionReceiver } from "../transmission/msg.transmission.receiver";
+import { ConnectionAdapter } from "../connector/connector.base";
 
 export interface MessageTransmissionManager {
     // what the hell is this here for
-    getTransmissionInstance(): MessageTransmission
+    getTransmissionInstance(transportServices: TransportService[]): MessageTransmission
 }
 
 export interface MessageTransmission {
@@ -15,30 +16,19 @@ export interface MessageTransmission {
     requestResponse: MessageRequestResponse,
     event: Observable<TransportEvent>
 }
-export interface FisAppActor {
-    incomingMessageBus: Subject<any>
-    outgoingMessageBus: Subject<any>
-
-    send(message: any): Observable<any>
-    emit(message: any): void
-    emitStream(message: any): void
-    subscribeMessages(messageFilter: any): Observable<any>
-}
 
-export interface MessageTransmissionBase extends FisAppActor {
-    msgRepositoryService: any
+export interface MessageTransmissionBase  {
+    msgRepositoryService: any // like logging service and what not
     transmissionRole: AdaptorTransmissionRole
-    adaptorsArray: Array<AdapterProfile> // this is the one we'll be using to catter for multiple clients
-    transmissionService: any
-    adapterService: any
+    adaptorsArray: Array<ConnectionAdapter> 
 
-    getMessageBus(bus: Bus): Observable<any>
     getInfo(): TransmissionProfile
 }
 
 export interface MessageReceiver extends MessageTransmissionBase {
     receiverProfile: ReceiverProfile
-
+    
+    getMessageBus(bus: Bus): Observable<any>
     setReceiver(receiverProfile: ReceiverProfile, role: AdaptorTransmissionRole, event: Subject<TransportEvent>): void
 }
 
@@ -52,7 +42,7 @@ export interface MessageRequestResponse extends MessageTransmissionBase {
     transmitterInstance: MessageTransmissionTransmitter
     receiverInstance: MessageTransmissionReceiver
 
-    setTransmissionProfile(transmissionInfo: MessageTransmissionTransmitter, receiverInfo: MessageTransmissionReceiver, role: AdaptorTransmissionRole, event: Subject<TransportEvent>): void
+    setTransmissionProfile(transmissionInfo: MessageTransmissionTransmitter, receiverInfo: MessageTransmissionReceiver): void
 }
 
 export interface FisMessage {
@@ -91,7 +81,7 @@ export enum Bus {
 }
 
 export interface EventMessage {
-    adapterId: string,
+    clientId: string,
     message: string,
     payload?: any
 }

+ 68 - 49
src/test/transmitter.ts

@@ -1,69 +1,88 @@
-import { filter, interval, map, Observable, Observer, Subject, take } from "rxjs";
-import { Bus, EventMessage, FisMessage, MessageTransmission, TransmissionMessage } from "../interface/transport.interface";
+import { filter, interval, map, Observable, Observer, Subject, Subscription, take } from "rxjs";
+import dotenv from 'dotenv';
+import { Bus, FisMessage, MessageTransmission, TransmissionMessage } from "../interface/transport.interface";
 import { v4 as uuidv4 } from 'uuid'
 import { MessageTransmissionManager } from "../transmission/msg.transmission.manager";
 import { TransportEvent } from "../interface/connector.interface";
 
-/*  These are the purple fonts. Gonna interact with blue fonts to set up the credentials to establish the necessary roles.
-Assuming the primary role is server. That means we will need transmitter and multiple receiver profiles that are connected. */
-class Application {
-    messageTransmissionManager: MessageTransmissionManager
-    transmissionInstance!: MessageTransmission
-    generalNotification: Subject<FisMessage> = new Subject()
+class Supervisor {
+    private clientIncomingMessage: Subject<FisMessage> = new Subject()
+    private messageProducer!: MessageProducer
+    private transmissionManager!: MessageTransmissionManager
+    private event: Subject<TransportEvent> = new Subject()
+    private transmissionSets: MessageTransmission[] = []
 
     constructor() {
-        console.log(`Contructing Application....`)
-        this.messageTransmissionManager = new MessageTransmissionManager()
-        this.transmissionInstance = this.messageTransmissionManager.getTransmissionInstance()
+        // so need them adapters now. But supervisor shouldn't be concerned, only messageTransmissionManager and ConnectionManager
+        this.messageProducer = new MessageProducer(this.clientIncomingMessage)
+        this.transmissionManager = new MessageTransmissionManager(this.event)
 
-        this.generateNotifcation().subscribe(this.generalNotification)
-        this.subscribeForNewClientWhoWantsNotification()
-    }
+        this.transmissionManager.subscribe().subscribe((transmissionSet: MessageTransmission) => {
+            this.transmissionSets.push(transmissionSet)
 
-    // Emulating request response. For the case where this transmitter is acting as a receiver
-    send(message: FisMessage): Observable<FisMessage> {
-        return new Observable((response) => {
-            // logic here
+            this.handleClientActivity(transmissionSet)
         })
     }
 
-    // Transmission only
-    emit(message: FisMessage, adapterId: string): void {
-        this.transmissionInstance.transmitter.emit({
-            adapterId: adapterId, // this should mqatch the request ID??
-            payload: message
+    // only called once for each connected clients.
+    private handleClientActivity(messageTransmission: MessageTransmission): void {
+        // start listening to incoming messages from this client
+        messageTransmission.receiver.getMessageBus(Bus.GeneralBus).subscribe((event: TransmissionMessage) => {
+            let requestMessage: FisMessage = event.payload
+            this.clientIncomingMessage.next(event.payload as FisMessage)
+            this.messageProducer.getOutgoingMessages().pipe(
+                filter(message => message.header.messageID === requestMessage.header.messageID)
+            ).subscribe(message => {
+                messageTransmission.transmitter.emit(message)
+            })
         })
-    }
 
-    // Receiving only
-    susbcribe(): Observable<FisMessage> {
-        return new Observable((observer: Observer<any>) => {
-            this.transmissionInstance.receiver.getMessageBus(Bus.GeneralBus).subscribe((message: TransmissionMessage) => {
-                // logic here
-                this.appProcess(message.adapterId, message.payload)
-            })
+        // to emulate general notification. Send every second
+        this.messageProducer.getNotificationMessage().subscribe((message: FisMessage) => {
+            messageTransmission.transmitter.emit(message)
         })
     }
 
-    // no request needed, auto broadcast 
-    subscribeForNewClientWhoWantsNotification(): void {
-        this.transmissionInstance.event.pipe(
-            filter(obj => obj.event == 'New Adapter')
-        ).subscribe((event: TransportEvent) => {
-            this.generalNotification.subscribe((message: FisMessage) => {
-                this.emit(message, (event.data as EventMessage).adapterId)
-            })
-        })
+}
+
+
+class MessageProducer {
+    private transmissionInstance!: MessageTransmission
+    private generalNotification: Subject<FisMessage> = new Subject()
+    private incomingMessageBus!: Subject<FisMessage>
+    private outgoingMessageBus: Subject<FisMessage> = new Subject()
+
+    constructor(incomingMessageBus: Subject<any>) {
+        console.log(`Contructing Application....`)
+        this.incomingMessageBus = incomingMessageBus
+
+        this.generateNotifcation().subscribe(this.generalNotification)
+        this.handleIncomingRequests(this.incomingMessageBus, this.outgoingMessageBus)
+    }
+
+    public getNotificationMessage(): Observable<FisMessage> {
+        return this.generalNotification.asObservable()
+    }
+
+    public getOutgoingMessages(): Observable<FisMessage> {
+        return this.outgoingMessageBus.asObservable()
     }
 
-    // just assume that the provide will provide 10 responses messages 
-    appProcess(adapterId: string, message: FisMessage): void {
-        this.generateMessage(10).subscribe({
-            next: (message: FisMessage) => {
-                this.emit(message, adapterId)
-            },
-            error: error => console.error(error),
-            complete: () => console.log(`All responses generated completed and passed into adapter: ${adapterId}`)
+    private handleIncomingRequests(requests: Subject<FisMessage>, outgoingMessageBus: Subject<FisMessage>): void {
+        requests.subscribe(request => {
+            this.generateMessage(10).subscribe({
+                next: message => outgoingMessageBus.next(message),
+                error: error => console.error(error),
+                complete: () => {
+                    outgoingMessageBus.next({
+                        header: {
+                            messageID: request.header.messageID,
+                            messageName: `ResponseMessage`
+                        },
+                        data: `Complete`
+                    } as FisMessage)
+                }
+            })
         })
     }
 
@@ -139,4 +158,4 @@ class Application {
     }
 }
 
-const application = new Application()
+let supervisor = new Supervisor()

+ 3 - 26
src/transmission/msg.transmission.base.ts

@@ -3,14 +3,15 @@ import { filter, Observable, Observer, Subject, Subscription, takeWhile, Unsubsc
 import { AdapterProfile, AdaptorTransmissionRole } from '../interface/connector.interface';
 import { Bus, FisMessage, MessageTransmissionBase as MessageTransmissionBaseInterface, TransmissionProfile } from '../interface/transport.interface'
 import { v4 as uuidv4 } from 'uuid'
+import { ConnectionAdapter } from '../connector/connector.base';
 
 export class MessageTransmissionBase implements MessageTransmissionBaseInterface {
     transmissionProfile!: TransmissionProfile
     msgRepositoryService: any;
     transmissionRole!: AdaptorTransmissionRole;
-    adaptorsArray: Array<AdapterProfile> = []
+    adaptorsArray: Array<ConnectionAdapter> = []
     transmissionService: any;
-    adapterService: any;
+    adapterService!: ConnectionAdapter | undefined
     incomingMessageBus!: Subject<any>;
     outgoingMessageBus!: Subject<any>;
 
@@ -18,30 +19,6 @@ export class MessageTransmissionBase implements MessageTransmissionBaseInterface
         // logic here
     }
 
-    getMessageBus(bus: Bus): Observable<any> {
-        throw new Error('Method not implemented.');
-    }
-
-    send(message: any): Observable<any> {
-        throw new Error(`Method not implemented.`)
-    }
-
-    subscribe(observer: Partial<Observer<any>>): Unsubscribable {
-        throw new Error('Method not implemented.');
-    }
-
-    emit(message: any): void {
-        throw new Error('Method not implemented.');
-    }
-
-    emitStream(message: any): void {
-        throw new Error('Method not implemented.');
-    }
-
-    subscribeMessages(messageFilter: any): Observable<any> {
-        throw new Error('Method not implemented.');
-    }
-
     getInfo(): TransmissionProfile {
         return this.transmissionProfile
     }

+ 103 - 39
src/transmission/msg.transmission.manager.ts

@@ -1,69 +1,133 @@
 import { MessageTransmissionTransmitter } from "./msg.transmission.transmitter";
 import { MessageTransmissionReceiver } from "./msg.transmission.receiver";
 import { ConnectionManager } from "../connector/connector.manager";
-import { MessageTransmission, MessageTransmissionManager as MessageTransmissionManagerInterface, ReceiverProfile, TransmissionProfile, TransmitterProfile } from "../interface/transport.interface";
+import { EventMessage, MessageTransmission, MessageTransmissionManager as MessageTransmissionManagerInterface, ReceiverProfile, TransmissionProfile, TransmitterProfile } from "../interface/transport.interface";
 import { v4 as uuidv4 } from 'uuid'
-import { AdaptorTransmissionRole, RequestResponseConnectionAdapter, TransportEvent } from "../interface/connector.interface";
+import { AdapterSet, AdaptorTransmissionRole, RequestResponseConnectionAdapter, Transport, TransportEvent, TransportService } from "../interface/connector.interface";
 import { MessageTransmissionRequestResponse } from "./msg.transmission.request-response";
-/*OKay, the application don't give a shit whose request it comes from. That will be the responsibility of this manager in particular.
-So, from the transmtiter perspective, it would be as if it's only coming from one source, but the demultiplexing will occur here 
-so to speak. The plan, for one type of transport, this manager will make sure all of the connector instances travel through here.
-But of course, the transmitter or fis app actor can always instaniate more transmitter and receiver if needed, and there will be 
-options to cater for wanting to instante different types of transport services according to their needs. */
-export class MessageTransmissionManager implements MessageTransmissionManagerInterface {
-    // transmission: MessageTransmission[] = []
+import { filter, Observable, Observer, Subject } from "rxjs";
+import { WebsocketTransportService } from "../transport/websocket";
+import { HttpTransportService } from "../transport/http";
+import { error } from "console";
+
+export class MessageTransmissionManager {
+    private transportServiceArray: TransportService[] = []
+    private transportSet: Set<TransportSet> = new Set()
+    transmission: MessageTransmission[] = []
     connectionManager!: ConnectionManager
-    messageTransmissionTransmitters: MessageTransmissionTransmitter[] = []
-    messageTransmissionReceiver: MessageTransmissionReceiver[] = []
-    messageTransmissionRequestResponse: MessageTransmissionRequestResponse[] = []
-
-    constructor() {
-       // logic here
-       console.log(`TransmissionManager: Contructing Transmission Manager...`)
-       this.instantiateConnectionManager()
+    event!: Subject<TransportEvent>
+
+    constructor(event: Subject<TransportEvent>) {
+        // logic here
+        console.log(`TransmissionManager: Contructing Transmission Manager...`)
+        this.event = event
+        this.connectionManager = new ConnectionManager(this.event)
+
+        this.sort(this.transportSet)
+        this.transportSet.forEach(set => {
+            this.setUpTransportService(set, event)
+        })
     }
 
     /* so there will be some changes here. will nto be assigning just one, but all of them dynamically to pour into this boy
     Transmitter only have to call this once. */
-    getTransmissionInstance(): MessageTransmission {
-        let transmitter: MessageTransmissionTransmitter = this.getTransmitter()
-        let receiver: MessageTransmissionReceiver = this.getReceiver()
-        let requestResponse: MessageTransmissionRequestResponse = this.getRequestResponse(transmitter, receiver)
-        let transmission: MessageTransmission = {
-            id: uuidv4(),
-            transmitter: transmitter,
-            receiver: receiver,
-            requestResponse: requestResponse,
-            event: this.connectionManager.transportEvent.asObservable()
-        }
-        // this.transmission.push(transmission)
-        return transmission
+    subscribe(): Observable<MessageTransmission> {
+        return new Observable((observer: Observer<MessageTransmission>) => {
+            this.event.pipe(
+                filter(event => event.event == 'New Client')
+            ).subscribe(event => {
+                // 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)
+                let receiver: MessageTransmissionReceiver = this.getReceiver(clientId, adapterSet)
+                let requestResponse: MessageTransmissionRequestResponse = this.getRequestResponse(transmitter, receiver)
+                let transmission: MessageTransmission = {
+                    id: clientId,
+                    transmitter: transmitter,
+                    receiver: receiver,
+                    requestResponse: requestResponse,
+                    event: this.event.asObservable()
+                }
+                this.transmission.push(transmission)
+
+                observer.next(transmission)
+            })
+        })
     }
 
-    private getTransmitter(): MessageTransmissionTransmitter {
+
+    private getTransmitter(transmissionId: string, adapterSets: AdapterSet[]): MessageTransmissionTransmitter {
         let transmitterProfile: TransmitterProfile = {
-            id: uuidv4(),
+            id: transmissionId,
             name: '', // for now make it empty. We will use the assigned uuid here
             dateCreated: new Date()
         }
-        return new MessageTransmissionTransmitter(transmitterProfile, AdaptorTransmissionRole.Transmitter, this.connectionManager.transportEvent)
+        return new MessageTransmissionTransmitter(transmitterProfile, adapterSets)
     }
 
-    private getReceiver(): MessageTransmissionReceiver {
+    private getReceiver(transmissionId: string, adapterSets: AdapterSet[]): MessageTransmissionReceiver {
         let receiverProfile: ReceiverProfile = {
-            id: uuidv4(),
+            id: transmissionId,
             name: '', // for now make it empty. We will use the assigned uuid here
             dateCreated: new Date()
         }
-        return new MessageTransmissionReceiver(receiverProfile, AdaptorTransmissionRole.Receiver, this.connectionManager.transportEvent)
+        return new MessageTransmissionReceiver(receiverProfile, adapterSets)
     }
 
     private getRequestResponse(transmitterInstance: MessageTransmissionTransmitter, receiverInstance: MessageTransmissionReceiver): MessageTransmissionRequestResponse {
-        return new MessageTransmissionRequestResponse(transmitterInstance, receiverInstance, AdaptorTransmissionRole.RequestResponse, this.connectionManager.transportEvent)
+        return new MessageTransmissionRequestResponse(transmitterInstance, receiverInstance)
     }
 
-    private instantiateConnectionManager(): void {
-        this.connectionManager = new ConnectionManager()
+
+    // 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)
+        })
+    }
+}
+
+
+interface TransportSet {
+    transport: Transport,
+    port: number
 }

+ 4 - 16
src/transmission/msg.transmission.receiver.ts

@@ -5,21 +5,20 @@ import { Bus, EventMessage, FisMessage, MessageReceiver as MessageReceiverInterf
 import { ConnectionAdapter } from '../connector/connector.base';
 import { v4 as uuidv4 } from 'uuid'
 import { ReceiverConnectionAdapter } from '../connector/connector.receiver';
+import { ConnectionManager } from '../connector/connector.manager';
 
 export class MessageTransmissionReceiver extends MessageTransmissionBase implements MessageReceiverInterface {
     receiverProfile!: ReceiverProfile;
     private incomingTransportMessage: Subject<TransportMessage> = new Subject()
 
-    constructor(profile: ReceiverProfile, role: AdaptorTransmissionRole, event: Observable<TransportEvent>) {
+    constructor(profile: ReceiverProfile, adapterSets: AdapterSet[]) {
         super();
 
-        this.setReceiver(profile, role)
-        this.handleEvent(event)
+        this.setReceiver(profile)
     }
 
-    setReceiver(receiverProfile: ReceiverProfile, role: AdaptorTransmissionRole): void {
+    setReceiver(receiverProfile: ReceiverProfile): void {
         this.receiverProfile = receiverProfile
-        this.transmissionRole = role
     }
 
     getMessageBus(bus: Bus): Observable<TransmissionMessage> {
@@ -43,15 +42,4 @@ export class MessageTransmissionReceiver extends MessageTransmissionBase impleme
             }
         })
     }
-
-    private handleEvent(event: Observable<TransportEvent>): void {
-        event.pipe(
-            filter((obj: TransportEvent) => obj.event == `New Adapter`),
-            map((obj: TransportEvent) => (obj.data as EventMessage))
-        ).subscribe((event: EventMessage) => {
-            let adapter = (event.payload as AdapterSet).receiverAdapter
-            this.adaptorsArray.push({ id: adapter.getInfo().id, adapter: adapter } as unknown as AdapterProfile)
-            adapter.getMessageBus(Bus.GeneralBus).subscribe(this.incomingTransportMessage)
-        })
-    }
 }

+ 8 - 11
src/transmission/msg.transmission.request-response.ts

@@ -2,32 +2,29 @@ import { MessageTransmissionBase } from "./msg.transmission.base";
 import { FisMessage, MessageReceiver, MessageRequestResponse as MessageRequestResponseInterface } from '../interface/transport.interface'
 import { filter, Observable, Observer, Subscription, takeWhile } from "rxjs";
 import { v4 as uuidv4 } from 'uuid'
-import { AdaptorTransmissionRole, RequestResponseConnectionAdapter, TransportEvent } from "../interface/connector.interface";
+import { AdapterSet, AdaptorTransmissionRole, RequestResponseConnectionAdapter, TransportEvent } from "../interface/connector.interface";
 import { MessageTransmissionReceiver } from "./msg.transmission.receiver";
 import { MessageTransmissionTransmitter } from "./msg.transmission.transmitter";
+import { ConnectionManager } from "../connector/connector.manager";
 
 export class MessageTransmissionRequestResponse extends MessageTransmissionBase implements MessageRequestResponseInterface {
     transmitterInstance!: MessageTransmissionTransmitter;
     receiverInstance!: MessageTransmissionReceiver;
 
-    constructor(transmitterInstance: MessageTransmissionTransmitter, receiverInstance: MessageTransmissionReceiver, role: AdaptorTransmissionRole, event: Observable<TransportEvent>) {
+    constructor(transmitterInstance: MessageTransmissionTransmitter, receiverInstance: MessageTransmissionReceiver) {
         super()
-        this.setTransmissionProfile(transmitterInstance, receiverInstance, role)
+        this.setTransmissionProfile(transmitterInstance, receiverInstance)
     }
 
-    setTransmissionProfile(transmitterInstance: MessageTransmissionTransmitter, receiverInstance: MessageTransmissionReceiver, role: AdaptorTransmissionRole): void {
-        this.transmitterInstance = transmitterInstance
-        this.receiverInstance = receiverInstance
-        this.transmissionRole = role
+    setTransmissionProfile(transmissionInfo: MessageTransmissionTransmitter, receiverInfo: MessageTransmissionReceiver): void {
+        this.transmitterInstance = transmissionInfo
+        this.receiverInstance = receiverInfo
     }
 
     // To be Enhanced. This is actually wrong at the moment
     send(message: FisMessage): Observable<FisMessage> {
         return new Observable((response: Observer<FisMessage>) => {
-            this.transmitterInstance.send({
-                transmitter: '',
-                payload: message
-            });
+            this.transmitterInstance.emit(message);
 
             const subscription: Subscription = this.incomingMessageBus
                 .pipe(

+ 17 - 23
src/transmission/msg.transmission.transmitter.ts

@@ -1,43 +1,37 @@
 import { MessageTransmissionBase } from "./msg.transmission.base";
-import { EventMessage, FisMessage, MessageTransmitter as MessageTransmitterInterface, TransmissionMessage, TransmitterProfile } from '../interface/transport.interface'
-import { AdapterProfile, AdapterSet, AdaptorTransmissionRole, ConnectionState, TransportEvent, TransportMessage, TransportService } from "../interface/connector.interface";
+import { FisMessage, MessageTransmitter as MessageTransmitterInterface, TransmitterProfile } from '../interface/transport.interface'
+import { AdapterSet, Transport } from "../interface/connector.interface";
 import { v4 as uuidv4 } from 'uuid'
 import { TransmitterConnectionAdapter } from "../connector/connector.transmitter";
-import { BehaviorSubject, filter, map, Observable } from "rxjs";
 
 /* Take in all the messages that needs to be transported, and divide them accordingly. So the connector instances will do just that
 connectors or adapters will have their own identifier*/
 export class MessageTransmissionTransmitter extends MessageTransmissionBase implements MessageTransmitterInterface {
     transmitterProfile!: TransmitterProfile;
 
-    constructor(profile: TransmitterProfile, role: AdaptorTransmissionRole, event: Observable<TransportEvent>) {
+    constructor(profile: TransmitterProfile, adapterSets: AdapterSet[]) {
         super()
-        this.setTransmitter(profile, role)
+        this.setTransmitter(profile)
+        this.setUpAdapter(adapterSets)
 
-        this.handleEvent(event)
     }
 
-    setTransmitter(transmitterProfile: TransmitterProfile, role: AdaptorTransmissionRole): void {
+    setTransmitter(transmitterProfile: TransmitterProfile): void {
         this.transmitterProfile = transmitterProfile
-        this.transmissionRole = role
     }
 
-    emit(message: TransmissionMessage): void {
-        // logic here, emit based on message
-        let adapter: AdapterProfile | undefined = this.adaptorsArray.find(obj => obj.id == message.adapterId)
-        if (adapter) {
-            (adapter.adapter as TransmitterConnectionAdapter).emit(message)
-        }
+    emit(message: FisMessage): void {
+        // for now only use one adapter
+        (this.adapterService as TransmitterConnectionAdapter).emit(message)
     }
 
-    private handleEvent(event: Observable<TransportEvent>): void {
-        event.pipe(
-            filter((obj: TransportEvent) => obj.event == `New Adapter`),
-            map(obj => (obj as TransportEvent).data as EventMessage)
-        ).subscribe((event: EventMessage) => {
-            let adapter: TransmitterConnectionAdapter = (event.payload as AdapterSet).transmitterAdapter
-            // so event is only id. because I don't want to have too much instance ?
-            this.adaptorsArray.push({ id: adapter.getInfo().id, adapter: adapter, connectionState: adapter.connectionStateBus })
-        })
+    private setUpAdapter(adapterSets: AdapterSet[]) {
+        if (adapterSets.length > 0) {
+            adapterSets.forEach((adapter: AdapterSet) => {
+                this.adaptorsArray.push(adapter.transmitterAdapter)
+            })
+        }
+        // for now just hardcode to use 1 adapter type until connection manager is further enhacne to configure adapters on the fly
+        this.adapterService = this.adaptorsArray.find(obj => obj.getInfo().transportType === Transport.Websocket)
     }
 }

+ 10 - 11
src/transport/http.ts

@@ -2,26 +2,25 @@ import { Observable, Subject } from "rxjs";
 import { Transport, TransportEvent, TransportMessage, TransportService } from "../interface/connector.interface";
 
 export class HttpTransportService implements TransportService {
-    transportEvent: Subject<TransportEvent> = new Subject()
+    transportEvent!: Subject<TransportEvent>
+
+    constructor(event: Subject<TransportEvent>) {
+        this.transportEvent = event
+    }
+
     getInfo(): Transport {
         throw new Error("Method not implemented.");
     }
+
     emit(message: TransportMessage): void {
         throw new Error("Method not implemented.");
     }
+
     subscribe(): Observable<TransportEvent> {
         throw new Error("Method not implemented.");
     }
-    getTransportEventNotification(): Observable<TransportEvent> {
-        throw new Error("Method not implemented.");
-    }
+   
     startServer(port: number): void {
-        throw new Error("Method not implemented.");
-    }
-    getTransportEvent(): Observable<TransportEvent> {
-        return this.transportEvent.asObservable()
+        // start HTTP server
     }
-
-
-
 }

+ 9 - 10
src/transport/websocket.ts

@@ -4,17 +4,19 @@ import { Socket as SocketForConnectedClient } from "socket.io"
 import { handleClientSocketConnection, handleNewSocketClient, startClientSocketConnection, startSocketServer } from "../utils/socket.utils";
 import { ClientObject, ConnectionState, Info, Transport, TransportEvent, TransportMessage, TransportService } from "../interface/connector.interface";
 import { error } from "console";
+import { subscribe } from "diagnostics_channel";
 
 /* Just code in the context that this websocket service will be handling multiple UI clients. Can think about the server communication at a later time. */
 export class WebsocketTransportService implements TransportService {
-    private info: Transport = Transport.Websocket 
+    private info: Transport = Transport.Websocket
     private connectedServer: ConnectedServerSocket[] = [] // to allow the possibility of having to communicate with multiple servers as a client
     private connectedClientSocket: ConnectedClientSocket[] = [] // to keep track of the all the clients that are connected
     // private incomingMessage: Subject<TransportMessage> = new Subject() // this is only for client roles only atm
-    private transportEvent: Subject<TransportEvent> = new Subject()
+    private transportEvent!: Subject<TransportEvent>
 
-    constructor() {
+    constructor(event: Subject<TransportEvent>) {
         console.log(`WebsocketTransportService: Constructing socket transport service....`)
+        this.transportEvent = event
         // logic here
     }
 
@@ -27,7 +29,7 @@ export class WebsocketTransportService implements TransportService {
                     next: event => this.transportEvent.next(event),
                     error: error => console.error(error),
                     complete: () => console.log(`Client ${connectedClient.id} disconnected...`)
-                }) 
+                })
             },
             error: error => console.error(error),
             complete: () => console.log(`...`)
@@ -39,25 +41,22 @@ export class WebsocketTransportService implements TransportService {
         startClientSocketConnection(url).then((socket: ClientSocket) => {
             handleClientSocketConnection(socket, this.connectedServer).subscribe(this.transportEvent)
         }).catch((error) => {
-            console.error(`WebsocketTransport ERROR:`, error) 
+            console.error(`WebsocketTransport ERROR:`, error)
         })
     }
 
-    public getTransportEvent(): Observable<TransportEvent> {
-        return this.transportEvent.asObservable()
-    }
-
 
     // for transmission(Server Only, not applicable for client Socket)
     public emit(message: TransportMessage): void {
         /* Just a rough idea, Because this service still needs to be direct the mesage to be emiteed based on the client that send it earlier.
         For example, if it'd doing a request response, obviosuly, it needs to be identified whose respnses it belong to. */
         let clientObj: ConnectedClientSocket | undefined = this.connectedClientSocket.find(obj => obj.id == message.target)
-        if(clientObj && clientObj.connectionState.getValue() == 'ONLINE') {
+        if (clientObj && clientObj.connectionState.getValue() == 'ONLINE') {
             clientObj.socketInstance.emit(`message`, message)
         }
     }
 
+    // this returns the ref pointer for the TransportEvent instantiated at Supervisor. Socket will broadcast incoming messages as event
     public subscribe(): Observable<TransportEvent> {
         return this.transportEvent.asObservable()
     }

+ 7 - 7
src/utils/socket.utils.ts

@@ -114,7 +114,7 @@ export function handleClientSocketConnection(socket: ClientSocket, serversConnec
                         id: uuidv4(),
                         event: `New Server`,
                         data: {
-                            adapterId: (data.message as ConnectedServerSocket).id,
+                            clientId: (data.message as ConnectedServerSocket).id,
                             message: `New Websocket Channel ${(data.message as ConnectedServerSocket).id} established.`
                         } as EventMessage
                     })
@@ -138,7 +138,7 @@ export function handleClientSocketConnection(socket: ClientSocket, serversConnec
                         id: uuidv4(),
                         event: 'Client Reconnected',
                         data: {
-                            adapterId: (data.message as ConnectedServerSocket).id,
+                            clientId: (data.message as ConnectedServerSocket).id,
                             message: `Existing Websocket Channel ${(data.message as ConnectedServerSocket).id} re-established.`
                         } as EventMessage
                     })
@@ -170,7 +170,7 @@ export function handleClientSocketConnection(socket: ClientSocket, serversConnec
                     id: uuidv4(),
                     event: `Client Disconnected`,
                     data: {
-                        adapterId: receiverProfileInfo.id,
+                        clientId: receiverProfileInfo.id,
                         message: `Server for Channel ${receiverProfileInfo.id} disconnected.`
                     } as EventMessage
                 })
@@ -189,7 +189,7 @@ export function handleNewSocketClient(socket: SocketForConnectedClient, connecte
         socket.on(`profile`, (message: { name: string, data: any }) => {
             if (message.name == 'New Client') {
                 let clientInstance: ConnectedClientSocket = {
-                    id: uuidv4(),
+                    id: uuidv4(), // client should only be assigned at this level. And is passed around for reference pointing
                     dateCreated: new Date(),
                     socketInstance: socket,
                     connectionState: new BehaviorSubject<ConnectionState>(`ONLINE`)
@@ -203,7 +203,7 @@ export function handleNewSocketClient(socket: SocketForConnectedClient, connecte
                     id: uuidv4(),
                     event: `New Client`,
                     data: {
-                        adapterId: clientInstance.id,
+                        clientId: clientInstance.id,
                         message: `New Client Connected. Adapter ID assigned: ${clientInstance.id}`,
                         payload: clientInstance
                     } as EventMessage
@@ -225,7 +225,7 @@ export function handleNewSocketClient(socket: SocketForConnectedClient, connecte
                         id: uuidv4(),
                         event: 'Client Reconnected',
                         data: {
-                            adapterId: clientInstance.id,
+                            clientId: clientInstance.id,
                             message: `Client ${clientInstance.id} connection re-established`,
                             payload: clientInstance
                         } as EventMessage
@@ -302,7 +302,7 @@ export function startListening(socket: SocketForConnectedClient, client: Connect
                 id: uuidv4(),
                 dateCreated: new Date(),
                 transport: Transport.Websocket,
-                target: client.id, // this would have been assigned it's own adapter with the associated ID
+                target: client.id, // this ref to be associated with the client/channel
                 payload: message
             } as TransportMessage
         })