|
@@ -1,19 +1,46 @@
|
|
|
import { MessageTransmissionBase } from "./msg.transmission.base";
|
|
|
import { EventMessage, FisMessage, MessageTransmitter as MessageTransmitterInterface, TransmitterProfile } from '../interface/transport.interface'
|
|
|
-import { AdapterSet, Event, Transport, TransportEvent } from "../interface/connector.interface";
|
|
|
+import { AdapterSet, ConnectionState, Event, Transport, TransportEvent } from "../interface/connector.interface";
|
|
|
import { v4 as uuidv4 } from 'uuid'
|
|
|
import { TransmitterConnectionAdapter } from "../connector/connector.transmitter";
|
|
|
-import { filter, Observable } from "rxjs";
|
|
|
+import { BehaviorSubject, filter, map, Observable, Subject } from "rxjs";
|
|
|
+import { RetransmissionService } from "../utils/retransmission.service";
|
|
|
|
|
|
/* 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 {
|
|
|
+ private messageToBeTransmitted!: Subject<FisMessage>
|
|
|
transmitterProfile!: TransmitterProfile;
|
|
|
+ retransmission!: RetransmissionService;
|
|
|
|
|
|
constructor(profile: TransmitterProfile, adapterSets: AdapterSet[], event: Observable<TransportEvent>) {
|
|
|
super(event)
|
|
|
+ this.event = event
|
|
|
+ this.messageToBeTransmitted = new Subject()
|
|
|
+ this.retransmission = new RetransmissionService()
|
|
|
this.setTransmitter(profile)
|
|
|
this.setUpAdapter(adapterSets)
|
|
|
+ this.setUpRetransmission()
|
|
|
+ }
|
|
|
+
|
|
|
+ // by the time this transmission set is instantiated, the connected client would've been online. Need ot manually signal retransmission to release buffer immediately
|
|
|
+ setUpRetransmission(): void {
|
|
|
+ let connectionStateEvent = new BehaviorSubject<'OFFLINE' | 'ONLINE'>('ONLINE')
|
|
|
+ this.event.pipe(
|
|
|
+ filter(event => event.event == 'Client Disconnected' || event.event == 'Client Reconnected'),
|
|
|
+ map(event => {
|
|
|
+ if (event.event == 'Client Disconnected') {
|
|
|
+ return 'OFFLINE'
|
|
|
+ } else {
|
|
|
+ return `ONLINE`
|
|
|
+ }
|
|
|
+ })
|
|
|
+ ).subscribe((signal: ConnectionState) => {
|
|
|
+ connectionStateEvent.next(signal)
|
|
|
+ })
|
|
|
+ this.retransmission.implementRetransmission(this.messageToBeTransmitted, connectionStateEvent)
|
|
|
+ // automatically subscribe to allow released bffered messages to be released
|
|
|
+ this.retransmission.returnSubjectForBufferedItems().subscribe(message => (this.adapterService as TransmitterConnectionAdapter).emit(message.payload))
|
|
|
}
|
|
|
|
|
|
setTransmitter(transmitterProfile: TransmitterProfile): void {
|
|
@@ -22,7 +49,8 @@ export class MessageTransmissionTransmitter extends MessageTransmissionBase impl
|
|
|
|
|
|
emit(message: FisMessage): void {
|
|
|
// for now only use one adapter
|
|
|
- (this.adapterService as TransmitterConnectionAdapter).emit(message)
|
|
|
+ this.messageToBeTransmitted.next(message)
|
|
|
+ // (this.adapterService as TransmitterConnectionAdapter).emit(message)
|
|
|
}
|
|
|
|
|
|
setUpAdapter(adapterSets: AdapterSet[]) {
|