Bladeren bron

minor update

Enzo 9 maanden geleden
bovenliggende
commit
905555b78c
1 gewijzigde bestanden met toevoegingen van 21 en 14 verwijderingen
  1. 21 14
      services/server-client.service.ts

+ 21 - 14
services/server-client.service.ts

@@ -32,14 +32,15 @@ export class ServerClientManager {
             let initialReport: ConnectionState
             let reportSubject: BehaviorSubject<ConnectionState>
             let retransmission: BufferService
+            let errorString: string
             // let originalRequest = JSON.parse(JSON.stringify(request))
             let originalRequest = _.cloneDeep(request)
             let database: string
             let response: any = { message: `Fail to complete connection generation` }
-            let statusChain: State = 0
+            let statusChain: State = 1
             let connectionAttribute: ConnectionAttribute
 
-            if (statusChain == 0) {
+            if (statusChain == 1) {
                 if (!request.server) {
                     request.server = this.defaultServerAttribute
                 }
@@ -55,18 +56,17 @@ export class ServerClientManager {
                 initialReport = { status: 'BUFFER' }
                 reportSubject = new BehaviorSubject(initialReport)
                 retransmission = new BufferService(request.server.messageToBePublishedFromApplication, reportSubject, database)
-
-                statusChain = 1
             }
 
             if (statusChain == 1) {
                 // Connection Type checking
                 if (request.server!.connectionType != request.client!.connectionType) {
                     console.log(`Connection Type DOES NOT MATCH!`)
-                    statusChain = 0
+                    statusChain = -1
+                    errorString ="Connection Type DOES NOT MATCH!"
                 } else {
                     statusChain = 1
-                }
+                }  
             }
 
             if (statusChain == 1) {
@@ -102,17 +102,27 @@ export class ServerClientManager {
                     if (res == false) {
                         this.connectionAttributes.push(connectionAttribute)
                         console.log(`Connection ${connectionAttribute.ConnectionID.local} registered...`)
-                        response = {
-                            message: "Channel Response",
-                            requestedTo: originalRequest,
-                            data: connectionAttribute
-                        }
                     }
                     console.log(`There is now ${this.connectionAttributes.length} connection Attributes`)
                 })
                 statusChain = 1
             }
 
+            if (statusChain == 1) {
+                response = {
+                    message: "Channel Response",
+                    requestedTo: originalRequest,
+                    data: connectionAttribute!
+                }
+                resolve(response);
+            } else if (statusChain == -1) {
+                response = {
+                    message: "Channel Response Error",
+                    requestedTo: originalRequest,
+                    data: errorString! // put error string here
+                }
+                resolve(response);
+            }
             if (statusChain == 1) {
                 // This is default connection`
                 if (!request.client!.connectionType) {
@@ -123,9 +133,6 @@ export class ServerClientManager {
                     // this.grpcService.create(request, connectionAttribute, this.outGoingInfo)
                 }
             }
-
-            resolve(response);
-
         })
     }