123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- import { BehaviorSubject, Subject } from 'rxjs';
- import { ColorCode, Message, ReportStatus, ConnectionAttribute, ConnectionRequest, ConnectionStatus } from '../interfaces/general.interface';
- import { GrpcServiceMethod } from './grpc.service.method';
- import { FisRetransmissionService } from './fis.retransmission.service';
- export class ServerClientManager {
- private connectionAttributes: ConnectionAttribute[] = []
- constructor(private grpcService: GrpcServiceMethod) {
- }
- public generateConnection(request: ConnectionRequest) {
- let initialReport: ReportStatus = { code: ColorCode.YELLOW, message: 'Initialization of the subject' }
- let reportSubject: BehaviorSubject<ReportStatus> = new BehaviorSubject(initialReport)
- let retransmission: FisRetransmissionService = new FisRetransmissionService()
- let messageToBePublished: Subject<Message> = retransmission.handleMessage(request.server.messageToBePublishedfromApplication, reportSubject)
- let connectionAttribute: ConnectionAttribute = {
- ConnectionID: {
- local: '',
- remote: ''
- },
- outGoing: {
- MessageToBePublished: messageToBePublished,
- MessageToBeReceived: null
- },
- inComing: {
- MessageToBePublished: null,
- MessageToBeReceived: request.client.messageToBeReceivedFromRemote
- },
- connectionStatus: reportSubject // this is not related to report status for the retrasmission service
- }
- // let connectionStatus: Record<string, ConnectionStatus> = {
- // localStatus: ConnectionStatus.RED,
- // remoteStatus: ConnectionStatus.RED
- // }
- // This is default connection
- if (!request.server.connectionType) {
- request.server.connectionType = 'GRPC'
- }
- // For each connection type:
- if (request.server.connectionType == 'GRPC') {
- this.grpcService.create(request, connectionAttribute)
- this.connectionAttributes.push(connectionAttribute)
- }
- // Check to make sure both the connection at local and remote is up, then report to retransmission service to release message
- // connectionAttribute.connectionStatus.subscribe({
- // // Check this....
- // next: (element: any) => {
- // if (element.message == 'Local Server Communication Established') {
- // connectionStatus.localStatus = ConnectionStatus.GREEN
- // console.log(`Local alive`)
- // }
- // if (element.message == 'Remote Server Communication Established') {
- // connectionStatus.remoteStatus = ConnectionStatus.GREEN
- // console.log(`Remote alive`)
- // }
- // if (connectionStatus.localStatus == ConnectionStatus.GREEN && connectionStatus.remoteStatus == ConnectionStatus.GREEN) {
- // let report: ReportStatus = {
- // code: ColorCode.GREEN,
- // message: `Both Local and Remote are connected`
- // }
- // // reportSubject.next(report)
- // console.log(`Both local and remote alive`)
- // }
- // },
- // error: (err) => console.error(err),
- // complete: () => { }
- // })
- }
- }
|