|
@@ -10,16 +10,6 @@ export class GrpcServiceMethod {
|
|
|
private clientRequest: Subject<ConnectionAttribute> = new Subject()
|
|
|
private localServerStatus: Subject<any> = new Subject()
|
|
|
|
|
|
- // keep track of all the incoming channel request from the servers
|
|
|
- public getClientRequest() {
|
|
|
- return this.clientRequest
|
|
|
- }
|
|
|
-
|
|
|
- // keep track of all the incoming channel request from the servers
|
|
|
- public getLocalServerStatus() {
|
|
|
- return this.localServerStatus
|
|
|
- }
|
|
|
-
|
|
|
public async create(connectionAttribute: ConnectionAttribute): Promise<any> {
|
|
|
return new Promise((resolve, reject) => {
|
|
|
this.createGrpcInstance({ instanceType: 'server' }, connectionAttribute)
|
|
@@ -60,14 +50,14 @@ export class GrpcServiceMethod {
|
|
|
this.server = new grpc.Server()
|
|
|
this.localServerStatus.next({
|
|
|
connectionStatus: 'ON',
|
|
|
- connectionIDlocal: connectionAttribute.ConnectionID.local,
|
|
|
+ connectionID: connectionAttribute.ConnectionID.local,
|
|
|
message: `${connectionAttribute.outGoing.serverUrl} started.`
|
|
|
})
|
|
|
} else {
|
|
|
console.log(`Grpc server alrady started.`)
|
|
|
this.localServerStatus.next({
|
|
|
connectionStatus: 'ON',
|
|
|
- connectionIDlocal: connectionAttribute.ConnectionID.local,
|
|
|
+ connectionID: connectionAttribute.ConnectionID.local,
|
|
|
message: `${connectionAttribute.outGoing.serverUrl} already started.`
|
|
|
})
|
|
|
}
|
|
@@ -108,7 +98,7 @@ export class GrpcServiceMethod {
|
|
|
connectionAttribute.connectionStatus!.next(report)
|
|
|
}
|
|
|
} else {
|
|
|
- console.error(`INVALID REQUEST`)
|
|
|
+ console.error(`INVALID REQUEST! Client request does not fulfill criteria`)
|
|
|
}
|
|
|
},
|
|
|
Check: (_, callback) => {
|
|
@@ -168,6 +158,12 @@ export class GrpcServiceMethod {
|
|
|
payload: this.messageToBeSendOver ?? `There's no message at the moment...`
|
|
|
}
|
|
|
connectionAttribute.connectionStatus!.next(report)
|
|
|
+ let clientStatusUpdateInfo: any = {
|
|
|
+ connectionStatus: 'OFF',
|
|
|
+ connectionID: connectionAttribute.ConnectionID.remote,
|
|
|
+ message: `${connectionAttribute.outGoing.serverUrl} started.`
|
|
|
+ }
|
|
|
+ this.clientRequest.next(clientStatusUpdateInfo)
|
|
|
resolve('No connection established. Server is not responding..')
|
|
|
}
|
|
|
});
|
|
@@ -206,7 +202,7 @@ export class GrpcServiceMethod {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ // TO check or validate if the client request meets the criteria
|
|
|
private isConnectionAttribute(obj: any): obj is ConnectionAttribute {
|
|
|
const isMatch = (
|
|
|
typeof obj.ConnectionID === 'object' && // Further checks can be added based on the structure of ConnectionID
|
|
@@ -236,6 +232,40 @@ export class GrpcServiceMethod {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // update the referenced array
|
|
|
+ public updateConnectionStatus(connectionAttributeArray: ConnectionAttribute[]) {
|
|
|
+ this.localServerStatus.subscribe({
|
|
|
+ next: (notification: any) => {
|
|
|
+ if (notification.connectionStatus === `ON`) {
|
|
|
+ let connectionAttribute = connectionAttributeArray.find(connection => connection.ConnectionID.local == notification.connectionID)
|
|
|
+ if (connectionAttribute) {
|
|
|
+ connectionAttribute.outGoing.connectionState = 'ON'
|
|
|
+ console.log(`Connection ${notification.connectionID} updated`)
|
|
|
+ } else {
|
|
|
+ console.log(`Connection ${notification.connectionID} attribute is not found.`)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ error: err => console.error(err),
|
|
|
+ complete: () => { }
|
|
|
+ })
|
|
|
+ this.clientRequest.subscribe({
|
|
|
+ next: (clientConnectionAttribute: ConnectionAttribute) => {
|
|
|
+ console.log(`Received a request from ${clientConnectionAttribute.outGoing.serverUrl}`)
|
|
|
+ let connectionAttribute = connectionAttributeArray.find(connection => connection.ConnectionID.remote == clientConnectionAttribute.ConnectionID.local)
|
|
|
+ if (connectionAttribute) {
|
|
|
+ console.log(`Connection ${clientConnectionAttribute.ConnectionID.local} updated`)
|
|
|
+ connectionAttribute.inComing.connectionState = 'ON'
|
|
|
+ } else {
|
|
|
+ console.log(`Connection Attribut ${clientConnectionAttribute.inComing.PublisherID} is not found`)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ error: err => console.error(err),
|
|
|
+ complete: () => { }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
}
|
|
|
|