@@ -7,12 +7,12 @@ import {AppGuardResponse__Output} from './proto/appguard/AppGuardResponse'
77import { AppGuardTcpConnection } from './proto/appguard/AppGuardTcpConnection'
88import { AppGuardHttpResponse } from './proto/appguard/AppGuardHttpResponse'
99import { AppGuardTcpResponse__Output } from "./proto/appguard/AppGuardTcpResponse" ;
10- import { HeartbeatRequest } from "./proto/appguard/HeartbeatRequest" ;
11- import { HeartbeatResponse__Output } from "./proto/appguard/HeartbeatResponse" ;
12- import { DeviceStatus } from "./proto/appguard/DeviceStatus" ;
1310import { TOKEN_FILE } from "./auth" ;
1411import { AppGuardFirewall , AppGuardFirewall__Output } from "./proto/appguard/AppGuardFirewall" ;
1512import { FirewallPolicy } from "./proto/appguard/FirewallPolicy" ;
13+ import { AuthorizationRequest } from "./proto/appguard_commands/AuthorizationRequest" ;
14+ import { ClientMessage } from "./proto/appguard_commands/ClientMessage" ;
15+ import { ServerMessage__Output } from "./proto/appguard_commands/ServerMessage" ;
1616
1717const opts = { includeDirs : [
1818 'node_modules/@nullnet/appguard-express/node_modules/appguard-client-common/proto/' ,
@@ -131,9 +131,20 @@ export class AppGuardService {
131131 }
132132 }
133133
134- heartbeat ( req : HeartbeatRequest ) {
135- let call = this . client . heartbeat ( req ) ;
136- call . on ( 'data' , function ( heartbeat : HeartbeatResponse__Output ) {
134+ control_stream ( req : AuthorizationRequest ) {
135+ let call = this . client . controlChannel ( ) ;
136+
137+ let authz_req : ClientMessage = { authorizationRequest : req } ;
138+ call . write ( authz_req ) ;
139+
140+ call . on ( 'data' , function ( server_msg : ServerMessage__Output ) {
141+ if ( server_msg . deviceAuthorized ) {
142+
143+ } else if ( server_msg . updateTokenCommand ) {
144+
145+ } else if ( server_msg . setFirewallDefaults ) {
146+
147+ }
137148 // handle the heartbeat response
138149 console . log ( "Received heartbeat from server" ) ;
139150 // write token to file
@@ -149,9 +160,9 @@ export class AppGuardService {
149160 call . on ( 'error' , ( _e ) => {
150161 // An error has occurred and the stream has been closed.
151162 // sleep for 10 seconds and try again
152- console . log ( "Error in heartbeat, retrying in 10 seconds " ) ;
163+ console . log ( "Error in control stream " ) ;
153164 setTimeout ( ( ) => {
154- this . heartbeat ( req ) ;
165+ this . control_stream ( req ) ;
155166 } , 10000 ) ;
156167 } ) ;
157168 }
0 commit comments