|
@@ -1,116 +1,49 @@
|
|
-import { interval, map, Observable, Observer, Subject } from "rxjs"
|
|
|
|
-import { v4 as uuidv4 } from 'uuid'
|
|
|
|
-import { FisMessage, TransportManager } from "../transport/transport.manager"
|
|
|
|
-import { ReceiverProfile, ReceiverRetransmissionProfile, TransportEventNotification, TransportManagerEventNotification, TransportMessage } from "../interface/ITransport.interface"
|
|
|
|
-import { error } from "console"
|
|
|
|
-import { RetransmissionService } from "../utils/retransmission.service"
|
|
|
|
|
|
+import { Observable, Subject } from "rxjs";
|
|
|
|
+import { FisAppActor, FisMessage } from "../interface/transport.interface";
|
|
|
|
+import { MessageTransmissionBase } from "../transmission/msg.transmission.base";
|
|
|
|
+import dotenv from 'dotenv';
|
|
|
|
|
|
-// need to instantiate to grab both incoming and outgoing
|
|
|
|
|
|
+/* 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 implements FisAppActor {
|
|
|
|
+ incomingMessageBus!: Subject<FisMessage>
|
|
|
|
+ outgoingMessageBus!: Subject<FisMessage>
|
|
|
|
+ transmissionService!: MessageTransmissionBase
|
|
|
|
|
|
-class Application {
|
|
|
|
- service!: Blue
|
|
|
|
- notification = new Subject<any>()
|
|
|
|
- constructor(service: Blue) {
|
|
|
|
- this.service = service
|
|
|
|
-
|
|
|
|
- // this one will directly send over
|
|
|
|
- // this.notify()
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- subscribeNotification(): Observable<FisMessage> {
|
|
|
|
- return this.notification.asObservable()
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- notify() {
|
|
|
|
- // logic here
|
|
|
|
- let output = interval(1000)
|
|
|
|
- output.pipe(map(
|
|
|
|
- value => {
|
|
|
|
- let message: FisMessage = {
|
|
|
|
- header: {
|
|
|
|
- messageID: uuidv4(),
|
|
|
|
- messageName: `NotificationMessage`
|
|
|
|
- },
|
|
|
|
- data: `Notification Message ${value}`
|
|
|
|
- }
|
|
|
|
- return message
|
|
|
|
- }
|
|
|
|
- )).subscribe(this.notification)
|
|
|
|
|
|
+ constructor(messageTransmissionBase: MessageTransmissionBase) {
|
|
|
|
+ this.transmissionService = messageTransmissionBase
|
|
|
|
+ this.incomingMessageBus = messageTransmissionBase.incomingMessageBus
|
|
|
|
+ this.outgoingMessageBus = messageTransmissionBase.outgoingMessageBus
|
|
}
|
|
}
|
|
|
|
|
|
- /* EXTRA. Appplication acting as a receiver */
|
|
|
|
- processRequest(request: FisMessage): Observable<FisMessage> {
|
|
|
|
- return new Observable((response) => {
|
|
|
|
- // process responses. Should be called by Blue after receiving a request
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
- // This two only exist at this level.
|
|
|
|
send(message: FisMessage): Observable<FisMessage> {
|
|
send(message: FisMessage): Observable<FisMessage> {
|
|
return new Observable((response) => {
|
|
return new Observable((response) => {
|
|
- // logic here
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-/* At the highest level, blue will also need to know who the receiver is so that it can establsih said one to one relationsuhip */
|
|
|
|
-class Blue {
|
|
|
|
- transportManager!: TransportManager
|
|
|
|
- receiverProfiles: ReceiverRetransmissionProfile[] = []
|
|
|
|
- event: Subject<TransportManagerEventNotification> = new Subject()
|
|
|
|
- constructor(transportManager: TransportManager) {
|
|
|
|
- this.transportManager = transportManager
|
|
|
|
- this.subscribeForTransportManagerEvent()
|
|
|
|
- this.manageReceiverCommunication()
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private subscribeForTransportManagerEvent(): void {
|
|
|
|
- this.transportManager.getTransportManagerEventNotification().subscribe({
|
|
|
|
- next: (notification: TransportManagerEventNotification) => {
|
|
|
|
- this.event.next(notification)
|
|
|
|
- }
|
|
|
|
|
|
+ this.outgoingMessageBus.next(message)
|
|
|
|
+ this.incomingMessageBus.subscribe({
|
|
|
|
+ next: (message: FisMessage) => {
|
|
|
|
+ if (message.header.messageID == message.header.messageID) {
|
|
|
|
+ response.next(message)
|
|
|
|
+ }
|
|
|
|
+ if (message.header.messageID == message.header.messageID && message.data == 'Complete') {
|
|
|
|
+ response.complete()
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ error: error => response.error(error)
|
|
|
|
+ })
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
- private manageReceiverCommunication(): void {
|
|
|
|
- this.event.subscribe((notification: TransportManagerEventNotification) => {
|
|
|
|
- if (notification.event == 'New Client Connection') {
|
|
|
|
- // first thing first, it will check if it's a previously connected receiver
|
|
|
|
- this.checkIfPreviouslyConnected(notification.data?.receiverID as string) // but this id is assigned at connection though So that means the receiver must self identify
|
|
|
|
- let adjustedReceiverProfile: ReceiverRetransmissionProfile = notification.data?.payload
|
|
|
|
- adjustedReceiverProfile.buffer = new RetransmissionService()
|
|
|
|
- // retransmission to be activated. Now it's just assigning it there, but idling.
|
|
|
|
- this.receiverProfiles.push(adjustedReceiverProfile)
|
|
|
|
- console.log(`BLUE: Added new Receiver Profile ${notification.data?.receiverID} to record. `)
|
|
|
|
- }
|
|
|
|
- if (notification.event == 'Client Disconnected') {
|
|
|
|
- console.log(`BLUE: Client ${notification.data?.receiverID} disconnected. Buffering....`)
|
|
|
|
- let receiverProfile: ReceiverRetransmissionProfile | undefined = this.receiverProfiles.find(obj => obj.uuid === notification.data?.receiverID)
|
|
|
|
- if (receiverProfile) {
|
|
|
|
- // then notifiy retransmission to stop releasing the buffer
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if (notification.event == 'New Client Request') {
|
|
|
|
- this.manageReceiverRequest(notification.data?.payload)
|
|
|
|
- console.log(`BLUE: Client request ${notification.data?.payload?.header?.messageID ?? `messageID undefined`} received.`)
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
|
|
+ emit(message: FisMessage): void {
|
|
|
|
+ this.outgoingMessageBus.next(message)
|
|
}
|
|
}
|
|
|
|
|
|
- private manageReceiverRequest(request: FisMessage): void {
|
|
|
|
-
|
|
|
|
|
|
+ emitStream(message: FisMessage): void {
|
|
|
|
+ this.outgoingMessageBus.next(message)
|
|
}
|
|
}
|
|
|
|
|
|
- private checkIfPreviouslyConnected(receiverID: string): boolean {
|
|
|
|
- return this.receiverProfiles.some(obj => obj.uuid === receiverID)
|
|
|
|
|
|
+ subscribeMessages(messageFilter: any): Observable<FisMessage> {
|
|
|
|
+ throw new Error(`Unavailable for now....`)
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-const application = new Application(new Blue(new TransportManager(3000)))
|
|
|
|
-// const application = new Application(new Blue(new TransportManager(null, 'http://localhost:3000')))
|
|
|
|
-// const application = new Application(new Blue(new TransportManager(3000, 'http://localhost:3000')))
|
|
|
|
-
|
|
|
|
-/* Transmitter acting as a receiver */
|
|
|
|
-// logic here
|
|
|
|
|
|
+const application = new Application(new MessageTransmissionBase())
|